Skip to content

Commit

Permalink
Display age IDs next to age names as well
Browse files Browse the repository at this point in the history
  • Loading branch information
dgelessus committed Mar 14, 2024
1 parent a7d27b4 commit 6b732fe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/PrpShop/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1174,15 +1174,17 @@ void PrpShopMain::showAgePageIDs(bool show)
{
s_showAgePageIDs = show;

// Refresh currently loaded pages
// Refresh currently loaded ages/pages
for (int i=0; i<fBrowserTree->topLevelItemCount(); i++) {
QPlasmaTreeItem* ageNode = (QPlasmaTreeItem*)fBrowserTree->topLevelItem(i);
for (int j=0; j<ageNode->childCount(); j++) {
QPlasmaTreeItem* pageNode = (QPlasmaTreeItem*)ageNode->child(j);
pageNode->reinit();
}
ageNode->sortChildren(0, Qt::AscendingOrder);
ageNode->reinit();
}
fBrowserTree->sortItems(0, Qt::AscendingOrder);
}

void PrpShopMain::showTypeIDs(bool show)
Expand Down
28 changes: 21 additions & 7 deletions src/PrpShop/QPlasmaTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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()) {
Expand All @@ -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;

Expand All @@ -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<const QPlasmaTreeItem&>(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<const QPlasmaTreeItem&>(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.
Expand Down
8 changes: 5 additions & 3 deletions src/PrpShop/QPlasmaTreeItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class QPlasmaTreeItem : public QTreeWidgetItem
plPageInfo* fPage;
bool fHasBuiltIn, fHasTextures;
QString fAge;
int fAgeSeqPrefix;

QString fFilename;

Expand All @@ -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();
Expand All @@ -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<short>(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; }
Expand Down

0 comments on commit 6b732fe

Please sign in to comment.