rewrote LDDocument::shortenName using Qt stuff

Sat, 24 Mar 2018 13:11:17 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Mar 2018 13:11:17 +0200
changeset 1329
025578d6e491
parent 1328
d68d1ce89d05
child 1330
9155a6b153f3

rewrote LDDocument::shortenName using Qt stuff

src/documentmanager.cpp file | annotate | diff | comparison | revisions
src/documentmanager.h file | annotate | diff | comparison | revisions
src/lddocument.cpp file | annotate | diff | comparison | revisions
src/lddocument.h file | annotate | diff | comparison | revisions
--- a/src/documentmanager.cpp	Sat Mar 24 13:03:02 2018 +0200
+++ b/src/documentmanager.cpp	Sat Mar 24 13:11:17 2018 +0200
@@ -26,8 +26,6 @@
 #include "parser.h"
 #include "editHistory.h"
 
-const QStringList DocumentManager::specialSubdirectories {"s", "48", "8"};
-
 enum
 {
 	MaxRecentFiles = 10
--- a/src/documentmanager.h	Sat Mar 24 13:03:02 2018 +0200
+++ b/src/documentmanager.h	Sat Mar 24 13:11:17 2018 +0200
@@ -51,8 +51,6 @@
 	void openMainModel (QString path);
 	bool preInline (LDDocument* doc, Model& model, bool deep, bool renderinline);
 
-	static const QStringList specialSubdirectories;
-
 signals:
 	void documentClosed(LDDocument* document);
 
--- a/src/lddocument.cpp	Sat Mar 24 13:03:02 2018 +0200
+++ b/src/lddocument.cpp	Sat Mar 24 13:11:17 2018 +0200
@@ -548,15 +548,15 @@
 
 // =============================================================================
 //
-QString LDDocument::shortenName (QString a) // [static]
+QString LDDocument::shortenName(const QFileInfo& path) // [static]
 {
-	QString shortname = Basename (a);
-	QString topdirname = Basename (Dirname (a));
+	QString shortname = path.fileName();
+	QString topdirname = QFileInfo {path.absoluteFilePath()}.dir().dirName();
 
-	if (DocumentManager::specialSubdirectories.contains (topdirname))
-		shortname.prepend (topdirname + "\\");
-
-	return shortname;
+	if (isOneOf(topdirname, "s", "48", "8"))
+		return topdirname + "\\" + shortname;
+	else
+		return shortname;
 }
 
 // =============================================================================
--- a/src/lddocument.h	Sat Mar 24 13:03:02 2018 +0200
+++ b/src/lddocument.h	Sat Mar 24 13:11:17 2018 +0200
@@ -121,7 +121,7 @@
 	void undo();
 	void vertexChanged (const Vertex& a, const Vertex& b);
 
-	static QString shortenName (QString a); // Turns a full path into a relative path
+	static QString shortenName(const class QFileInfo& path); // Turns a full path into a relative path
 
 protected:
 	LDObject* withdrawAt(int position);

mercurial