CatalogueSideBarWidget.cpp
81 lines
| 2.9 KiB
| text/x-c
|
CppLexer
r1095 | #include "Catalogue/CatalogueSideBarWidget.h" | |||
#include "ui_CatalogueSideBarWidget.h" | ||||
r1098 | auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType; | |||
auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1; | ||||
auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2; | ||||
auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3; | ||||
struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { | ||||
void configureTreeWidget(QTreeWidget *treeWidget); | ||||
r1102 | QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget); | |||
void addCatalogueItem(const QString &name, QTreeWidgetItem *parentDatabaseItem); | ||||
r1098 | }; | |||
r1095 | CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) | |||
r1098 | : QWidget(parent), | |||
ui(new Ui::CatalogueSideBarWidget), | ||||
impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()} | ||||
r1095 | { | |||
ui->setupUi(this); | ||||
r1098 | impl->configureTreeWidget(ui->treeWidget); | |||
r1095 | } | |||
CatalogueSideBarWidget::~CatalogueSideBarWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
r1098 | ||||
void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget( | ||||
QTreeWidget *treeWidget) | ||||
{ | ||||
auto allEventsItem = new QTreeWidgetItem({"All Events"}, ALL_EVENT_ITEM_TYPE); | ||||
allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png")); | ||||
treeWidget->addTopLevelItem(allEventsItem); | ||||
auto trashItem = new QTreeWidgetItem({"Trash"}, TRASH_ITEM_TYPE); | ||||
trashItem->setIcon(0, QIcon(":/icones/trash.png")); | ||||
treeWidget->addTopLevelItem(trashItem); | ||||
auto separator = new QFrame(treeWidget); | ||||
separator->setFrameShape(QFrame::HLine); | ||||
auto separatorItem = new QTreeWidgetItem(); | ||||
separatorItem->setFlags(Qt::NoItemFlags); | ||||
treeWidget->addTopLevelItem(separatorItem); | ||||
treeWidget->setItemWidget(separatorItem, 0, separator); | ||||
r1102 | ||||
// Test | ||||
auto db = addDatabaseItem("Database 1", treeWidget); | ||||
addCatalogueItem("Catalogue 1", db); | ||||
addCatalogueItem("Catalogue 2", db); | ||||
addCatalogueItem("Catalogue 3", db); | ||||
addCatalogueItem("Catalogue 4", db); | ||||
auto db2 = addDatabaseItem("Database 2", treeWidget); | ||||
addCatalogueItem("Catalogue A", db2); | ||||
addCatalogueItem("Catalogue B", db2); | ||||
addCatalogueItem("Catalogue C", db2); | ||||
treeWidget->expandAll(); | ||||
} | ||||
QTreeWidgetItem * | ||||
CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name, | ||||
QTreeWidget *treeWidget) | ||||
{ | ||||
auto databaseItem = new QTreeWidgetItem({name}, DATABASE_ITEM_TYPE); | ||||
databaseItem->setIcon(0, QIcon(":/icones/database.png")); | ||||
treeWidget->addTopLevelItem(databaseItem); | ||||
return databaseItem; | ||||
} | ||||
void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( | ||||
const QString &name, QTreeWidgetItem *parentDatabaseItem) | ||||
{ | ||||
auto catalogueItem = new QTreeWidgetItem({name}, CATALOGUE_ITEM_TYPE); | ||||
catalogueItem->setIcon(0, QIcon(":/icones/catalogue.png")); | ||||
parentDatabaseItem->addChild(catalogueItem); | ||||
r1098 | } | |||