[qet] [2022] Elements panel: added methods to easily get the underlying filepath for a particular item.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 2022
Author:   xavier
Date:     2013-02-03 20:22:58 +0100 (Sun, 03 Feb 2013)
Log Message:
-----------
Elements panel: added methods to easily get the underlying filepath for a particular item.

Modified Paths:
--------------
    trunk/sources/elementspanel.cpp
    trunk/sources/elementspanel.h

Modified: trunk/sources/elementspanel.cpp
===================================================================
--- trunk/sources/elementspanel.cpp	2013-02-03 19:21:13 UTC (rev 2021)
+++ trunk/sources/elementspanel.cpp	2013-02-03 19:22:58 UTC (rev 2022)
@@ -683,6 +683,53 @@
 }
 
 /**
+	@param qtwi a QTreeWidgetItem
+	@return the directory path of the object represented by \a qtwi
+*/
+QString ElementsPanel::dirPathForItem(QTreeWidgetItem *item) {
+	QString file_path = filePathForItem(item);
+	if (!file_path.isEmpty()) {
+		QFileInfo path_info(file_path);
+		if (path_info.isDir()) {
+			return(file_path);
+		}
+		else {
+			return(path_info.canonicalPath());
+		}
+	}
+	return(QString());
+}
+
+/**
+	@param qtwi a QTreeWidgetItem
+	@return the filepath of the object represented by \a qtwi
+*/
+QString ElementsPanel::filePathForItem(QTreeWidgetItem *item) {
+	if (!item) return(QString());
+	
+	ElementsCollectionItem *collection_item = collectionItemForItem(item);
+	if (collection_item) {
+		if (collection_item -> hasFilePath()) {
+			return(collection_item -> filePath());
+		}
+	}
+	else {
+		TitleBlockTemplateLocation tbt_location = templateLocationForItem(item);
+		TitleBlockTemplatesCollection *tbt_collection = tbt_location.parentCollection();
+		if (tbt_collection && tbt_collection -> hasFilePath()) {
+			return(tbt_collection -> filePath());
+		}
+		else {
+			QETProject *project = projectForItem(item);
+			if (project) {
+				return(project -> filePath());
+			}
+		}
+	}
+	return(QString());
+}
+
+/**
 	Hide items that do not match the provided string, ensure others are visible
 	along with their parent hierarchy. When ending the filtering, restore the tree
 	as it was before the filtering (except the current item) and scroll to the

Modified: trunk/sources/elementspanel.h
===================================================================
--- trunk/sources/elementspanel.h	2013-02-03 19:21:13 UTC (rev 2021)
+++ trunk/sources/elementspanel.h	2013-02-03 19:22:58 UTC (rev 2022)
@@ -58,6 +58,8 @@
 	ElementsCollectionItem *selectedItem() const;
 	ElementsCategory *categoryForItem(QTreeWidgetItem *);
 	ElementsCategory *categoryForPos(const QPoint &);
+	QString dirPathForItem(QTreeWidgetItem *);
+	QString filePathForItem(QTreeWidgetItem *);
 	
 	void reloadCollections();
 	int elementsCollectionItemsCount();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/