From 6b732fe3bd98ceb555f48ec80008c06328452624 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Fri, 15 Mar 2024 00:32:25 +0100 Subject: [PATCH] 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; }