diff --git a/sources/elementspanel.cpp b/sources/elementspanel.cpp index 3ed1c4ff1..69023f665 100644 --- a/sources/elementspanel.cpp +++ b/sources/elementspanel.cpp @@ -682,6 +682,53 @@ ElementsCategory *ElementsPanel::categoryForPos(const QPoint &pos) { return(categoryForItem(pos_qtwi)); } +/** + @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 diff --git a/sources/elementspanel.h b/sources/elementspanel.h index 8b102ee05..ba9baa417 100644 --- a/sources/elementspanel.h +++ b/sources/elementspanel.h @@ -58,6 +58,8 @@ class ElementsPanel : public GenericPanel { ElementsCollectionItem *selectedItem() const; ElementsCategory *categoryForItem(QTreeWidgetItem *); ElementsCategory *categoryForPos(const QPoint &); + QString dirPathForItem(QTreeWidgetItem *); + QString filePathForItem(QTreeWidgetItem *); void reloadCollections(); int elementsCollectionItemsCount();