##// END OF EJS Templates
Methods to facilitate add/remove operations
trabillard -
r1134:9ee6cd254cb4
parent child
Show More
@@ -13,6 +13,8 public:
13 void setEvents(const QVector<DBEvent> &events);
13 void setEvents(const QVector<DBEvent> &events);
14 DBEvent getEvent(int row) const;
14 DBEvent getEvent(int row) const;
15
15
16 void addEvent(const DBEvent &events);
17 void removeEvent(const DBEvent &events);
16
18
17 // Model
19 // Model
18 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
20 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
@@ -66,6 +66,24 DBEvent CatalogueEventsTableModel::getEvent(int row) const
66 return impl->m_Events.value(row);
66 return impl->m_Events.value(row);
67 }
67 }
68
68
69 void CatalogueEventsTableModel::addEvent(const DBEvent &events)
70 {
71 beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1);
72 // impl->m_Events.append(event); TODO
73 endInsertRows();
74 }
75
76 void CatalogueEventsTableModel::removeEvent(const DBEvent &events)
77 {
78 // TODO
79 auto index = -1; // impl->m_Events.indexOf(event);
80 if (index >= 0) {
81 beginRemoveRows(QModelIndex(), index, index);
82 impl->m_Events.removeAt(index);
83 endRemoveRows();
84 }
85 }
86
69 int CatalogueEventsTableModel::rowCount(const QModelIndex &parent) const
87 int CatalogueEventsTableModel::rowCount(const QModelIndex &parent) const
70 {
88 {
71 int r = impl->m_Events.count();
89 int r = impl->m_Events.count();
@@ -14,6 +14,27 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss");
14 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
14 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
15
15
16 CatalogueEventsTableModel *m_Model = nullptr;
16 CatalogueEventsTableModel *m_Model = nullptr;
17
18 void setEvents(const QVector<DBEvent> &events, QTableView *tableView)
19 {
20 tableView->setSortingEnabled(false);
21 m_Model->setEvents(events);
22 tableView->setSortingEnabled(true);
23 }
24
25 void addEvent(const DBEvent &event, QTableView *tableView)
26 {
27 tableView->setSortingEnabled(false);
28 m_Model->addEvent(event);
29 tableView->setSortingEnabled(true);
30 }
31
32 void removeEvent(const DBEvent &event, QTableView *tableView)
33 {
34 tableView->setSortingEnabled(false);
35 m_Model->removeEvent(event);
36 tableView->setSortingEnabled(true);
37 }
17 };
38 };
18
39
19
40
@@ -24,13 +45,12 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
24 {
45 {
25 ui->setupUi(this);
46 ui->setupUi(this);
26
47
27 ui->tableView->setDragDropMode(QAbstractItemView::DragDrop);
28 ui->tableView->setDragEnabled(true);
29
30 impl->m_Model = new CatalogueEventsTableModel{this};
48 impl->m_Model = new CatalogueEventsTableModel{this};
31 ui->tableView->setModel(impl->m_Model);
49 ui->tableView->setModel(impl->m_Model);
32
50
33 ui->tableView->setSortingEnabled(true);
51 ui->tableView->setSortingEnabled(true);
52 ui->tableView->setDragDropMode(QAbstractItemView::DragDrop);
53 ui->tableView->setDragEnabled(true);
34
54
35 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
55 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
36 if (checked) {
56 if (checked) {
@@ -89,7 +109,5 void CatalogueEventsWidget::populateWithCatalogues(const QVector<DBCatalogue> &c
89 }
109 }
90 }
110 }
91
111
92 ui->tableView->setSortingEnabled(false);
112 impl->setEvents(events, ui->tableView);
93 impl->m_Model->setEvents(events);
94 ui->tableView->setSortingEnabled(true);
95 }
113 }
@@ -21,6 +21,7 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
21
21
22 void configureTreeWidget(QTreeWidget *treeWidget);
22 void configureTreeWidget(QTreeWidget *treeWidget);
23 QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget);
23 QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget);
24 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
24 void addCatalogueItem(const DBCatalogue &catalogue, QTreeWidgetItem *parentDatabaseItem);
25 void addCatalogueItem(const DBCatalogue &catalogue, QTreeWidgetItem *parentDatabaseItem);
25 };
26 };
26
27
@@ -142,6 +143,20 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QSt
142 return databaseItem;
143 return databaseItem;
143 }
144 }
144
145
146 QTreeWidgetItem *
147 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name,
148 QTreeWidget *treeWidget)
149 {
150 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
151 auto item = treeWidget->topLevelItem(i);
152 if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) {
153 return item;
154 }
155 }
156
157 return nullptr;
158 }
159
145 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
160 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
146 const DBCatalogue &catalogue, QTreeWidgetItem *parentDatabaseItem)
161 const DBCatalogue &catalogue, QTreeWidgetItem *parentDatabaseItem)
147 {
162 {
General Comments 0
You need to be logged in to leave comments. Login now