From 52c32831391dcf0718951d11233087d94bc12ba7 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sat, 2 Mar 2024 14:58:30 +0100 Subject: [PATCH 1/7] Refactor QPlasmaTreeItem constructors and allow later reinit --- src/PrpShop/QPlasmaTreeItem.cpp | 63 ++++++++++++++++++++------------- src/PrpShop/QPlasmaTreeItem.h | 2 ++ 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/PrpShop/QPlasmaTreeItem.cpp b/src/PrpShop/QPlasmaTreeItem.cpp index f6d153f..cb3f562 100644 --- a/src/PrpShop/QPlasmaTreeItem.cpp +++ b/src/PrpShop/QPlasmaTreeItem.cpp @@ -20,83 +20,98 @@ QPlasmaTreeItem::QPlasmaTreeItem() : QTreeWidgetItem(kTypeNone) { - setIcon(0, QIcon(":/img/folder.png")); + reinit(); } QPlasmaTreeItem::QPlasmaTreeItem(plKey obj) - : QTreeWidgetItem(kTypeKO), fObjKey(obj) + : QTreeWidgetItem(kTypeKO), fObjKey(std::move(obj)) { - setText(0, st2qstr(obj->getName())); - setIcon(0, pqGetTypeIcon(obj->getType())); + reinit(); } QPlasmaTreeItem::QPlasmaTreeItem(const QString& age) : QTreeWidgetItem(kTypeAge), fHasBuiltIn(false), fHasTextures(false), fAge(age) { - setText(0, age); - setIcon(0, QIcon(":/img/age.png")); + reinit(); } QPlasmaTreeItem::QPlasmaTreeItem(plPageInfo* page) : QTreeWidgetItem(kTypePage), fPage(page) { - setText(0, st2qstr(page->getPage())); - setIcon(0, QIcon(":/img/page.png")); + reinit(); } QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidget* parent) : QTreeWidgetItem(parent, kTypeNone) { - setIcon(0, QIcon(":/img/folder.png")); + reinit(); } QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidget* parent, plKey obj) - : QTreeWidgetItem(parent, kTypeKO), fObjKey(obj) + : QTreeWidgetItem(parent, kTypeKO), fObjKey(std::move(obj)) { - setText(0, st2qstr(obj->getName())); - setIcon(0, pqGetTypeIcon(obj->getType())); + reinit(); } QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidget* parent, const QString& age) : QTreeWidgetItem(parent, kTypeAge), fHasBuiltIn(false), fHasTextures(false), fAge(age) { - setText(0, age); - setIcon(0, QIcon(":/img/age.png")); + reinit(); } QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidget* parent, plPageInfo* page) : QTreeWidgetItem(parent, kTypePage), fPage(page) { - setText(0, st2qstr(page->getPage())); - setIcon(0, QIcon(":/img/page.png")); + reinit(); } QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent) : QTreeWidgetItem(parent, kTypeNone) { - setIcon(0, QIcon(":/img/folder.png")); + reinit(); } QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent, plKey obj) - : QTreeWidgetItem(parent, kTypeKO), fObjKey(obj) + : QTreeWidgetItem(parent, kTypeKO), fObjKey(std::move(obj)) { - setText(0, st2qstr(obj->getName())); - setIcon(0, pqGetTypeIcon(obj->getType())); + reinit(); } QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent, const QString& age) : QTreeWidgetItem(parent, kTypeAge), fHasBuiltIn(false), fHasTextures(false), fAge(age) { - setText(0, age); - setIcon(0, QIcon(":/img/age.png")); + reinit(); } QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent, plPageInfo* page) : QTreeWidgetItem(parent, kTypePage), fPage(page) { - setText(0, st2qstr(page->getPage())); - setIcon(0, QIcon(":/img/page.png")); + reinit(); +} + +void QPlasmaTreeItem::reinit() +{ + switch (type()) { + case kTypeNone: + setIcon(0, QIcon(":/img/folder.png")); + break; + + case kTypeKO: + setText(0, st2qstr(fObjKey->getName())); + setIcon(0, pqGetTypeIcon(fObjKey->getType())); + break; + + case kTypeAge: + setText(0, fAge); + setIcon(0, QIcon(":/img/age.png")); + break; + + case kTypePage: + setText(0, st2qstr(fPage->getPage())); + setIcon(0, QIcon(":/img/page.png")); + break; + } } diff --git a/src/PrpShop/QPlasmaTreeItem.h b/src/PrpShop/QPlasmaTreeItem.h index d3501ca..17981e4 100644 --- a/src/PrpShop/QPlasmaTreeItem.h +++ b/src/PrpShop/QPlasmaTreeItem.h @@ -51,6 +51,8 @@ class QPlasmaTreeItem : public QTreeWidgetItem QPlasmaTreeItem(QTreeWidgetItem* parent, const QString& age); QPlasmaTreeItem(QTreeWidgetItem* parent, plPageInfo* page); + void reinit(); + hsKeyedObject* obj() const { return (type() == kTypeKO) ? fObjKey->getObj() : NULL; } QString age() const { return (type() == kTypeAge) ? fAge : QString(); } plPageInfo* page() const { return (type() == kTypePage) ? fPage : NULL; } From fdb710ce624395532d65c09a638c1e4a20754507 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sat, 2 Mar 2024 15:45:38 +0100 Subject: [PATCH 2/7] Add dedicated QPlasmaTreeItem type for class type folders --- src/PrpShop/Main.cpp | 63 +++++++++++++-------------------- src/PrpShop/QPlasmaTreeItem.cpp | 23 ++++++++++++ src/PrpShop/QPlasmaTreeItem.h | 7 +++- 3 files changed, 53 insertions(+), 40 deletions(-) diff --git a/src/PrpShop/Main.cpp b/src/PrpShop/Main.cpp index 77d2f4a..970a4ea 100644 --- a/src/PrpShop/Main.cpp +++ b/src/PrpShop/Main.cpp @@ -449,20 +449,13 @@ void PrpShopMain::treeContextMenu(const QPoint& pos) menu.setDefaultAction(fActions[kTreeEdit]); fActions[kTreePreview]->setEnabled(pqCanPreviewType(item->obj())); fActions[kTreeViewTargets]->setEnabled(pqHasTargets(item->obj())); - } else { + } else if (item->type() == QPlasmaTreeItem::kTypeClassType) { menu.addAction(fActions[kTreeImport]); - if (item->childCount() != 0) { - QPlasmaTreeItem* child = (QPlasmaTreeItem*)item->child(0); - if (child->type() == QPlasmaTreeItem::kTypeKO) { - auto obj_type = child->obj()->getKey()->getType(); - - menu.addAction(fActions[kTreeNewObject]); - fActions[kTreeNewObject]->setText(tr("New %1...").arg( - pqGetFriendlyClassName(obj_type)) - ); - fActions[kTreeNewObject]->setEnabled(pqIsValidKOType(obj_type)); - } - } + menu.addAction(fActions[kTreeNewObject]); + fActions[kTreeNewObject]->setText(tr("New %1...").arg( + pqGetFriendlyClassName(item->classType())) + ); + fActions[kTreeNewObject]->setEnabled(pqIsValidKOType(item->classType())); } menu.exec(fBrowserTree->viewport()->mapToGlobal(pos)); } @@ -587,19 +580,18 @@ QPlasmaTreeItem* PrpShopMain::ensurePath(const plLocation& loc, short objType) if (pageItem == NULL) throw hsBadParamException(__FILE__, __LINE__, "Invalid Page"); - QPlasmaTreeItem* folderItem = NULL; - QString typeName = pqGetFriendlyClassName(objType); + QPlasmaTreeItem* typeItem = nullptr; for (int i=0; ichildCount(); i++) { - if (pageItem->child(i)->text(0) == typeName) { - folderItem = (QPlasmaTreeItem*)pageItem->child(i); + auto child = static_cast(pageItem->child(i)); + if (child->classType() == objType) { + typeItem = child; break; } } - if (folderItem == NULL) { - folderItem = new QPlasmaTreeItem(pageItem); - folderItem->setText(0, typeName); + if (typeItem == nullptr) { + typeItem = new QPlasmaTreeItem(pageItem, objType); } - return folderItem; + return typeItem; } void PrpShopMain::closeWindows(const plLocation& loc) @@ -917,12 +909,13 @@ QPlasmaTreeItem* PrpShopMain::findCurrentPageItem(bool isSave) return item; } else if (item->type() == QPlasmaTreeItem::kTypeKO) { return fLoadedLocations.value(item->obj()->getKey()->getLocation(), NULL); - } else { - // Type folder + } else if (item->type() == QPlasmaTreeItem::kTypeClassType) { QPlasmaTreeItem* pageItem = (QPlasmaTreeItem*)item->parent(); if (pageItem->type() != QPlasmaTreeItem::kTypePage) throw hsBadParamException(__FILE__, __LINE__, "Got non-page parent"); return pageItem; + } else { + return nullptr; } } @@ -1096,12 +1089,11 @@ QPlasmaTreeItem* PrpShopMain::loadPage(plPageInfo* page, QString filename) // Populate the type folders and actual objects std::vector types = fResMgr.getTypes(page->getLocation(), true); for (size_t i=0; isetText(0, pqGetFriendlyClassName(types[i])); + QPlasmaTreeItem* typeItem = new QPlasmaTreeItem(item, types[i]); std::vector keys = fResMgr.getKeys(page->getLocation(), types[i], true); for (size_t j=0; jsetFilename(filename); @@ -1132,21 +1124,15 @@ void PrpShopMain::createNewObject() } } else if (item->type() == QPlasmaTreeItem::kTypePage) { dlg.init(&fResMgr, item->page()->getLocation()); + } else if (item->type() == QPlasmaTreeItem::kTypeClassType) { + if (item->parent()->type() != QPlasmaTreeItem::kTypePage) + throw hsBadParamException(__FILE__, __LINE__, "Got non-page parent"); + dlg.init(&fResMgr, ((QPlasmaTreeItem*)item->parent())->page()->getLocation(), item->classType()); } else if (item->type() == QPlasmaTreeItem::kTypeKO) { dlg.init(&fResMgr, item->obj()->getKey()->getLocation(), item->obj()->getKey()->getType()); } else { - if (item->childCount() != 0) { - QPlasmaTreeItem* child = (QPlasmaTreeItem*)item->child(0); - if (child->type() != QPlasmaTreeItem::kTypeKO) - throw hsBadParamException(__FILE__, __LINE__, "Got non-KO child"); - dlg.init(&fResMgr, child->obj()->getKey()->getLocation(), - child->obj()->getKey()->getType()); - } else { - if (item->parent()->type() != QPlasmaTreeItem::kTypePage) - throw hsBadParamException(__FILE__, __LINE__, "Got non-page parent"); - dlg.init(&fResMgr, ((QPlasmaTreeItem*)item->parent())->page()->getLocation()); - } + dlg.init(&fResMgr); } } else { dlg.init(&fResMgr); @@ -1184,8 +1170,7 @@ void PrpShopMain::showTypeIDs(bool show) QPlasmaTreeItem* pageNode = (QPlasmaTreeItem*)ageNode->child(j); for (int t=0; tchildCount(); t++) { QPlasmaTreeItem* typeNode = (QPlasmaTreeItem*)pageNode->child(t); - short type = ((QPlasmaTreeItem*)typeNode->child(0))->obj()->ClassIndex(); - typeNode->setText(0, pqGetFriendlyClassName(type)); + typeNode->reinit(); } pageNode->sortChildren(0, Qt::AscendingOrder); } diff --git a/src/PrpShop/QPlasmaTreeItem.cpp b/src/PrpShop/QPlasmaTreeItem.cpp index cb3f562..e2aa757 100644 --- a/src/PrpShop/QPlasmaTreeItem.cpp +++ b/src/PrpShop/QPlasmaTreeItem.cpp @@ -29,6 +29,12 @@ QPlasmaTreeItem::QPlasmaTreeItem(plKey obj) reinit(); } +QPlasmaTreeItem::QPlasmaTreeItem(short classType) + : QTreeWidgetItem(kTypeClassType), fClassType(classType) +{ + reinit(); +} + QPlasmaTreeItem::QPlasmaTreeItem(const QString& age) : QTreeWidgetItem(kTypeAge), fHasBuiltIn(false), fHasTextures(false), fAge(age) @@ -54,6 +60,12 @@ QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidget* parent, plKey obj) reinit(); } +QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidget* parent, short classType) + : QTreeWidgetItem(parent, kTypeClassType), fClassType(classType) +{ + reinit(); +} + QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidget* parent, const QString& age) : QTreeWidgetItem(parent, kTypeAge), fHasBuiltIn(false), fHasTextures(false), fAge(age) @@ -79,6 +91,12 @@ QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent, plKey obj) reinit(); } +QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent, short classType) + : QTreeWidgetItem(parent, kTypeClassType), fClassType(classType) +{ + reinit(); +} + QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent, const QString& age) : QTreeWidgetItem(parent, kTypeAge), fHasBuiltIn(false), fHasTextures(false), fAge(age) @@ -104,6 +122,11 @@ void QPlasmaTreeItem::reinit() setIcon(0, pqGetTypeIcon(fObjKey->getType())); break; + case kTypeClassType: + setText(0, pqGetFriendlyClassName(fClassType)); + setIcon(0, QIcon(":/img/folder.png")); + break; + case kTypeAge: setText(0, fAge); setIcon(0, QIcon(":/img/age.png")); diff --git a/src/PrpShop/QPlasmaTreeItem.h b/src/PrpShop/QPlasmaTreeItem.h index 17981e4..e9fd768 100644 --- a/src/PrpShop/QPlasmaTreeItem.h +++ b/src/PrpShop/QPlasmaTreeItem.h @@ -25,6 +25,7 @@ class QPlasmaTreeItem : public QTreeWidgetItem { private: plKey fObjKey; + short fClassType; plPageInfo* fPage; bool fHasBuiltIn, fHasTextures; QString fAge; @@ -34,26 +35,30 @@ class QPlasmaTreeItem : public QTreeWidgetItem public: enum ItemType { - kTypeNone = QTreeWidgetItem::UserType, kTypeAge, kTypePage, kTypeKO, + kTypeNone = QTreeWidgetItem::UserType, kTypeAge, kTypePage, kTypeClassType, kTypeKO, kMaxPlasmaTypes }; QPlasmaTreeItem(); QPlasmaTreeItem(plKey obj); + QPlasmaTreeItem(short classType); QPlasmaTreeItem(const QString& age); QPlasmaTreeItem(plPageInfo* page); QPlasmaTreeItem(QTreeWidget* parent); QPlasmaTreeItem(QTreeWidget* parent, plKey obj); + QPlasmaTreeItem(QTreeWidget* parent, short classType); QPlasmaTreeItem(QTreeWidget* parent, const QString& age); QPlasmaTreeItem(QTreeWidget* parent, plPageInfo* page); QPlasmaTreeItem(QTreeWidgetItem* parent); QPlasmaTreeItem(QTreeWidgetItem* parent, plKey obj); + QPlasmaTreeItem(QTreeWidgetItem* parent, short classType); QPlasmaTreeItem(QTreeWidgetItem* parent, const QString& age); QPlasmaTreeItem(QTreeWidgetItem* parent, plPageInfo* page); void reinit(); hsKeyedObject* obj() const { return (type() == kTypeKO) ? fObjKey->getObj() : NULL; } + short classType() const { return (type() == kTypeClassType) ? fClassType : static_cast(0x8000); } QString age() const { return (type() == kTypeAge) ? fAge : QString(); } plPageInfo* page() const { return (type() == kTypePage) ? fPage : NULL; } From 8df56bac1bf748ba818cdee34deb2a047bdba36f Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sat, 2 Mar 2024 16:05:28 +0100 Subject: [PATCH 3/7] Implement numeric sorting of tree items with visible ID numbers --- src/PrpShop/QPlasmaTreeItem.cpp | 20 ++++++++++++++++++++ src/PrpShop/QPlasmaTreeItem.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/PrpShop/QPlasmaTreeItem.cpp b/src/PrpShop/QPlasmaTreeItem.cpp index e2aa757..98deb0c 100644 --- a/src/PrpShop/QPlasmaTreeItem.cpp +++ b/src/PrpShop/QPlasmaTreeItem.cpp @@ -138,3 +138,23 @@ void QPlasmaTreeItem::reinit() break; } } + +bool QPlasmaTreeItem::operator<(const QTreeWidgetItem& other) const +{ + if (s_showTypeIDs && type() == kTypeClassType && other.type() == kTypeClassType) { + // If type IDs are shown, + // sort class type folders by the numeric type ID. + auto otherPlasma = static_cast(other); + return fClassType < otherPlasma.fClassType; + } else if (type() != other.type()) { + // Sort items of different types by their type, + // i. e. group items of the same type together. + // (This ensures a consistent sort order in case items of different types + // with special sorting behavior somehow end up in the same list.) + return type() < other.type(); + } else { + // If both items have the same type, but the type has no special sorting behavior, + // fall back to default sorting by text. + return QTreeWidgetItem::operator<(other); + } +} diff --git a/src/PrpShop/QPlasmaTreeItem.h b/src/PrpShop/QPlasmaTreeItem.h index e9fd768..1dc2b7e 100644 --- a/src/PrpShop/QPlasmaTreeItem.h +++ b/src/PrpShop/QPlasmaTreeItem.h @@ -57,6 +57,8 @@ class QPlasmaTreeItem : public QTreeWidgetItem void reinit(); + bool operator<(const QTreeWidgetItem& other) const override; + hsKeyedObject* obj() const { return (type() == kTypeKO) ? fObjKey->getObj() : NULL; } short classType() const { return (type() == kTypeClassType) ? fClassType : static_cast(0x8000); } QString age() const { return (type() == kTypeAge) ? fAge : QString(); } From 994de1b2d22da20e7e2e7554626e575f2ad364e8 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sat, 2 Mar 2024 16:33:36 +0100 Subject: [PATCH 4/7] Allow displaying age/page IDs in Object Browser tree --- src/PrpShop/Main.cpp | 24 ++++++++++++++++++++++++ src/PrpShop/Main.h | 5 +++-- src/PrpShop/QPlasmaTreeItem.cpp | 19 ++++++++++++++++++- src/PrpShop/QPlasmaUtils.cpp | 1 + src/PrpShop/QPlasmaUtils.h | 1 + 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/PrpShop/Main.cpp b/src/PrpShop/Main.cpp index 970a4ea..184b337 100644 --- a/src/PrpShop/Main.cpp +++ b/src/PrpShop/Main.cpp @@ -67,6 +67,7 @@ PrpShopMain::PrpShopMain() fActions[kFileSaveAs] = new QAction(tr("Sa&ve As..."), this); fActions[kFileExit] = new QAction(tr("E&xit"), this); fActions[kToolsProperties] = new QAction(tr("Show &Properties Pane"), this); + fActions[kToolsShowAgePageIDs] = new QAction(tr("Show &Age/Page IDs"), this); fActions[kToolsShowTypeIDs] = new QAction(tr("Show Type &IDs"), this); fActions[kToolsNewObject] = new QAction(tr("&New Object..."), this); fActions[kWindowPrev] = new QAction(tr("&Previous"), this); @@ -96,6 +97,8 @@ PrpShopMain::PrpShopMain() fActions[kWindowClose]->setShortcutContext(Qt::WidgetWithChildrenShortcut); fActions[kToolsProperties]->setCheckable(true); fActions[kToolsProperties]->setChecked(true); + fActions[kToolsShowAgePageIDs]->setCheckable(true); + fActions[kToolsShowAgePageIDs]->setChecked(false); fActions[kToolsShowTypeIDs]->setCheckable(true); fActions[kToolsShowTypeIDs]->setChecked(false); @@ -111,6 +114,7 @@ PrpShopMain::PrpShopMain() QMenu* viewMenu = menuBar()->addMenu(tr("&Tools")); viewMenu->addAction(fActions[kToolsProperties]); + viewMenu->addAction(fActions[kToolsShowAgePageIDs]); viewMenu->addAction(fActions[kToolsShowTypeIDs]); viewMenu->addSeparator(); viewMenu->addAction(fActions[kToolsNewObject]); @@ -180,6 +184,8 @@ PrpShopMain::PrpShopMain() fPropertyDock, &QWidget::setVisible); connect(fPropertyDock, &QDockWidget::visibilityChanged, fActions[kToolsProperties], &QAction::setChecked); + connect(fActions[kToolsShowAgePageIDs], &QAction::toggled, + this, &PrpShopMain::showAgePageIDs); connect(fActions[kToolsShowTypeIDs], &QAction::toggled, this, &PrpShopMain::showTypeIDs); connect(fActions[kToolsNewObject], &QAction::triggered, @@ -231,6 +237,8 @@ PrpShopMain::PrpShopMain() if (settings.contains("DialogDir")) fDialogDir = settings.value("DialogDir").toString(); + fActions[kToolsShowAgePageIDs]->setChecked( + settings.value("ShowAgePageIDs", false).toBool()); fActions[kToolsShowTypeIDs]->setChecked( settings.value("ShowTypeIDs", false).toBool()); } @@ -248,6 +256,7 @@ void PrpShopMain::closeEvent(QCloseEvent*) settings.setValue("WinState", saveState()); settings.setValue("DialogDir", fDialogDir); + settings.setValue("ShowAgePageIDs", s_showAgePageIDs); settings.setValue("ShowTypeIDs", s_showTypeIDs); } @@ -1159,6 +1168,21 @@ void PrpShopMain::createNewObject() } } +void PrpShopMain::showAgePageIDs(bool show) +{ + s_showAgePageIDs = show; + + // Refresh currently loaded pages + for (int i=0; itopLevelItemCount(); i++) { + QPlasmaTreeItem* ageNode = (QPlasmaTreeItem*)fBrowserTree->topLevelItem(i); + for (int j=0; jchildCount(); j++) { + QPlasmaTreeItem* pageNode = (QPlasmaTreeItem*)ageNode->child(j); + pageNode->reinit(); + } + ageNode->sortChildren(0, Qt::AscendingOrder); + } +} + void PrpShopMain::showTypeIDs(bool show) { s_showTypeIDs = show; diff --git a/src/PrpShop/Main.h b/src/PrpShop/Main.h index 1d927d9..4c206e5 100644 --- a/src/PrpShop/Main.h +++ b/src/PrpShop/Main.h @@ -73,8 +73,8 @@ class PrpShopMain : public QMainWindow { // Main Menu kFileNewPage, kFileOpen, kFileSave, kFileSaveAs, kFileExit, - kToolsProperties, kToolsShowTypeIDs, kToolsNewObject, kWindowPrev, - kWindowNext, kWindowTile, kWindowCascade, kWindowClose, kWindowCloseAll, + kToolsProperties, kToolsShowAgePageIDs, kToolsShowTypeIDs, kToolsNewObject, + kWindowPrev, kWindowNext, kWindowTile, kWindowCascade, kWindowClose, kWindowCloseAll, // Tree Context Menu kTreeClose, kTreeEdit, kTreeEditPRC, kTreeEditHex, kTreePreview, @@ -119,6 +119,7 @@ public slots: void treeItemActivated(QTreeWidgetItem* item, int column); void treeContextMenu(const QPoint& pos); void createNewObject(); + void showAgePageIDs(bool show); void showTypeIDs(bool show); void closeWindows(const plLocation& loc); diff --git a/src/PrpShop/QPlasmaTreeItem.cpp b/src/PrpShop/QPlasmaTreeItem.cpp index 98deb0c..de19690 100644 --- a/src/PrpShop/QPlasmaTreeItem.cpp +++ b/src/PrpShop/QPlasmaTreeItem.cpp @@ -15,6 +15,8 @@ */ #include "QPlasmaTreeItem.h" + +#include #include "QPlasmaUtils.h" QPlasmaTreeItem::QPlasmaTreeItem() @@ -110,6 +112,15 @@ QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent, plPageInfo* page) reinit(); } +static QString pqFormatPageName(const plPageInfo* page) +{ + if (s_showAgePageIDs) { + return st2qstr(ST::format("{} {}", page->getLocation().toString(), page->getPage())); + } else { + return st2qstr(page->getPage()); + } +} + void QPlasmaTreeItem::reinit() { switch (type()) { @@ -133,7 +144,7 @@ void QPlasmaTreeItem::reinit() break; case kTypePage: - setText(0, st2qstr(fPage->getPage())); + setText(0, pqFormatPageName(fPage)); setIcon(0, QIcon(":/img/page.png")); break; } @@ -146,6 +157,12 @@ bool QPlasmaTreeItem::operator<(const QTreeWidgetItem& other) const // sort class type folders by the numeric type ID. auto otherPlasma = static_cast(other); return fClassType < otherPlasma.fClassType; + } else if (s_showAgePageIDs && type() == kTypePage && other.type() == kTypePage) { + // If age/page IDs are shown, + // sort pages by their location + // (i. e. first by age ID, then by page ID). + auto otherPlasma = static_cast(other); + return fPage->getLocation() < otherPlasma.fPage->getLocation(); } else if (type() != other.type()) { // Sort items of different types by their type, // i. e. group items of the same type together. diff --git a/src/PrpShop/QPlasmaUtils.cpp b/src/PrpShop/QPlasmaUtils.cpp index 0f53a4d..0213591 100644 --- a/src/PrpShop/QPlasmaUtils.cpp +++ b/src/PrpShop/QPlasmaUtils.cpp @@ -21,6 +21,7 @@ #include #include +bool s_showAgePageIDs = false; bool s_showTypeIDs = false; enum diff --git a/src/PrpShop/QPlasmaUtils.h b/src/PrpShop/QPlasmaUtils.h index 565cea7..bf5678c 100644 --- a/src/PrpShop/QPlasmaUtils.h +++ b/src/PrpShop/QPlasmaUtils.h @@ -24,6 +24,7 @@ #include "QPlasma.h" #include "QNumerics.h" +extern bool s_showAgePageIDs; extern bool s_showTypeIDs; enum From a7d27b44601bf187dbd291597dfb906947831681 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sat, 2 Mar 2024 19:05:27 +0100 Subject: [PATCH 5/7] Fix code that looked up tree items by their displayed text This no longer works for pages now that they might have IDs displayed. For ages it's technically still fine, but better to fix those as well to avoid unpleasant surprises later. --- src/PrpShop/Main.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/PrpShop/Main.cpp b/src/PrpShop/Main.cpp index 184b337..7b4ec0a 100644 --- a/src/PrpShop/Main.cpp +++ b/src/PrpShop/Main.cpp @@ -569,10 +569,10 @@ QPlasmaTreeItem* PrpShopMain::ensurePath(const plLocation& loc, short objType) plPageInfo* page = fResMgr.FindPage(loc); QPlasmaTreeItem* ageItem = NULL; QString ageName = st2qstr(page->getAge()); - QString pageName = st2qstr(page->getPage()); for (int i=0; itopLevelItemCount(); i++) { - if (fBrowserTree->topLevelItem(i)->text(0) == ageName) { - ageItem = (QPlasmaTreeItem*)fBrowserTree->topLevelItem(i); + auto topLevelItem = static_cast(fBrowserTree->topLevelItem(i)); + if (topLevelItem->age() == ageName) { + ageItem = topLevelItem; break; } } @@ -581,8 +581,9 @@ QPlasmaTreeItem* PrpShopMain::ensurePath(const plLocation& loc, short objType) QPlasmaTreeItem* pageItem = NULL; for (int i=0; ichildCount(); i++) { - if (ageItem->child(i)->text(0) == pageName) { - pageItem = (QPlasmaTreeItem*)ageItem->child(i); + auto child = static_cast(ageItem->child(i)); + if (child->page()->getLocation() == loc) { + pageItem = child; break; } } @@ -1076,8 +1077,9 @@ QPlasmaTreeItem* PrpShopMain::loadPage(plPageInfo* page, QString filename) // Find or create the Age folder QString ageName = st2qstr(page->getAge()); for (int i=0; itopLevelItemCount(); i++) { - if (fBrowserTree->topLevelItem(i)->text(0) == ageName) { - parent = (QPlasmaTreeItem*)fBrowserTree->topLevelItem(i); + auto topLevelItem = static_cast(fBrowserTree->topLevelItem(i)); + if (topLevelItem->age() == ageName) { + parent = topLevelItem; break; } } From 6b732fe3bd98ceb555f48ec80008c06328452624 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Fri, 15 Mar 2024 00:32:25 +0100 Subject: [PATCH 6/7] Display age IDs next to age names as well --- src/PrpShop/Main.cpp | 6 ++++-- src/PrpShop/QPlasmaTreeItem.cpp | 28 +++++++++++++++++++++------- src/PrpShop/QPlasmaTreeItem.h | 8 +++++--- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/PrpShop/Main.cpp b/src/PrpShop/Main.cpp index 7b4ec0a..bd7c362 100644 --- a/src/PrpShop/Main.cpp +++ b/src/PrpShop/Main.cpp @@ -1084,7 +1084,7 @@ QPlasmaTreeItem* PrpShopMain::loadPage(plPageInfo* page, QString filename) } } if (parent == NULL) - parent = new QPlasmaTreeItem(fBrowserTree, ageName); + parent = new QPlasmaTreeItem(fBrowserTree, ageName, page->getLocation().getSeqPrefix()); // Treat BuiltIn and Textures PRPs specially: if (page->getLocation().getPageNum() == -1) @@ -1174,7 +1174,7 @@ void PrpShopMain::showAgePageIDs(bool show) { s_showAgePageIDs = show; - // Refresh currently loaded pages + // Refresh currently loaded ages/pages for (int i=0; itopLevelItemCount(); i++) { QPlasmaTreeItem* ageNode = (QPlasmaTreeItem*)fBrowserTree->topLevelItem(i); for (int j=0; jchildCount(); j++) { @@ -1182,7 +1182,9 @@ void PrpShopMain::showAgePageIDs(bool show) pageNode->reinit(); } ageNode->sortChildren(0, Qt::AscendingOrder); + ageNode->reinit(); } + fBrowserTree->sortItems(0, Qt::AscendingOrder); } void PrpShopMain::showTypeIDs(bool show) diff --git a/src/PrpShop/QPlasmaTreeItem.cpp b/src/PrpShop/QPlasmaTreeItem.cpp index de19690..46f07b1 100644 --- a/src/PrpShop/QPlasmaTreeItem.cpp +++ b/src/PrpShop/QPlasmaTreeItem.cpp @@ -37,9 +37,9 @@ QPlasmaTreeItem::QPlasmaTreeItem(short classType) reinit(); } -QPlasmaTreeItem::QPlasmaTreeItem(const QString& age) +QPlasmaTreeItem::QPlasmaTreeItem(const QString& age, int ageSeqPrefix) : QTreeWidgetItem(kTypeAge), fHasBuiltIn(false), fHasTextures(false), - fAge(age) + fAge(age), fAgeSeqPrefix(ageSeqPrefix) { reinit(); } @@ -68,9 +68,9 @@ QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidget* parent, short classType) reinit(); } -QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidget* parent, const QString& age) +QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidget* parent, const QString& age, int ageSeqPrefix) : QTreeWidgetItem(parent, kTypeAge), fHasBuiltIn(false), - fHasTextures(false), fAge(age) + fHasTextures(false), fAge(age), fAgeSeqPrefix(ageSeqPrefix) { reinit(); } @@ -99,9 +99,9 @@ QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent, short classType) reinit(); } -QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent, const QString& age) +QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent, const QString& age, int ageSeqPrefix) : QTreeWidgetItem(parent, kTypeAge), fHasBuiltIn(false), - fHasTextures(false), fAge(age) + fHasTextures(false), fAge(age), fAgeSeqPrefix(ageSeqPrefix) { reinit(); } @@ -121,6 +121,15 @@ static QString pqFormatPageName(const plPageInfo* page) } } +static QString pqFormatAgeName(const QString& name, int seqPrefix) +{ + if (s_showAgePageIDs) { + return QString("<%1> %2").arg(seqPrefix).arg(name); + } else { + return name; + } +} + void QPlasmaTreeItem::reinit() { switch (type()) { @@ -139,7 +148,7 @@ void QPlasmaTreeItem::reinit() break; case kTypeAge: - setText(0, fAge); + setText(0, pqFormatAgeName(fAge, fAgeSeqPrefix)); setIcon(0, QIcon(":/img/age.png")); break; @@ -163,6 +172,11 @@ bool QPlasmaTreeItem::operator<(const QTreeWidgetItem& other) const // (i. e. first by age ID, then by page ID). auto otherPlasma = static_cast(other); return fPage->getLocation() < otherPlasma.fPage->getLocation(); + } else if (s_showAgePageIDs && type() == kTypeAge && other.type() == kTypeAge) { + // If age/page IDs are shown, + // sort ages by their ID (sequence prefix). + auto otherPlasma = static_cast(other); + return fAgeSeqPrefix < otherPlasma.fAgeSeqPrefix; } else if (type() != other.type()) { // Sort items of different types by their type, // i. e. group items of the same type together. diff --git a/src/PrpShop/QPlasmaTreeItem.h b/src/PrpShop/QPlasmaTreeItem.h index 1dc2b7e..ccccf02 100644 --- a/src/PrpShop/QPlasmaTreeItem.h +++ b/src/PrpShop/QPlasmaTreeItem.h @@ -29,6 +29,7 @@ class QPlasmaTreeItem : public QTreeWidgetItem plPageInfo* fPage; bool fHasBuiltIn, fHasTextures; QString fAge; + int fAgeSeqPrefix; QString fFilename; @@ -42,17 +43,17 @@ class QPlasmaTreeItem : public QTreeWidgetItem QPlasmaTreeItem(); QPlasmaTreeItem(plKey obj); QPlasmaTreeItem(short classType); - QPlasmaTreeItem(const QString& age); + QPlasmaTreeItem(const QString& age, int ageSeqPrefix); QPlasmaTreeItem(plPageInfo* page); QPlasmaTreeItem(QTreeWidget* parent); QPlasmaTreeItem(QTreeWidget* parent, plKey obj); QPlasmaTreeItem(QTreeWidget* parent, short classType); - QPlasmaTreeItem(QTreeWidget* parent, const QString& age); + QPlasmaTreeItem(QTreeWidget* parent, const QString& age, int ageSeqPrefix); QPlasmaTreeItem(QTreeWidget* parent, plPageInfo* page); QPlasmaTreeItem(QTreeWidgetItem* parent); QPlasmaTreeItem(QTreeWidgetItem* parent, plKey obj); QPlasmaTreeItem(QTreeWidgetItem* parent, short classType); - QPlasmaTreeItem(QTreeWidgetItem* parent, const QString& age); + QPlasmaTreeItem(QTreeWidgetItem* parent, const QString& age, int ageSeqPrefix); QPlasmaTreeItem(QTreeWidgetItem* parent, plPageInfo* page); void reinit(); @@ -62,6 +63,7 @@ class QPlasmaTreeItem : public QTreeWidgetItem hsKeyedObject* obj() const { return (type() == kTypeKO) ? fObjKey->getObj() : NULL; } short classType() const { return (type() == kTypeClassType) ? fClassType : static_cast(0x8000); } QString age() const { return (type() == kTypeAge) ? fAge : QString(); } + int ageSeqPrefix() const { return (type() == kTypeAge) ? fAgeSeqPrefix : INT_MIN; } plPageInfo* page() const { return (type() == kTypePage) ? fPage : NULL; } bool hasBuiltIn() const { return (type() == kTypeAge) ? fHasBuiltIn : false; } From f9822d8bef4bc87ef16184c122f15fbaea526009 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sun, 17 Mar 2024 00:30:28 +0100 Subject: [PATCH 7/7] Fix tree item text not updating when changing page name or IDs --- src/PrpShop/Main.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/PrpShop/Main.cpp b/src/PrpShop/Main.cpp index bd7c362..35542c8 100644 --- a/src/PrpShop/Main.cpp +++ b/src/PrpShop/Main.cpp @@ -1017,6 +1017,7 @@ void PrpShopMain::saveFile(plPageInfo* page, QString filename) void PrpShopMain::saveProps(QPlasmaTreeItem* item) { if (item != NULL) { + bool reinit = false; bool refreshTree = false; if (item->type() == QPlasmaTreeItem::kTypePage) { if (fAgeName->text() != st2qstr(item->page()->getAge())) { @@ -1029,7 +1030,7 @@ void PrpShopMain::saveProps(QPlasmaTreeItem* item) } if (fPageName->text() != st2qstr(item->page()->getPage())) { item->page()->setPage(qstr2st(fPageName->text())); - item->setText(0, fPageName->text()); + reinit = true; refreshTree = true; } if (fReleaseVersion->value() != (int)item->page()->getReleaseVersion()) @@ -1046,12 +1047,13 @@ void PrpShopMain::saveProps(QPlasmaTreeItem* item) fLoadedLocations[loc] = fLoadedLocations[item->page()->getLocation()]; fLoadedLocations.erase(fLoadedLocations.find(item->page()->getLocation())); fResMgr.ChangeLocation(item->page()->getLocation(), loc); + reinit = true; } } else if (item->type() == QPlasmaTreeItem::kTypeKO) { if (item->obj() != NULL) { if (fObjName->text() != st2qstr(item->obj()->getKey()->getName())) { item->obj()->getKey()->setName(qstr2st(fObjName->text())); - item->setText(0, fObjName->text()); + reinit = true; refreshTree = true; } plLoadMask mask = item->obj()->getKey()->getLoadMask(); @@ -1061,6 +1063,10 @@ void PrpShopMain::saveProps(QPlasmaTreeItem* item) item->obj()->getKey()->setCloneIDs(fCloneId->value(), fClonePlayerId->value()); } } + if (reinit) { + item->reinit(); + item->parent()->sortChildren(0, Qt::AscendingOrder); + } if (refreshTree) fBrowserTree->sortItems(0, Qt::AscendingOrder); }