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

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2022 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2013-02-03 19:22:58 +00:00
parent 0796587a63
commit 9c32815887
2 changed files with 49 additions and 0 deletions

View File

@@ -682,6 +682,53 @@ ElementsCategory *ElementsPanel::categoryForPos(const QPoint &pos) {
return(categoryForItem(pos_qtwi)); 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 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 along with their parent hierarchy. When ending the filtering, restore the tree

View File

@@ -58,6 +58,8 @@ class ElementsPanel : public GenericPanel {
ElementsCollectionItem *selectedItem() const; ElementsCollectionItem *selectedItem() const;
ElementsCategory *categoryForItem(QTreeWidgetItem *); ElementsCategory *categoryForItem(QTreeWidgetItem *);
ElementsCategory *categoryForPos(const QPoint &); ElementsCategory *categoryForPos(const QPoint &);
QString dirPathForItem(QTreeWidgetItem *);
QString filePathForItem(QTreeWidgetItem *);
void reloadCollections(); void reloadCollections();
int elementsCollectionItemsCount(); int elementsCollectionItemsCount();