@@ -1,36 +1,38 | |||||
1 | #ifndef SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H |
|
1 | #ifndef SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H | |
2 | #define SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H |
|
2 | #define SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QAbstractTableModel> |
|
5 | #include <QAbstractTableModel> | |
6 |
|
6 | |||
7 | #include <DBEvent.h> |
|
7 | #include <DBEvent.h> | |
8 |
|
8 | |||
9 | class CatalogueEventsTableModel : public QAbstractTableModel { |
|
9 | class CatalogueEventsTableModel : public QAbstractTableModel { | |
10 | public: |
|
10 | public: | |
11 | CatalogueEventsTableModel(QObject *parent = nullptr); |
|
11 | CatalogueEventsTableModel(QObject *parent = nullptr); | |
12 |
|
12 | |||
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; | |
19 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
|
21 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; | |
20 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
|
22 | Qt::ItemFlags flags(const QModelIndex &index) const override; | |
21 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
|
23 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | |
22 | QVariant headerData(int section, Qt::Orientation orientation, |
|
24 | QVariant headerData(int section, Qt::Orientation orientation, | |
23 | int role = Qt::DisplayRole) const override; |
|
25 | int role = Qt::DisplayRole) const override; | |
24 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; |
|
26 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; | |
25 |
|
27 | |||
26 | Qt::DropActions supportedDragActions() const override; |
|
28 | Qt::DropActions supportedDragActions() const override; | |
27 | QStringList mimeTypes() const override; |
|
29 | QStringList mimeTypes() const override; | |
28 | QMimeData *mimeData(const QModelIndexList &indexes) const override; |
|
30 | QMimeData *mimeData(const QModelIndexList &indexes) const override; | |
29 |
|
31 | |||
30 |
|
32 | |||
31 | private: |
|
33 | private: | |
32 | class CatalogueEventsTableModelPrivate; |
|
34 | class CatalogueEventsTableModelPrivate; | |
33 | spimpl::unique_impl_ptr<CatalogueEventsTableModelPrivate> impl; |
|
35 | spimpl::unique_impl_ptr<CatalogueEventsTableModelPrivate> impl; | |
34 | }; |
|
36 | }; | |
35 |
|
37 | |||
36 | #endif // SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H |
|
38 | #endif // SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H |
@@ -1,167 +1,185 | |||||
1 | #include "Catalogue/CatalogueEventsTableModel.h" |
|
1 | #include "Catalogue/CatalogueEventsTableModel.h" | |
2 |
|
2 | |||
3 | #include <Common/DateUtils.h> |
|
3 | #include <Common/DateUtils.h> | |
4 | #include <Common/MimeTypesDef.h> |
|
4 | #include <Common/MimeTypesDef.h> | |
5 | #include <DBEvent.h> |
|
5 | #include <DBEvent.h> | |
6 | #include <DBTag.h> |
|
6 | #include <DBTag.h> | |
7 | #include <Data/SqpRange.h> |
|
7 | #include <Data/SqpRange.h> | |
8 | #include <QMimeData> |
|
8 | #include <QMimeData> | |
9 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
10 | #include <Time/TimeController.h> |
|
10 | #include <Time/TimeController.h> | |
11 |
|
11 | |||
12 | struct CatalogueEventsTableModel::CatalogueEventsTableModelPrivate { |
|
12 | struct CatalogueEventsTableModel::CatalogueEventsTableModelPrivate { | |
13 | QVector<DBEvent> m_Events; |
|
13 | QVector<DBEvent> m_Events; | |
14 |
|
14 | |||
15 | enum class Column { Event, TStart, TEnd, Tags, Product, NbColumn }; |
|
15 | enum class Column { Event, TStart, TEnd, Tags, Product, NbColumn }; | |
16 | QStringList columnNames() |
|
16 | QStringList columnNames() | |
17 | { |
|
17 | { | |
18 | return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")}; |
|
18 | return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")}; | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | QVariant eventData(int col, const DBEvent &event) const |
|
21 | QVariant eventData(int col, const DBEvent &event) const | |
22 | { |
|
22 | { | |
23 | switch (static_cast<Column>(col)) { |
|
23 | switch (static_cast<Column>(col)) { | |
24 | case Column::Event: |
|
24 | case Column::Event: | |
25 | return event.getName(); |
|
25 | return event.getName(); | |
26 | case Column::TStart: |
|
26 | case Column::TStart: | |
27 | return DateUtils::dateTime(event.getTStart()); |
|
27 | return DateUtils::dateTime(event.getTStart()); | |
28 | case Column::TEnd: |
|
28 | case Column::TEnd: | |
29 | return DateUtils::dateTime(event.getTEnd()); |
|
29 | return DateUtils::dateTime(event.getTEnd()); | |
30 | case Column::Product: |
|
30 | case Column::Product: | |
31 | return event.getProduct(); |
|
31 | return event.getProduct(); | |
32 | case Column::Tags: { |
|
32 | case Column::Tags: { | |
33 | QString tagList; |
|
33 | QString tagList; | |
34 | auto tags = const_cast<DBEvent *>(&event)->getTags(); |
|
34 | auto tags = const_cast<DBEvent *>(&event)->getTags(); | |
35 | for (auto tag : tags) { |
|
35 | for (auto tag : tags) { | |
36 | tagList += tag.getName(); |
|
36 | tagList += tag.getName(); | |
37 | tagList += ' '; |
|
37 | tagList += ' '; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | return tagList; |
|
40 | return tagList; | |
41 | } |
|
41 | } | |
42 | default: |
|
42 | default: | |
43 | break; |
|
43 | break; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | Q_ASSERT(false); |
|
46 | Q_ASSERT(false); | |
47 | return QStringLiteral("Unknown Data"); |
|
47 | return QStringLiteral("Unknown Data"); | |
48 | } |
|
48 | } | |
49 | }; |
|
49 | }; | |
50 |
|
50 | |||
51 | CatalogueEventsTableModel::CatalogueEventsTableModel(QObject *parent) |
|
51 | CatalogueEventsTableModel::CatalogueEventsTableModel(QObject *parent) | |
52 | : QAbstractTableModel(parent), |
|
52 | : QAbstractTableModel(parent), | |
53 | impl{spimpl::make_unique_impl<CatalogueEventsTableModelPrivate>()} |
|
53 | impl{spimpl::make_unique_impl<CatalogueEventsTableModelPrivate>()} | |
54 | { |
|
54 | { | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void CatalogueEventsTableModel::setEvents(const QVector<DBEvent> &events) |
|
57 | void CatalogueEventsTableModel::setEvents(const QVector<DBEvent> &events) | |
58 | { |
|
58 | { | |
59 | beginResetModel(); |
|
59 | beginResetModel(); | |
60 | impl->m_Events = events; |
|
60 | impl->m_Events = events; | |
61 | endResetModel(); |
|
61 | endResetModel(); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | DBEvent CatalogueEventsTableModel::getEvent(int row) const |
|
64 | DBEvent CatalogueEventsTableModel::getEvent(int row) const | |
65 | { |
|
65 | { | |
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(); | |
72 | return r; |
|
90 | return r; | |
73 | } |
|
91 | } | |
74 |
|
92 | |||
75 | int CatalogueEventsTableModel::columnCount(const QModelIndex &parent) const |
|
93 | int CatalogueEventsTableModel::columnCount(const QModelIndex &parent) const | |
76 | { |
|
94 | { | |
77 | int c = static_cast<int>(CatalogueEventsTableModelPrivate::Column::NbColumn); |
|
95 | int c = static_cast<int>(CatalogueEventsTableModelPrivate::Column::NbColumn); | |
78 | return c; |
|
96 | return c; | |
79 | } |
|
97 | } | |
80 |
|
98 | |||
81 | Qt::ItemFlags CatalogueEventsTableModel::flags(const QModelIndex &index) const |
|
99 | Qt::ItemFlags CatalogueEventsTableModel::flags(const QModelIndex &index) const | |
82 | { |
|
100 | { | |
83 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; |
|
101 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; | |
84 | } |
|
102 | } | |
85 |
|
103 | |||
86 | QVariant CatalogueEventsTableModel::data(const QModelIndex &index, int role) const |
|
104 | QVariant CatalogueEventsTableModel::data(const QModelIndex &index, int role) const | |
87 | { |
|
105 | { | |
88 | if (index.isValid()) { |
|
106 | if (index.isValid()) { | |
89 | auto event = getEvent(index.row()); |
|
107 | auto event = getEvent(index.row()); | |
90 |
|
108 | |||
91 | switch (role) { |
|
109 | switch (role) { | |
92 | case Qt::DisplayRole: |
|
110 | case Qt::DisplayRole: | |
93 | return impl->eventData(index.column(), event); |
|
111 | return impl->eventData(index.column(), event); | |
94 | break; |
|
112 | break; | |
95 | } |
|
113 | } | |
96 | } |
|
114 | } | |
97 |
|
115 | |||
98 | return QVariant{}; |
|
116 | return QVariant{}; | |
99 | } |
|
117 | } | |
100 |
|
118 | |||
101 | QVariant CatalogueEventsTableModel::headerData(int section, Qt::Orientation orientation, |
|
119 | QVariant CatalogueEventsTableModel::headerData(int section, Qt::Orientation orientation, | |
102 | int role) const |
|
120 | int role) const | |
103 | { |
|
121 | { | |
104 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { |
|
122 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { | |
105 | return impl->columnNames().value(section); |
|
123 | return impl->columnNames().value(section); | |
106 | } |
|
124 | } | |
107 |
|
125 | |||
108 | return QVariant(); |
|
126 | return QVariant(); | |
109 | } |
|
127 | } | |
110 |
|
128 | |||
111 | void CatalogueEventsTableModel::sort(int column, Qt::SortOrder order) |
|
129 | void CatalogueEventsTableModel::sort(int column, Qt::SortOrder order) | |
112 | { |
|
130 | { | |
113 | std::sort(impl->m_Events.begin(), impl->m_Events.end(), |
|
131 | std::sort(impl->m_Events.begin(), impl->m_Events.end(), | |
114 | [this, column, order](auto e1, auto e2) { |
|
132 | [this, column, order](auto e1, auto e2) { | |
115 | auto data1 = impl->eventData(column, e1); |
|
133 | auto data1 = impl->eventData(column, e1); | |
116 | auto data2 = impl->eventData(column, e2); |
|
134 | auto data2 = impl->eventData(column, e2); | |
117 |
|
135 | |||
118 | auto result = data1.toString() < data2.toString(); |
|
136 | auto result = data1.toString() < data2.toString(); | |
119 |
|
137 | |||
120 | return order == Qt::AscendingOrder ? result : !result; |
|
138 | return order == Qt::AscendingOrder ? result : !result; | |
121 | }); |
|
139 | }); | |
122 |
|
140 | |||
123 | emit dataChanged(QModelIndex(), QModelIndex()); |
|
141 | emit dataChanged(QModelIndex(), QModelIndex()); | |
124 | } |
|
142 | } | |
125 |
|
143 | |||
126 | Qt::DropActions CatalogueEventsTableModel::supportedDragActions() const |
|
144 | Qt::DropActions CatalogueEventsTableModel::supportedDragActions() const | |
127 | { |
|
145 | { | |
128 | return Qt::CopyAction | Qt::MoveAction; |
|
146 | return Qt::CopyAction | Qt::MoveAction; | |
129 | } |
|
147 | } | |
130 |
|
148 | |||
131 | QStringList CatalogueEventsTableModel::mimeTypes() const |
|
149 | QStringList CatalogueEventsTableModel::mimeTypes() const | |
132 | { |
|
150 | { | |
133 | return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE}; |
|
151 | return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE}; | |
134 | } |
|
152 | } | |
135 |
|
153 | |||
136 | QMimeData *CatalogueEventsTableModel::mimeData(const QModelIndexList &indexes) const |
|
154 | QMimeData *CatalogueEventsTableModel::mimeData(const QModelIndexList &indexes) const | |
137 | { |
|
155 | { | |
138 | auto mimeData = new QMimeData; |
|
156 | auto mimeData = new QMimeData; | |
139 |
|
157 | |||
140 | QVector<DBEvent> eventList; |
|
158 | QVector<DBEvent> eventList; | |
141 |
|
159 | |||
142 | SqpRange firstTimeRange; |
|
160 | SqpRange firstTimeRange; | |
143 | for (const auto &index : indexes) { |
|
161 | for (const auto &index : indexes) { | |
144 | if (index.column() == 0) { // only the first column |
|
162 | if (index.column() == 0) { // only the first column | |
145 | auto event = getEvent(index.row()); |
|
163 | auto event = getEvent(index.row()); | |
146 | if (eventList.isEmpty()) { |
|
164 | if (eventList.isEmpty()) { | |
147 | // Gets the range of the first variable |
|
165 | // Gets the range of the first variable | |
148 | firstTimeRange.m_TStart = event.getTStart(); |
|
166 | firstTimeRange.m_TStart = event.getTStart(); | |
149 | firstTimeRange.m_TEnd = event.getTEnd(); |
|
167 | firstTimeRange.m_TEnd = event.getTEnd(); | |
150 | } |
|
168 | } | |
151 |
|
169 | |||
152 | eventList << event; |
|
170 | eventList << event; | |
153 | } |
|
171 | } | |
154 | } |
|
172 | } | |
155 |
|
173 | |||
156 | auto eventsEncodedData |
|
174 | auto eventsEncodedData | |
157 | = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO |
|
175 | = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO | |
158 | mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData); |
|
176 | mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData); | |
159 |
|
177 | |||
160 | if (eventList.count() == 1) { |
|
178 | if (eventList.count() == 1) { | |
161 | // No time range MIME data if multiple events are dragged |
|
179 | // No time range MIME data if multiple events are dragged | |
162 | auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange); |
|
180 | auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange); | |
163 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData); |
|
181 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData); | |
164 | } |
|
182 | } | |
165 |
|
183 | |||
166 | return mimeData; |
|
184 | return mimeData; | |
167 | } |
|
185 | } |
@@ -1,95 +1,113 | |||||
1 | #include "Catalogue/CatalogueEventsWidget.h" |
|
1 | #include "Catalogue/CatalogueEventsWidget.h" | |
2 | #include "ui_CatalogueEventsWidget.h" |
|
2 | #include "ui_CatalogueEventsWidget.h" | |
3 |
|
3 | |||
4 | #include <Catalogue/CatalogueController.h> |
|
4 | #include <Catalogue/CatalogueController.h> | |
5 | #include <Catalogue/CatalogueEventsTableModel.h> |
|
5 | #include <Catalogue/CatalogueEventsTableModel.h> | |
6 | #include <CatalogueDao.h> |
|
6 | #include <CatalogueDao.h> | |
7 | #include <DBCatalogue.h> |
|
7 | #include <DBCatalogue.h> | |
8 | #include <SqpApplication.h> |
|
8 | #include <SqpApplication.h> | |
9 |
|
9 | |||
10 |
|
10 | |||
11 | /// Format of the dates appearing in the label of a cursor |
|
11 | /// Format of the dates appearing in the label of a cursor | |
12 | const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss"); |
|
12 | const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss"); | |
13 |
|
13 | |||
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 | |||
20 | CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) |
|
41 | CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |
21 | : QWidget(parent), |
|
42 | : QWidget(parent), | |
22 | ui(new Ui::CatalogueEventsWidget), |
|
43 | ui(new Ui::CatalogueEventsWidget), | |
23 | impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()} |
|
44 | impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()} | |
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) { | |
37 | ui->btnChart->setChecked(false); |
|
57 | ui->btnChart->setChecked(false); | |
38 | } |
|
58 | } | |
39 | }); |
|
59 | }); | |
40 |
|
60 | |||
41 | connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) { |
|
61 | connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) { | |
42 | if (checked) { |
|
62 | if (checked) { | |
43 | ui->btnTime->setChecked(false); |
|
63 | ui->btnTime->setChecked(false); | |
44 | } |
|
64 | } | |
45 | }); |
|
65 | }); | |
46 |
|
66 | |||
47 | auto emitSelection = [this]() { |
|
67 | auto emitSelection = [this]() { | |
48 | QVector<DBEvent> events; |
|
68 | QVector<DBEvent> events; | |
49 | for (auto rowIndex : ui->tableView->selectionModel()->selectedRows()) { |
|
69 | for (auto rowIndex : ui->tableView->selectionModel()->selectedRows()) { | |
50 | events << impl->m_Model->getEvent(rowIndex.row()); |
|
70 | events << impl->m_Model->getEvent(rowIndex.row()); | |
51 | } |
|
71 | } | |
52 |
|
72 | |||
53 | emit this->eventsSelected(events); |
|
73 | emit this->eventsSelected(events); | |
54 | }; |
|
74 | }; | |
55 |
|
75 | |||
56 | connect(ui->tableView, &QTableView::clicked, emitSelection); |
|
76 | connect(ui->tableView, &QTableView::clicked, emitSelection); | |
57 | connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection); |
|
77 | connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection); | |
58 |
|
78 | |||
59 | connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { |
|
79 | connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { | |
60 | auto isNotMultiSelection = ui->tableView->selectionModel()->selectedRows().count() <= 1; |
|
80 | auto isNotMultiSelection = ui->tableView->selectionModel()->selectedRows().count() <= 1; | |
61 | ui->btnChart->setEnabled(isNotMultiSelection); |
|
81 | ui->btnChart->setEnabled(isNotMultiSelection); | |
62 | ui->btnTime->setEnabled(isNotMultiSelection); |
|
82 | ui->btnTime->setEnabled(isNotMultiSelection); | |
63 | }); |
|
83 | }); | |
64 |
|
84 | |||
65 | ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); |
|
85 | ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); | |
66 | ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); |
|
86 | ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); | |
67 | ui->tableView->horizontalHeader()->setSortIndicatorShown(true); |
|
87 | ui->tableView->horizontalHeader()->setSortIndicatorShown(true); | |
68 | } |
|
88 | } | |
69 |
|
89 | |||
70 | CatalogueEventsWidget::~CatalogueEventsWidget() |
|
90 | CatalogueEventsWidget::~CatalogueEventsWidget() | |
71 | { |
|
91 | { | |
72 | delete ui; |
|
92 | delete ui; | |
73 | } |
|
93 | } | |
74 |
|
94 | |||
75 | void CatalogueEventsWidget::populateWithCatalogues(const QVector<DBCatalogue> &catalogues) |
|
95 | void CatalogueEventsWidget::populateWithCatalogues(const QVector<DBCatalogue> &catalogues) | |
76 | { |
|
96 | { | |
77 | auto &dao = sqpApp->catalogueController().getDao(); |
|
97 | auto &dao = sqpApp->catalogueController().getDao(); | |
78 |
|
98 | |||
79 | QSet<QUuid> eventIds; |
|
99 | QSet<QUuid> eventIds; | |
80 | QVector<DBEvent> events; |
|
100 | QVector<DBEvent> events; | |
81 |
|
101 | |||
82 | for (auto catalogue : catalogues) { |
|
102 | for (auto catalogue : catalogues) { | |
83 | auto catalogueEvents = dao.getCatalogueEvents(catalogue); |
|
103 | auto catalogueEvents = dao.getCatalogueEvents(catalogue); | |
84 | for (auto event : catalogueEvents) { |
|
104 | for (auto event : catalogueEvents) { | |
85 | if (!eventIds.contains(event.getUniqId())) { |
|
105 | if (!eventIds.contains(event.getUniqId())) { | |
86 | events << event; |
|
106 | events << event; | |
87 | eventIds.insert(event.getUniqId()); |
|
107 | eventIds.insert(event.getUniqId()); | |
88 | } |
|
108 | } | |
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 | } |
@@ -1,151 +1,166 | |||||
1 | #include "Catalogue/CatalogueSideBarWidget.h" |
|
1 | #include "Catalogue/CatalogueSideBarWidget.h" | |
2 | #include "ui_CatalogueSideBarWidget.h" |
|
2 | #include "ui_CatalogueSideBarWidget.h" | |
3 | #include <SqpApplication.h> |
|
3 | #include <SqpApplication.h> | |
4 |
|
4 | |||
5 | #include <Catalogue/CatalogueController.h> |
|
5 | #include <Catalogue/CatalogueController.h> | |
6 | #include <Catalogue/CatalogueTreeWidgetItem.h> |
|
6 | #include <Catalogue/CatalogueTreeWidgetItem.h> | |
7 | #include <CatalogueDao.h> |
|
7 | #include <CatalogueDao.h> | |
8 | #include <ComparaisonPredicate.h> |
|
8 | #include <ComparaisonPredicate.h> | |
9 | #include <DBCatalogue.h> |
|
9 | #include <DBCatalogue.h> | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType; |
|
12 | constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType; | |
13 | constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1; |
|
13 | constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1; | |
14 | constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2; |
|
14 | constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2; | |
15 | constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3; |
|
15 | constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3; | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { |
|
18 | struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { | |
19 |
|
19 | |||
20 | QHash<QTreeWidgetItem *, DBCatalogue> m_CatalogueMap; |
|
20 | QHash<QTreeWidgetItem *, DBCatalogue> m_CatalogueMap; | |
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 | |||
27 | CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) |
|
28 | CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) | |
28 | : QWidget(parent), |
|
29 | : QWidget(parent), | |
29 | ui(new Ui::CatalogueSideBarWidget), |
|
30 | ui(new Ui::CatalogueSideBarWidget), | |
30 | impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()} |
|
31 | impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()} | |
31 | { |
|
32 | { | |
32 | ui->setupUi(this); |
|
33 | ui->setupUi(this); | |
33 | impl->configureTreeWidget(ui->treeWidget); |
|
34 | impl->configureTreeWidget(ui->treeWidget); | |
34 |
|
35 | |||
35 | auto emitSelection = [this]() { |
|
36 | auto emitSelection = [this]() { | |
36 |
|
37 | |||
37 | auto selectedItems = ui->treeWidget->selectedItems(); |
|
38 | auto selectedItems = ui->treeWidget->selectedItems(); | |
38 | if (selectedItems.isEmpty()) { |
|
39 | if (selectedItems.isEmpty()) { | |
39 | emit this->selectionCleared(); |
|
40 | emit this->selectionCleared(); | |
40 | } |
|
41 | } | |
41 | else { |
|
42 | else { | |
42 | QVector<DBCatalogue> catalogues; |
|
43 | QVector<DBCatalogue> catalogues; | |
43 | QStringList databases; |
|
44 | QStringList databases; | |
44 | int selectionType = selectedItems.first()->type(); |
|
45 | int selectionType = selectedItems.first()->type(); | |
45 |
|
46 | |||
46 | for (auto item : ui->treeWidget->selectedItems()) { |
|
47 | for (auto item : ui->treeWidget->selectedItems()) { | |
47 | if (item->type() == selectionType) { |
|
48 | if (item->type() == selectionType) { | |
48 | switch (selectionType) { |
|
49 | switch (selectionType) { | |
49 | case CATALOGUE_ITEM_TYPE: |
|
50 | case CATALOGUE_ITEM_TYPE: | |
50 | catalogues.append( |
|
51 | catalogues.append( | |
51 | static_cast<CatalogueTreeWidgetItem *>(item)->catalogue()); |
|
52 | static_cast<CatalogueTreeWidgetItem *>(item)->catalogue()); | |
52 | break; |
|
53 | break; | |
53 | case DATABASE_ITEM_TYPE: |
|
54 | case DATABASE_ITEM_TYPE: | |
54 | selectionType = DATABASE_ITEM_TYPE; |
|
55 | selectionType = DATABASE_ITEM_TYPE; | |
55 | databases.append(item->text(0)); |
|
56 | databases.append(item->text(0)); | |
56 | case ALL_EVENT_ITEM_TYPE: // fallthrough |
|
57 | case ALL_EVENT_ITEM_TYPE: // fallthrough | |
57 | case TRASH_ITEM_TYPE: // fallthrough |
|
58 | case TRASH_ITEM_TYPE: // fallthrough | |
58 | default: |
|
59 | default: | |
59 | break; |
|
60 | break; | |
60 | } |
|
61 | } | |
61 | } |
|
62 | } | |
62 | else { |
|
63 | else { | |
63 | // Incoherent multi selection |
|
64 | // Incoherent multi selection | |
64 | selectionType = -1; |
|
65 | selectionType = -1; | |
65 | break; |
|
66 | break; | |
66 | } |
|
67 | } | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
69 | switch (selectionType) { |
|
70 | switch (selectionType) { | |
70 | case CATALOGUE_ITEM_TYPE: |
|
71 | case CATALOGUE_ITEM_TYPE: | |
71 | emit this->catalogueSelected(catalogues); |
|
72 | emit this->catalogueSelected(catalogues); | |
72 | break; |
|
73 | break; | |
73 | case DATABASE_ITEM_TYPE: |
|
74 | case DATABASE_ITEM_TYPE: | |
74 | emit this->databaseSelected(databases); |
|
75 | emit this->databaseSelected(databases); | |
75 | break; |
|
76 | break; | |
76 | case ALL_EVENT_ITEM_TYPE: |
|
77 | case ALL_EVENT_ITEM_TYPE: | |
77 | emit this->allEventsSelected(); |
|
78 | emit this->allEventsSelected(); | |
78 | break; |
|
79 | break; | |
79 | case TRASH_ITEM_TYPE: |
|
80 | case TRASH_ITEM_TYPE: | |
80 | emit this->trashSelected(); |
|
81 | emit this->trashSelected(); | |
81 | break; |
|
82 | break; | |
82 | default: |
|
83 | default: | |
83 | emit this->selectionCleared(); |
|
84 | emit this->selectionCleared(); | |
84 | break; |
|
85 | break; | |
85 | } |
|
86 | } | |
86 | } |
|
87 | } | |
87 |
|
88 | |||
88 |
|
89 | |||
89 | }; |
|
90 | }; | |
90 |
|
91 | |||
91 | connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection); |
|
92 | connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection); | |
92 | connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection); |
|
93 | connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection); | |
93 | } |
|
94 | } | |
94 |
|
95 | |||
95 | CatalogueSideBarWidget::~CatalogueSideBarWidget() |
|
96 | CatalogueSideBarWidget::~CatalogueSideBarWidget() | |
96 | { |
|
97 | { | |
97 | delete ui; |
|
98 | delete ui; | |
98 | } |
|
99 | } | |
99 |
|
100 | |||
100 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget( |
|
101 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget( | |
101 | QTreeWidget *treeWidget) |
|
102 | QTreeWidget *treeWidget) | |
102 | { |
|
103 | { | |
103 | auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE}; |
|
104 | auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE}; | |
104 | allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png")); |
|
105 | allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png")); | |
105 | treeWidget->addTopLevelItem(allEventsItem); |
|
106 | treeWidget->addTopLevelItem(allEventsItem); | |
106 |
|
107 | |||
107 | auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE}; |
|
108 | auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE}; | |
108 | trashItem->setIcon(0, QIcon(":/icones/trash.png")); |
|
109 | trashItem->setIcon(0, QIcon(":/icones/trash.png")); | |
109 | treeWidget->addTopLevelItem(trashItem); |
|
110 | treeWidget->addTopLevelItem(trashItem); | |
110 |
|
111 | |||
111 | auto separator = new QFrame{treeWidget}; |
|
112 | auto separator = new QFrame{treeWidget}; | |
112 | separator->setFrameShape(QFrame::HLine); |
|
113 | separator->setFrameShape(QFrame::HLine); | |
113 |
|
114 | |||
114 | auto separatorItem = new QTreeWidgetItem{}; |
|
115 | auto separatorItem = new QTreeWidgetItem{}; | |
115 | separatorItem->setFlags(Qt::NoItemFlags); |
|
116 | separatorItem->setFlags(Qt::NoItemFlags); | |
116 | treeWidget->addTopLevelItem(separatorItem); |
|
117 | treeWidget->addTopLevelItem(separatorItem); | |
117 | treeWidget->setItemWidget(separatorItem, 0, separator); |
|
118 | treeWidget->setItemWidget(separatorItem, 0, separator); | |
118 |
|
119 | |||
119 | // Test |
|
120 | // Test | |
120 | auto &dao = sqpApp->catalogueController().getDao(); |
|
121 | auto &dao = sqpApp->catalogueController().getDao(); | |
121 | auto allPredicate = std::make_shared<ComparaisonPredicate>(QString{"uniqId"}, "-1", |
|
122 | auto allPredicate = std::make_shared<ComparaisonPredicate>(QString{"uniqId"}, "-1", | |
122 | ComparaisonOperation::DIFFERENT); |
|
123 | ComparaisonOperation::DIFFERENT); | |
123 |
|
124 | |||
124 | auto db = addDatabaseItem("Default", treeWidget); |
|
125 | auto db = addDatabaseItem("Default", treeWidget); | |
125 |
|
126 | |||
126 | auto catalogues = dao.getCatalogues(allPredicate); |
|
127 | auto catalogues = dao.getCatalogues(allPredicate); | |
127 | for (auto catalogue : catalogues) { |
|
128 | for (auto catalogue : catalogues) { | |
128 | addCatalogueItem(catalogue, db); |
|
129 | addCatalogueItem(catalogue, db); | |
129 | } |
|
130 | } | |
130 |
|
131 | |||
131 | treeWidget->expandAll(); |
|
132 | treeWidget->expandAll(); | |
132 | } |
|
133 | } | |
133 |
|
134 | |||
134 | QTreeWidgetItem * |
|
135 | QTreeWidgetItem * | |
135 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name, |
|
136 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name, | |
136 | QTreeWidget *treeWidget) |
|
137 | QTreeWidget *treeWidget) | |
137 | { |
|
138 | { | |
138 | auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE}; |
|
139 | auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE}; | |
139 | databaseItem->setIcon(0, QIcon{":/icones/database.png"}); |
|
140 | databaseItem->setIcon(0, QIcon{":/icones/database.png"}); | |
140 | treeWidget->addTopLevelItem(databaseItem); |
|
141 | treeWidget->addTopLevelItem(databaseItem); | |
141 |
|
142 | |||
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 | { | |
148 | auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE}; |
|
163 | auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE}; | |
149 | catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"}); |
|
164 | catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"}); | |
150 | parentDatabaseItem->addChild(catalogueItem); |
|
165 | parentDatabaseItem->addChild(catalogueItem); | |
151 | } |
|
166 | } |
General Comments 0
You need to be logged in to leave comments.
Login now