Skip to content

Commit

Permalink
Allow displaying age/page IDs in Object Browser tree
Browse files Browse the repository at this point in the history
  • Loading branch information
dgelessus committed Mar 10, 2024
1 parent a435bc8 commit 9987ce7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/PrpShop/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

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

Expand Down Expand Up @@ -1171,6 +1180,21 @@ void PrpShopMain::createNewObject()
}
}

void PrpShopMain::showAgePageIDs(bool show)
{
s_showAgePageIDs = show;

// Refresh currently loaded 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);
}
}

void PrpShopMain::showTypeIDs(bool show)
{
s_showTypeIDs = show;
Expand Down
5 changes: 3 additions & 2 deletions src/PrpShop/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
19 changes: 18 additions & 1 deletion src/PrpShop/QPlasmaTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

#include "QPlasmaTreeItem.h"

#include <string_theory/format>
#include "QPlasmaUtils.h"

QPlasmaTreeItem::QPlasmaTreeItem()
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
}
Expand All @@ -146,6 +157,12 @@ bool QPlasmaTreeItem::operator<(const QTreeWidgetItem& other) const
// sort class type folders by the numeric type ID.
auto otherPlasma = static_cast<const QPlasmaTreeItem&>(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<const QPlasmaTreeItem&>(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.
Expand Down
1 change: 1 addition & 0 deletions src/PrpShop/QPlasmaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <PRP/Object/plCoordinateInterface.h>
#include <PRP/Object/plSceneObject.h>

bool s_showAgePageIDs = false;
bool s_showTypeIDs = false;

enum
Expand Down
1 change: 1 addition & 0 deletions src/PrpShop/QPlasmaUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "QPlasma.h"
#include "QNumerics.h"

extern bool s_showAgePageIDs;
extern bool s_showTypeIDs;

enum
Expand Down

0 comments on commit 9987ce7

Please sign in to comment.