Auto status change to "Under Review"
@@ -0,0 +1,33 | |||
|
1 | #ifndef SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H | |
|
2 | #define SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H | |
|
3 | ||
|
4 | #include <Common/spimpl.h> | |
|
5 | #include <QAbstractTableModel> | |
|
6 | ||
|
7 | #include <DBEvent.h> | |
|
8 | ||
|
9 | class CatalogueEventsTableModel : public QAbstractTableModel { | |
|
10 | public: | |
|
11 | CatalogueEventsTableModel(QObject *parent = nullptr); | |
|
12 | ||
|
13 | void setEvents(const QVector<DBEvent> &events); | |
|
14 | DBEvent getEvent(int row) const; | |
|
15 | ||
|
16 | ||
|
17 | // Model | |
|
18 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | |
|
19 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; | |
|
20 | Qt::ItemFlags flags(const QModelIndex &index) const override; | |
|
21 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | |
|
22 | QVariant headerData(int section, Qt::Orientation orientation, | |
|
23 | int role = Qt::DisplayRole) const override; | |
|
24 | ||
|
25 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; | |
|
26 | ||
|
27 | ||
|
28 | private: | |
|
29 | class CatalogueEventsTableModelPrivate; | |
|
30 | spimpl::unique_impl_ptr<CatalogueEventsTableModelPrivate> impl; | |
|
31 | }; | |
|
32 | ||
|
33 | #endif // SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H |
@@ -0,0 +1,119 | |||
|
1 | #include "Catalogue/CatalogueEventsTableModel.h" | |
|
2 | ||
|
3 | #include <Common/DateUtils.h> | |
|
4 | #include <DBEvent.h> | |
|
5 | #include <DBTag.h> | |
|
6 | ||
|
7 | struct CatalogueEventsTableModel::CatalogueEventsTableModelPrivate { | |
|
8 | QVector<DBEvent> m_Events; | |
|
9 | ||
|
10 | enum class Column { Event, TStart, TEnd, Tags, Product, NbColumn }; | |
|
11 | QStringList columnNames() | |
|
12 | { | |
|
13 | return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")}; | |
|
14 | } | |
|
15 | ||
|
16 | QVariant eventData(int col, const DBEvent &event) const | |
|
17 | { | |
|
18 | switch (static_cast<Column>(col)) { | |
|
19 | case Column::Event: | |
|
20 | return event.getName(); | |
|
21 | case Column::TStart: | |
|
22 | return DateUtils::dateTime(event.getTStart()); | |
|
23 | case Column::TEnd: | |
|
24 | return DateUtils::dateTime(event.getTEnd()); | |
|
25 | case Column::Product: | |
|
26 | return event.getProduct(); | |
|
27 | case Column::Tags: { | |
|
28 | QString tagList; | |
|
29 | auto tags = const_cast<DBEvent *>(&event)->getTags(); | |
|
30 | for (auto tag : tags) { | |
|
31 | tagList += tag.getName(); | |
|
32 | tagList += ' '; | |
|
33 | } | |
|
34 | ||
|
35 | return tagList; | |
|
36 | } | |
|
37 | default: | |
|
38 | break; | |
|
39 | } | |
|
40 | ||
|
41 | Q_ASSERT(false); | |
|
42 | return QStringLiteral("Unknown Data"); | |
|
43 | } | |
|
44 | }; | |
|
45 | ||
|
46 | CatalogueEventsTableModel::CatalogueEventsTableModel(QObject *parent) | |
|
47 | : QAbstractTableModel(parent), | |
|
48 | impl{spimpl::make_unique_impl<CatalogueEventsTableModelPrivate>()} | |
|
49 | { | |
|
50 | } | |
|
51 | ||
|
52 | void CatalogueEventsTableModel::setEvents(const QVector<DBEvent> &events) | |
|
53 | { | |
|
54 | beginResetModel(); | |
|
55 | impl->m_Events = events; | |
|
56 | endResetModel(); | |
|
57 | } | |
|
58 | ||
|
59 | DBEvent CatalogueEventsTableModel::getEvent(int row) const | |
|
60 | { | |
|
61 | return impl->m_Events.value(row); | |
|
62 | } | |
|
63 | ||
|
64 | int CatalogueEventsTableModel::rowCount(const QModelIndex &parent) const | |
|
65 | { | |
|
66 | int r = impl->m_Events.count(); | |
|
67 | return r; | |
|
68 | } | |
|
69 | ||
|
70 | int CatalogueEventsTableModel::columnCount(const QModelIndex &parent) const | |
|
71 | { | |
|
72 | int c = static_cast<int>(CatalogueEventsTableModelPrivate::Column::NbColumn); | |
|
73 | return c; | |
|
74 | } | |
|
75 | ||
|
76 | Qt::ItemFlags CatalogueEventsTableModel::flags(const QModelIndex &index) const | |
|
77 | { | |
|
78 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable; | |
|
79 | } | |
|
80 | ||
|
81 | QVariant CatalogueEventsTableModel::data(const QModelIndex &index, int role) const | |
|
82 | { | |
|
83 | if (index.isValid()) { | |
|
84 | auto event = impl->m_Events.value(index.row()); | |
|
85 | ||
|
86 | switch (role) { | |
|
87 | case Qt::DisplayRole: | |
|
88 | return impl->eventData(index.column(), event); | |
|
89 | break; | |
|
90 | } | |
|
91 | } | |
|
92 | ||
|
93 | return QVariant{}; | |
|
94 | } | |
|
95 | ||
|
96 | QVariant CatalogueEventsTableModel::headerData(int section, Qt::Orientation orientation, | |
|
97 | int role) const | |
|
98 | { | |
|
99 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { | |
|
100 | return impl->columnNames().value(section); | |
|
101 | } | |
|
102 | ||
|
103 | return QVariant(); | |
|
104 | } | |
|
105 | ||
|
106 | void CatalogueEventsTableModel::sort(int column, Qt::SortOrder order) | |
|
107 | { | |
|
108 | std::sort(impl->m_Events.begin(), impl->m_Events.end(), | |
|
109 | [this, column, order](auto e1, auto e2) { | |
|
110 | auto data1 = impl->eventData(column, e1); | |
|
111 | auto data2 = impl->eventData(column, e2); | |
|
112 | ||
|
113 | auto result = data1.toString() < data2.toString(); | |
|
114 | ||
|
115 | return order == Qt::AscendingOrder ? result : !result; | |
|
116 | }); | |
|
117 | ||
|
118 | emit dataChanged(QModelIndex(), QModelIndex()); | |
|
119 | } |
@@ -40,7 +40,7 ExternalProject_Add( | |||
|
40 | 40 | GIT_REPOSITORY https://perrinel@hephaistos.lpp.polytechnique.fr/rhodecode/GIT_REPOSITORIES/LPP/Users/mperrinel/CatalogueAPI |
|
41 | 41 | GIT_TAG develop |
|
42 | 42 | |
|
43 | UPDATE_COMMAND ${GIT_EXECUTABLE} pull | |
|
43 | UPDATE_COMMAND ${GIT_EXECUTABLE} pull origin develop | |
|
44 | 44 | PATCH_COMMAND "" |
|
45 | 45 | |
|
46 | 46 | SOURCE_DIR "${CATALOGUEAPI_SOURCES_PATH}" |
@@ -107,7 +107,8 gui_sources = [ | |||
|
107 | 107 | 'src/Catalogue/CatalogueEventsWidget.cpp', |
|
108 | 108 | 'src/Catalogue/CatalogueSideBarWidget.cpp', |
|
109 | 109 | 'src/Catalogue/CatalogueInspectorWidget.cpp', |
|
110 | 'src/Catalogue/CatalogueTreeWidgetItem.cpp' | |
|
110 | 'src/Catalogue/CatalogueTreeWidgetItem.cpp', | |
|
111 | 'src/Catalogue/CatalogueEventsTableModel.cpp' | |
|
111 | 112 | ] |
|
112 | 113 | |
|
113 | 114 | gui_inc = include_directories(['include']) |
@@ -2,6 +2,7 | |||
|
2 | 2 | #include "ui_CatalogueEventsWidget.h" |
|
3 | 3 | |
|
4 | 4 | #include <Catalogue/CatalogueController.h> |
|
5 | #include <Catalogue/CatalogueEventsTableModel.h> | |
|
5 | 6 | #include <CatalogueDao.h> |
|
6 | 7 | #include <DBCatalogue.h> |
|
7 | 8 | #include <SqpApplication.h> |
@@ -11,12 +12,8 | |||
|
11 | 12 | const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss"); |
|
12 | 13 | |
|
13 | 14 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { |
|
14 | void addEventItem(const QStringList &data, QTableWidget *tableWidget); | |
|
15 | 15 | |
|
16 | enum class Column { Event, TStart, TEnd, Tags, Product, NbColumn }; | |
|
17 | QStringList columnNames() { return QStringList{"Event", "TStart", "TEnd", "Tags", "Product"}; } | |
|
18 | ||
|
19 | QVector<DBEvent> m_Events; | |
|
16 | CatalogueEventsTableModel *m_Model = nullptr; | |
|
20 | 17 | }; |
|
21 | 18 | |
|
22 | 19 | |
@@ -27,6 +24,11 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |||
|
27 | 24 | { |
|
28 | 25 | ui->setupUi(this); |
|
29 | 26 | |
|
27 | impl->m_Model = new CatalogueEventsTableModel(this); | |
|
28 | ui->tableView->setModel(impl->m_Model); | |
|
29 | ||
|
30 | ui->tableView->setSortingEnabled(true); | |
|
31 | ||
|
30 | 32 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { |
|
31 | 33 | if (checked) { |
|
32 | 34 | ui->btnChart->setChecked(false); |
@@ -39,33 +41,28 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |||
|
39 | 41 | } |
|
40 | 42 | }); |
|
41 | 43 | |
|
42 |
connect(ui->table |
|
|
43 |
auto event = impl->m_ |
|
|
44 | connect(ui->tableView, &QTableView::clicked, [this](auto index) { | |
|
45 | auto event = impl->m_Model->getEvent(index.row()); | |
|
44 | 46 | emit this->eventSelected(event); |
|
45 | 47 | }); |
|
46 | 48 | |
|
47 |
connect(ui->table |
|
|
49 | connect(ui->tableView->selectionModel(), &QItemSelectionModel::currentChanged, | |
|
48 | 50 | [this](auto current, auto previous) { |
|
49 |
if (current && current |
|
|
50 |
auto event = impl->m_Event |
|
|
51 | if (current.isValid() && current.row() >= 0) { | |
|
52 | auto event = impl->m_Model->getEvent(current.row()); | |
|
51 | 53 | emit this->eventSelected(event); |
|
52 | 54 | } |
|
53 | 55 | }); |
|
54 | 56 | |
|
55 |
connect(ui->table |
|
|
56 |
auto selection = ui->table |
|
|
57 | auto isNotMultiSelection | |
|
58 | = selection.isEmpty() || (selection.count() == 1 && selection.first().rowCount() == 1); | |
|
57 | connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { | |
|
58 | auto isNotMultiSelection = ui->tableView->selectionModel()->selectedRows().count() <= 1; | |
|
59 | 59 | ui->btnChart->setEnabled(isNotMultiSelection); |
|
60 | 60 | ui->btnTime->setEnabled(isNotMultiSelection); |
|
61 | 61 | }); |
|
62 | 62 | |
|
63 | Q_ASSERT(impl->columnNames().count() == (int)CatalogueEventsWidgetPrivate::Column::NbColumn); | |
|
64 | ui->tableWidget->setColumnCount((int)CatalogueEventsWidgetPrivate::Column::NbColumn); | |
|
65 |
ui->table |
|
|
66 | ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); | |
|
67 | ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); | |
|
68 | ui->tableWidget->horizontalHeader()->setSortIndicatorShown(true); | |
|
63 | ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); | |
|
64 | ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); | |
|
65 | ui->tableView->horizontalHeader()->setSortIndicatorShown(true); | |
|
69 | 66 | } |
|
70 | 67 | |
|
71 | 68 | CatalogueEventsWidget::~CatalogueEventsWidget() |
@@ -75,41 +72,15 CatalogueEventsWidget::~CatalogueEventsWidget() | |||
|
75 | 72 | |
|
76 | 73 | void CatalogueEventsWidget::populateWithCatalogue(const DBCatalogue &catalogue) |
|
77 | 74 | { |
|
78 | ui->tableWidget->clearContents(); | |
|
79 | ui->tableWidget->setRowCount(0); | |
|
80 | ||
|
81 | 75 | auto &dao = sqpApp->catalogueController().getDao(); |
|
82 | 76 | auto events = dao.getCatalogueEvents(catalogue); |
|
83 | 77 | |
|
78 | QVector<DBEvent> eventVector; | |
|
84 | 79 | for (auto event : events) { |
|
85 |
|
|
|
86 | ||
|
87 | auto tags = event.getTags(); | |
|
88 | QString tagList; | |
|
89 | for (auto tag : tags) { | |
|
90 | tagList += tag.getName(); | |
|
91 | tagList += ' '; | |
|
92 | } | |
|
93 | ||
|
94 | impl->addEventItem({event.getName(), | |
|
95 | DateUtils::dateTime(event.getTStart()).toString(DATETIME_FORMAT), | |
|
96 | DateUtils::dateTime(event.getTEnd()).toString(DATETIME_FORMAT), tagList, | |
|
97 | event.getProduct()}, | |
|
98 | ui->tableWidget); | |
|
80 | eventVector << event; | |
|
99 | 81 | } |
|
100 | } | |
|
101 | 82 | |
|
102 | void CatalogueEventsWidget::CatalogueEventsWidgetPrivate::addEventItem(const QStringList &data, | |
|
103 | QTableWidget *tableWidget) | |
|
104 | { | |
|
105 | tableWidget->setSortingEnabled(false); | |
|
106 | auto row = tableWidget->rowCount(); | |
|
107 | tableWidget->setRowCount(row + 1); | |
|
108 | ||
|
109 | for (auto i = 0; i < (int)Column::NbColumn; ++i) { | |
|
110 | auto item = new QTableWidgetItem(data.value(i)); | |
|
111 | item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); | |
|
112 | tableWidget->setItem(row, i, item); | |
|
113 | } | |
|
114 | tableWidget->setSortingEnabled(true); | |
|
83 | ui->tableView->setSortingEnabled(false); | |
|
84 | impl->m_Model->setEvents(eventVector); | |
|
85 | ui->tableView->setSortingEnabled(true); | |
|
115 | 86 | } |
@@ -34,7 +34,7 | |||
|
34 | 34 | <string>+</string> |
|
35 | 35 | </property> |
|
36 | 36 | <property name="icon"> |
|
37 | <iconset> | |
|
37 | <iconset resource="../../resources/sqpguiresources.qrc"> | |
|
38 | 38 | <normaloff>:/icones/add.png</normaloff>:/icones/add.png</iconset> |
|
39 | 39 | </property> |
|
40 | 40 | <property name="autoRaise"> |
@@ -48,7 +48,7 | |||
|
48 | 48 | <string> - </string> |
|
49 | 49 | </property> |
|
50 | 50 | <property name="icon"> |
|
51 | <iconset> | |
|
51 | <iconset resource="../../resources/sqpguiresources.qrc"> | |
|
52 | 52 | <normaloff>:/icones/remove.png</normaloff>:/icones/remove.png</iconset> |
|
53 | 53 | </property> |
|
54 | 54 | <property name="autoRaise"> |
@@ -69,7 +69,7 | |||
|
69 | 69 | <string>T</string> |
|
70 | 70 | </property> |
|
71 | 71 | <property name="icon"> |
|
72 | <iconset> | |
|
72 | <iconset resource="../../resources/sqpguiresources.qrc"> | |
|
73 | 73 | <normaloff>:/icones/time.png</normaloff>:/icones/time.png</iconset> |
|
74 | 74 | </property> |
|
75 | 75 | <property name="checkable"> |
@@ -86,7 +86,7 | |||
|
86 | 86 | <string>G</string> |
|
87 | 87 | </property> |
|
88 | 88 | <property name="icon"> |
|
89 | <iconset> | |
|
89 | <iconset resource="../../resources/sqpguiresources.qrc"> | |
|
90 | 90 | <normaloff>:/icones/chart.png</normaloff>:/icones/chart.png</iconset> |
|
91 | 91 | </property> |
|
92 | 92 | <property name="checkable"> |
@@ -114,26 +114,35 | |||
|
114 | 114 | </layout> |
|
115 | 115 | </item> |
|
116 | 116 | <item> |
|
117 |
<widget class="QTable |
|
|
118 | <property name="alternatingRowColors"> | |
|
119 | <bool>true</bool> | |
|
120 | </property> | |
|
117 | <widget class="QTableView" name="tableView"> | |
|
121 | 118 | <property name="selectionBehavior"> |
|
122 | 119 | <enum>QAbstractItemView::SelectRows</enum> |
|
123 | 120 | </property> |
|
121 | <attribute name="horizontalHeaderVisible"> | |
|
122 | <bool>true</bool> | |
|
123 | </attribute> | |
|
124 | 124 | <attribute name="horizontalHeaderHighlightSections"> |
|
125 | 125 | <bool>false</bool> |
|
126 | 126 | </attribute> |
|
127 | <attribute name="horizontalHeaderShowSortIndicator" stdset="0"> | |
|
128 | <bool>true</bool> | |
|
129 | </attribute> | |
|
127 | 130 | <attribute name="verticalHeaderVisible"> |
|
128 | 131 | <bool>false</bool> |
|
129 | 132 | </attribute> |
|
130 | 133 | <attribute name="verticalHeaderDefaultSectionSize"> |
|
131 | 134 | <number>25</number> |
|
132 | 135 | </attribute> |
|
136 | <attribute name="verticalHeaderHighlightSections"> | |
|
137 | <bool>false</bool> | |
|
138 | </attribute> | |
|
133 | 139 | </widget> |
|
134 | 140 | </item> |
|
135 | 141 | </layout> |
|
136 | 142 | </widget> |
|
137 |
<resources |
|
|
143 | <resources> | |
|
144 | <include location="../../resources/sqpguiresources.qrc"/> | |
|
145 | <include location="../../resources/sqpguiresources.qrc"/> | |
|
146 | </resources> | |
|
138 | 147 | <connections/> |
|
139 | 148 | </ui> |
General Comments 3
Status change > Approved
You need to be logged in to leave comments.
Login now