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 2, 2024
1 parent 95e2dd4 commit 3a87074
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 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[kToolsShowObjectIDs] = new QAction(tr("Show &Object IDs"), this);
fActions[kToolsNewObject] = new QAction(tr("&New Object..."), this);
Expand Down Expand Up @@ -97,6 +98,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);
fActions[kToolsShowObjectIDs]->setCheckable(true);
Expand All @@ -114,6 +117,7 @@ PrpShopMain::PrpShopMain()

QMenu* viewMenu = menuBar()->addMenu(tr("&Tools"));
viewMenu->addAction(fActions[kToolsProperties]);
viewMenu->addAction(fActions[kToolsShowAgePageIDs]);
viewMenu->addAction(fActions[kToolsShowTypeIDs]);
viewMenu->addAction(fActions[kToolsShowObjectIDs]);
viewMenu->addSeparator();
Expand Down Expand Up @@ -184,6 +188,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[kToolsShowObjectIDs], &QAction::toggled,
Expand Down Expand Up @@ -237,6 +243,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());
fActions[kToolsShowObjectIDs]->setChecked(
Expand All @@ -256,6 +264,7 @@ void PrpShopMain::closeEvent(QCloseEvent*)
settings.setValue("WinState", saveState());

settings.setValue("DialogDir", fDialogDir);
settings.setValue("ShowAgePageIDs", s_showAgePageIDs);
settings.setValue("ShowTypeIDs", s_showTypeIDs);
settings.setValue("ShowObjectIDs", s_showObjectIDs);
}
Expand Down Expand Up @@ -1184,6 +1193,21 @@ void PrpShopMain::createNewObject()
}
}

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

// Refresh the folder display for 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 @@ -74,8 +74,8 @@ class PrpShopMain : public QMainWindow
{
// Main Menu
kFileNewPage, kFileOpen, kFileSave, kFileSaveAs, kFileExit,
kToolsProperties, kToolsShowTypeIDs, kToolsShowObjectIDs, kToolsNewObject, kWindowPrev,
kWindowNext, kWindowTile, kWindowCascade, kWindowClose, kWindowCloseAll,
kToolsProperties, kToolsShowAgePageIDs, kToolsShowTypeIDs, kToolsShowObjectIDs, kToolsNewObject,
kWindowPrev, kWindowNext, kWindowTile, kWindowCascade, kWindowClose, kWindowCloseAll,

// Tree Context Menu
kTreeClose, kTreeEdit, kTreeEditPRC, kTreeEditHex, kTreePreview,
Expand Down Expand Up @@ -120,6 +120,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 showObjectIDs(bool show);
void closeWindows(const plLocation& loc);
Expand Down
16 changes: 14 additions & 2 deletions src/PrpShop/QPlasmaTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ QPlasmaTreeItem::QPlasmaTreeItem(QTreeWidgetItem* parent, plPageInfo* page)
reinit();
}

static QString pqFormatPageName(const plPageInfo* page)
{
if (s_showAgePageIDs) {
return QString("[%1;%2] %3")
.arg(page->getLocation().getSeqPrefix())
.arg(page->getLocation().getPageNum())
.arg(st2qstr(page->getPage()));
} else {
return st2qstr(page->getPage());
}
}

void QPlasmaTreeItem::reinit()
{
switch (type()) {
Expand Down Expand Up @@ -137,8 +149,8 @@ void QPlasmaTreeItem::reinit()
break;

case kTypePage:
fSortId = 0;
setText(0, st2qstr(fPage->getPage()));
fSortId = s_showAgePageIDs ? static_cast<int32_t>(fPage->getLocation().unparse()) : 0;
setText(0, pqFormatPageName(fPage));
setIcon(0, QIcon(":/img/page.png"));
break;
}
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;
bool s_showObjectIDs = false;

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

extern bool s_showAgePageIDs;
extern bool s_showTypeIDs;
extern bool s_showObjectIDs;

Expand Down

0 comments on commit 3a87074

Please sign in to comment.