@@ -0,0 +1,17 | |||
|
1 | #ifndef SCIQLOP_CATALOGUEACTIONMANAGER_H | |
|
2 | #define SCIQLOP_CATALOGUEACTIONMANAGER_H | |
|
3 | ||
|
4 | #include <Common/spimpl.h> | |
|
5 | ||
|
6 | class CatalogueActionManager { | |
|
7 | public: | |
|
8 | CatalogueActionManager(); | |
|
9 | ||
|
10 | void installSelectionZoneActions(); | |
|
11 | ||
|
12 | private: | |
|
13 | class CatalogueActionManagerPrivate; | |
|
14 | spimpl::unique_impl_ptr<CatalogueActionManagerPrivate> impl; | |
|
15 | }; | |
|
16 | ||
|
17 | #endif // SCIQLOP_CATALOGUEACTIONMANAGER_H |
@@ -0,0 +1,13 | |||
|
1 | #ifndef SCIQLOP_CATALOGUEEXPLORERHELPER_H | |
|
2 | #define SCIQLOP_CATALOGUEEXPLORERHELPER_H | |
|
3 | ||
|
4 | #include <QWidget> | |
|
5 | ||
|
6 | #include <functional> | |
|
7 | ||
|
8 | struct CatalogueExplorerHelper { | |
|
9 | static QWidget *buildValidationWidget(QWidget *parent, std::function<void()> save, | |
|
10 | std::function<void()> discard); | |
|
11 | }; | |
|
12 | ||
|
13 | #endif // SCIQLOP_CATALOGUEEXPLORERHELPER_H |
@@ -0,0 +1,35 | |||
|
1 | #ifndef SCIQLOP_CREATEEVENTDIALOG_H | |
|
2 | #define SCIQLOP_CREATEEVENTDIALOG_H | |
|
3 | ||
|
4 | #include <Common/spimpl.h> | |
|
5 | #include <QDialog> | |
|
6 | #include <memory> | |
|
7 | ||
|
8 | namespace Ui { | |
|
9 | class CreateEventDialog; | |
|
10 | } | |
|
11 | ||
|
12 | class DBCatalogue; | |
|
13 | ||
|
14 | class CreateEventDialog : public QDialog { | |
|
15 | Q_OBJECT | |
|
16 | ||
|
17 | public: | |
|
18 | explicit CreateEventDialog(QWidget *parent = 0); | |
|
19 | virtual ~CreateEventDialog(); | |
|
20 | ||
|
21 | void hideCatalogueChoice(); | |
|
22 | ||
|
23 | QString eventName() const; | |
|
24 | ||
|
25 | std::shared_ptr<DBCatalogue> selectedCatalogue() const; | |
|
26 | QString catalogueName() const; | |
|
27 | ||
|
28 | private: | |
|
29 | Ui::CreateEventDialog *ui; | |
|
30 | ||
|
31 | class CreateEventDialogPrivate; | |
|
32 | spimpl::unique_impl_ptr<CreateEventDialogPrivate> impl; | |
|
33 | }; | |
|
34 | ||
|
35 | #endif // SCIQLOP_CREATEEVENTDIALOG_H |
@@ -0,0 +1,107 | |||
|
1 | #include "Catalogue/CatalogueActionManager.h" | |
|
2 | ||
|
3 | #include <Actions/ActionsGuiController.h> | |
|
4 | #include <Catalogue/CatalogueController.h> | |
|
5 | #include <SqpApplication.h> | |
|
6 | #include <Variable/Variable.h> | |
|
7 | #include <Visualization/VisualizationGraphWidget.h> | |
|
8 | #include <Visualization/VisualizationSelectionZoneItem.h> | |
|
9 | ||
|
10 | #include <Catalogue/CreateEventDialog.h> | |
|
11 | ||
|
12 | #include <DBCatalogue.h> | |
|
13 | #include <DBEvent.h> | |
|
14 | #include <DBEventProduct.h> | |
|
15 | ||
|
16 | #include <QBoxLayout> | |
|
17 | #include <QComboBox> | |
|
18 | #include <QDialog> | |
|
19 | #include <QDialogButtonBox> | |
|
20 | #include <QLineEdit> | |
|
21 | #include <memory> | |
|
22 | ||
|
23 | struct CatalogueActionManager::CatalogueActionManagerPrivate { | |
|
24 | void createEventFromZones(const QString &eventName, | |
|
25 | const QVector<VisualizationSelectionZoneItem *> &zones, | |
|
26 | const std::shared_ptr<DBCatalogue> &catalogue = nullptr) | |
|
27 | { | |
|
28 | auto event = std::make_shared<DBEvent>(); | |
|
29 | event->setName(eventName); | |
|
30 | ||
|
31 | std::list<DBEventProduct> productList; | |
|
32 | for (auto zone : zones) { | |
|
33 | auto graph = zone->parentGraphWidget(); | |
|
34 | for (auto var : graph->variables()) { | |
|
35 | auto eventProduct = std::make_shared<DBEventProduct>(); | |
|
36 | eventProduct->setEvent(*event); | |
|
37 | ||
|
38 | auto zoneRange = zone->range(); | |
|
39 | eventProduct->setTStart(zoneRange.m_TStart); | |
|
40 | eventProduct->setTEnd(zoneRange.m_TEnd); | |
|
41 | ||
|
42 | eventProduct->setProductId(var->metadata().value("id", "TODO").toString()); // todo | |
|
43 | ||
|
44 | productList.push_back(*eventProduct); | |
|
45 | } | |
|
46 | } | |
|
47 | ||
|
48 | event->setEventProducts(productList); | |
|
49 | ||
|
50 | sqpApp->catalogueController().addEvent(event); | |
|
51 | ||
|
52 | if (catalogue) { | |
|
53 | // TODO | |
|
54 | // catalogue->addEvent(event); | |
|
55 | } | |
|
56 | } | |
|
57 | }; | |
|
58 | ||
|
59 | CatalogueActionManager::CatalogueActionManager() | |
|
60 | : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>()} | |
|
61 | { | |
|
62 | } | |
|
63 | ||
|
64 | void CatalogueActionManager::installSelectionZoneActions() | |
|
65 | { | |
|
66 | auto &actionController = sqpApp->actionsGuiController(); | |
|
67 | ||
|
68 | auto createEventEnableFuntion = [](auto zones) { | |
|
69 | QSet<VisualizationGraphWidget *> usedGraphs; | |
|
70 | for (auto zone : zones) { | |
|
71 | auto graph = zone->parentGraphWidget(); | |
|
72 | if (!usedGraphs.contains(graph)) { | |
|
73 | usedGraphs.insert(graph); | |
|
74 | } | |
|
75 | else { | |
|
76 | return false; | |
|
77 | } | |
|
78 | } | |
|
79 | ||
|
80 | return true; | |
|
81 | }; | |
|
82 | ||
|
83 | auto createEventAction = actionController.addSectionZoneAction( | |
|
84 | {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) { | |
|
85 | CreateEventDialog dialog; | |
|
86 | dialog.hideCatalogueChoice(); | |
|
87 | if (dialog.exec() == QDialog::Accepted) { | |
|
88 | impl->createEventFromZones(dialog.eventName(), zones); | |
|
89 | } | |
|
90 | }); | |
|
91 | createEventAction->setEnableFunction(createEventEnableFuntion); | |
|
92 | ||
|
93 | auto createEventInCatalogueAction = actionController.addSectionZoneAction( | |
|
94 | {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) { | |
|
95 | CreateEventDialog dialog; | |
|
96 | if (dialog.exec() == QDialog::Accepted) { | |
|
97 | auto selectedCatalogue = dialog.selectedCatalogue(); | |
|
98 | if (!selectedCatalogue) { | |
|
99 | selectedCatalogue = std::make_shared<DBCatalogue>(); | |
|
100 | selectedCatalogue->setName(dialog.catalogueName()); | |
|
101 | } | |
|
102 | ||
|
103 | impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue); | |
|
104 | } | |
|
105 | }); | |
|
106 | createEventInCatalogueAction->setEnableFunction(createEventEnableFuntion); | |
|
107 | } |
@@ -0,0 +1,32 | |||
|
1 | #include "Catalogue/CatalogueExplorerHelper.h" | |
|
2 | ||
|
3 | #include <QBoxLayout> | |
|
4 | #include <QToolButton> | |
|
5 | ||
|
6 | const auto VALIDATION_BUTTON_ICON_SIZE = 12; | |
|
7 | ||
|
8 | QWidget *CatalogueExplorerHelper::buildValidationWidget(QWidget *parent, std::function<void()> save, | |
|
9 | std::function<void()> discard) | |
|
10 | { | |
|
11 | auto widget = new QWidget{parent}; | |
|
12 | ||
|
13 | auto layout = new QHBoxLayout{widget}; | |
|
14 | layout->setContentsMargins(0, 0, 0, 0); | |
|
15 | layout->setSpacing(0); | |
|
16 | ||
|
17 | auto btnValid = new QToolButton{widget}; | |
|
18 | btnValid->setIcon(QIcon{":/icones/save"}); | |
|
19 | btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE}); | |
|
20 | btnValid->setAutoRaise(true); | |
|
21 | QObject::connect(btnValid, &QToolButton::clicked, save); | |
|
22 | layout->addWidget(btnValid); | |
|
23 | ||
|
24 | auto btnDiscard = new QToolButton{widget}; | |
|
25 | btnDiscard->setIcon(QIcon{":/icones/discard"}); | |
|
26 | btnDiscard->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE}); | |
|
27 | btnDiscard->setAutoRaise(true); | |
|
28 | QObject::connect(btnDiscard, &QToolButton::clicked, discard); | |
|
29 | layout->addWidget(btnDiscard); | |
|
30 | ||
|
31 | return widget; | |
|
32 | } |
@@ -0,0 +1,59 | |||
|
1 | #include "Catalogue/CreateEventDialog.h" | |
|
2 | #include "ui_CreateEventDialog.h" | |
|
3 | ||
|
4 | #include <Catalogue/CatalogueController.h> | |
|
5 | #include <SqpApplication.h> | |
|
6 | ||
|
7 | #include <DBCatalogue.h> | |
|
8 | ||
|
9 | struct CreateEventDialog::CreateEventDialogPrivate { | |
|
10 | QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues; | |
|
11 | }; | |
|
12 | ||
|
13 | CreateEventDialog::CreateEventDialog(QWidget *parent) | |
|
14 | : QDialog(parent), | |
|
15 | ui(new Ui::CreateEventDialog), | |
|
16 | impl{spimpl::make_unique_impl<CreateEventDialogPrivate>()} | |
|
17 | { | |
|
18 | ui->setupUi(this); | |
|
19 | ||
|
20 | connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); | |
|
21 | connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); | |
|
22 | ||
|
23 | auto catalogues = sqpApp->catalogueController().retrieveCatalogues(); | |
|
24 | for (auto cat : catalogues) { | |
|
25 | ui->cbCatalogue->addItem(cat->getName()); | |
|
26 | impl->m_DisplayedCatalogues << cat; | |
|
27 | } | |
|
28 | } | |
|
29 | ||
|
30 | CreateEventDialog::~CreateEventDialog() | |
|
31 | { | |
|
32 | delete ui; | |
|
33 | } | |
|
34 | ||
|
35 | void CreateEventDialog::hideCatalogueChoice() | |
|
36 | { | |
|
37 | ui->cbCatalogue->hide(); | |
|
38 | ui->lblCatalogue->hide(); | |
|
39 | } | |
|
40 | ||
|
41 | QString CreateEventDialog::eventName() const | |
|
42 | { | |
|
43 | return ui->leEvent->text(); | |
|
44 | } | |
|
45 | ||
|
46 | std::shared_ptr<DBCatalogue> CreateEventDialog::selectedCatalogue() const | |
|
47 | { | |
|
48 | auto catalogue = impl->m_DisplayedCatalogues.value(ui->cbCatalogue->currentIndex()); | |
|
49 | if (!catalogue || catalogue->getName() != catalogueName()) { | |
|
50 | return nullptr; | |
|
51 | } | |
|
52 | ||
|
53 | return catalogue; | |
|
54 | } | |
|
55 | ||
|
56 | QString CreateEventDialog::catalogueName() const | |
|
57 | { | |
|
58 | return ui->cbCatalogue->currentText(); | |
|
59 | } |
@@ -0,0 +1,55 | |||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
|
2 | <ui version="4.0"> | |
|
3 | <class>CreateEventDialog</class> | |
|
4 | <widget class="QDialog" name="CreateEventDialog"> | |
|
5 | <property name="geometry"> | |
|
6 | <rect> | |
|
7 | <x>0</x> | |
|
8 | <y>0</y> | |
|
9 | <width>324</width> | |
|
10 | <height>93</height> | |
|
11 | </rect> | |
|
12 | </property> | |
|
13 | <property name="windowTitle"> | |
|
14 | <string>New Event</string> | |
|
15 | </property> | |
|
16 | <layout class="QGridLayout" name="gridLayout"> | |
|
17 | <item row="0" column="0"> | |
|
18 | <widget class="QLabel" name="label"> | |
|
19 | <property name="text"> | |
|
20 | <string>Event Name</string> | |
|
21 | </property> | |
|
22 | </widget> | |
|
23 | </item> | |
|
24 | <item row="0" column="1"> | |
|
25 | <widget class="QLineEdit" name="leEvent"/> | |
|
26 | </item> | |
|
27 | <item row="1" column="0"> | |
|
28 | <widget class="QLabel" name="lblCatalogue"> | |
|
29 | <property name="text"> | |
|
30 | <string>Catalogue</string> | |
|
31 | </property> | |
|
32 | </widget> | |
|
33 | </item> | |
|
34 | <item row="1" column="1"> | |
|
35 | <widget class="QComboBox" name="cbCatalogue"> | |
|
36 | <property name="editable"> | |
|
37 | <bool>true</bool> | |
|
38 | </property> | |
|
39 | <property name="insertPolicy"> | |
|
40 | <enum>QComboBox::NoInsert</enum> | |
|
41 | </property> | |
|
42 | </widget> | |
|
43 | </item> | |
|
44 | <item row="2" column="0" colspan="2"> | |
|
45 | <widget class="QDialogButtonBox" name="buttonBox"> | |
|
46 | <property name="standardButtons"> | |
|
47 | <set>QDialogButtonBox::Ok</set> | |
|
48 | </property> | |
|
49 | </widget> | |
|
50 | </item> | |
|
51 | </layout> | |
|
52 | </widget> | |
|
53 | <resources/> | |
|
54 | <connections/> | |
|
55 | </ui> |
@@ -25,9 +25,9 | |||
|
25 | 25 | #include <SqpApplication.h> |
|
26 | 26 | #include <qglobal.h> |
|
27 | 27 | |
|
28 | #include <QtPlugin> | |
|
29 | 28 | #include <Plugin/PluginManager.h> |
|
30 | 29 | #include <QDir> |
|
30 | #include <QtPlugin> | |
|
31 | 31 | |
|
32 | 32 | #include <QLoggingCategory> |
|
33 | 33 |
@@ -32,27 +32,33 public: | |||
|
32 | 32 | virtual ~CatalogueController(); |
|
33 | 33 | |
|
34 | 34 | // DB |
|
35 |
|
|
|
35 | QStringList getRepositories() const; | |
|
36 | 36 | void addDB(const QString &dbPath); |
|
37 | 37 | void saveDB(const QString &destinationPath, const QString &repository); |
|
38 | 38 | |
|
39 | 39 | // Event |
|
40 | // bool createEvent(const QString &name); | |
|
40 | /// retrieveEvents with empty repository retrieve them from the default repository | |
|
41 | 41 | std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const; |
|
42 | 42 | std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const; |
|
43 | 43 | std::list<std::shared_ptr<DBEvent> > |
|
44 | 44 | retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const; |
|
45 |
|
|
|
45 | void addEvent(std::shared_ptr<DBEvent> event); | |
|
46 | void updateEvent(std::shared_ptr<DBEvent> event); | |
|
47 | void removeEvent(std::shared_ptr<DBEvent> event); | |
|
46 | 48 | // void trashEvent(std::shared_ptr<DBEvent> event); |
|
47 | // void removeEvent(std::shared_ptr<DBEvent> event); | |
|
48 | 49 | // void restore(QUuid eventId); |
|
49 |
|
|
|
50 | void saveEvent(std::shared_ptr<DBEvent> event); | |
|
50 | 51 | |
|
51 | 52 | // Catalogue |
|
52 | 53 | // bool createCatalogue(const QString &name, QVector<QUuid> eventList); |
|
53 | std::list<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const; | |
|
54 | // void removeEvent(QUuid catalogueId, const QString &repository); | |
|
55 | // void saveCatalogue(std::shared_ptr<DBEvent> event); | |
|
54 | /// retrieveEvents with empty repository retrieve them from the default repository | |
|
55 | std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository | |
|
56 | = QString()) const; | |
|
57 | void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue); | |
|
58 | void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue); | |
|
59 | void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue); | |
|
60 | ||
|
61 | void saveAll(); | |
|
56 | 62 | |
|
57 | 63 | public slots: |
|
58 | 64 | /// Manage init/end of the controller |
@@ -8,6 +8,7 | |||
|
8 | 8 | #include <CompoundPredicate.h> |
|
9 | 9 | #include <DBCatalogue.h> |
|
10 | 10 | #include <DBEvent.h> |
|
11 | #include <DBEventProduct.h> | |
|
11 | 12 | #include <DBTag.h> |
|
12 | 13 | #include <IRequestPredicate.h> |
|
13 | 14 | |
@@ -21,20 +22,28 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController") | |||
|
21 | 22 | |
|
22 | 23 | namespace { |
|
23 | 24 | |
|
24 |
static QString REPOSITORY_WORK_SUFFIX = QString{" |
|
|
25 | ||
|
25 | static QString REPOSITORY_WORK_SUFFIX = QString{"work"}; | |
|
26 | static QString REPOSITORY_TRASH_SUFFIX = QString{"trash"}; | |
|
26 | 27 | } |
|
27 | 28 | |
|
28 | 29 | class CatalogueController::CatalogueControllerPrivate { |
|
30 | ||
|
29 | 31 | public: |
|
32 | explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {} | |
|
33 | ||
|
30 | 34 | QMutex m_WorkingMutex; |
|
31 | 35 | CatalogueDao m_CatalogueDao; |
|
32 | 36 | |
|
33 |
|
|
|
37 | QStringList m_RepositoryList; | |
|
38 | CatalogueController *m_Q; | |
|
39 | ||
|
40 | void copyDBtoDB(const QString &dbFrom, const QString &dbTo); | |
|
41 | QString toWorkRepository(QString repository); | |
|
42 | QString toSyncRepository(QString repository); | |
|
34 | 43 | }; |
|
35 | 44 | |
|
36 | 45 | CatalogueController::CatalogueController(QObject *parent) |
|
37 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>()} | |
|
46 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)} | |
|
38 | 47 | { |
|
39 | 48 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") |
|
40 | 49 | << QThread::currentThread(); |
@@ -47,6 +56,11 CatalogueController::~CatalogueController() | |||
|
47 | 56 | this->waitForFinish(); |
|
48 | 57 | } |
|
49 | 58 | |
|
59 | QStringList CatalogueController::getRepositories() const | |
|
60 | { | |
|
61 | return impl->m_RepositoryList; | |
|
62 | } | |
|
63 | ||
|
50 | 64 | void CatalogueController::addDB(const QString &dbPath) |
|
51 | 65 | { |
|
52 | 66 | QDir dbDir(dbPath); |
@@ -64,7 +78,8 void CatalogueController::addDB(const QString &dbPath) | |||
|
64 | 78 | << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); |
|
65 | 79 | } |
|
66 | 80 | else { |
|
67 |
impl->m_RepositoryList |
|
|
81 | impl->m_RepositoryList << dirName; | |
|
82 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); | |
|
68 | 83 | } |
|
69 | 84 | } |
|
70 | 85 | else { |
@@ -84,8 +99,10 void CatalogueController::saveDB(const QString &destinationPath, const QString & | |||
|
84 | 99 | std::list<std::shared_ptr<DBEvent> > |
|
85 | 100 | CatalogueController::retrieveEvents(const QString &repository) const |
|
86 | 101 | { |
|
102 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; | |
|
103 | ||
|
87 | 104 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
88 | auto events = impl->m_CatalogueDao.getEvents(repository); | |
|
105 | auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); | |
|
89 | 106 | for (auto event : events) { |
|
90 | 107 | eventsShared.push_back(std::make_shared<DBEvent>(event)); |
|
91 | 108 | } |
@@ -113,17 +130,92 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> ca | |||
|
113 | 130 | return eventsShared; |
|
114 | 131 | } |
|
115 | 132 | |
|
133 | void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event) | |
|
134 | { | |
|
135 | event->setRepository(impl->toSyncRepository(event->getRepository())); | |
|
136 | ||
|
137 | impl->m_CatalogueDao.updateEvent(*event); | |
|
138 | } | |
|
139 | ||
|
140 | void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event) | |
|
141 | { | |
|
142 | // Remove it from both repository and repository_work | |
|
143 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |
|
144 | impl->m_CatalogueDao.removeEvent(*event); | |
|
145 | event->setRepository(impl->toSyncRepository(event->getRepository())); | |
|
146 | impl->m_CatalogueDao.removeEvent(*event); | |
|
147 | } | |
|
148 | ||
|
149 | void CatalogueController::addEvent(std::shared_ptr<DBEvent> event) | |
|
150 | { | |
|
151 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |
|
152 | ||
|
153 | impl->m_CatalogueDao.addEvent(*event); | |
|
154 | ||
|
155 | // Call update is necessary at the creation of add Event if it has some tags or some event | |
|
156 | // products | |
|
157 | if (!event->getEventProducts().empty() || !event->getTags().empty()) { | |
|
158 | impl->m_CatalogueDao.updateEvent(*event); | |
|
159 | } | |
|
160 | } | |
|
161 | ||
|
162 | void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event) | |
|
163 | { | |
|
164 | impl->m_CatalogueDao.moveEvent(*event, impl->toSyncRepository(event->getRepository()), true); | |
|
165 | } | |
|
166 | ||
|
116 | 167 | std::list<std::shared_ptr<DBCatalogue> > |
|
117 |
CatalogueController:: |
|
|
168 | CatalogueController::retrieveCatalogues(const QString &repository) const | |
|
118 | 169 | { |
|
170 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; | |
|
171 | ||
|
119 | 172 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; |
|
120 | auto catalogues = impl->m_CatalogueDao.getCatalogues(repository); | |
|
173 | auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); | |
|
121 | 174 | for (auto catalogue : catalogues) { |
|
122 | 175 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); |
|
123 | 176 | } |
|
124 | 177 | return cataloguesShared; |
|
125 | 178 | } |
|
126 | 179 | |
|
180 | void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
|
181 | { | |
|
182 | catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); | |
|
183 | ||
|
184 | impl->m_CatalogueDao.updateCatalogue(*catalogue); | |
|
185 | } | |
|
186 | ||
|
187 | void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
|
188 | { | |
|
189 | // Remove it from both repository and repository_work | |
|
190 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); | |
|
191 | impl->m_CatalogueDao.removeCatalogue(*catalogue); | |
|
192 | catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); | |
|
193 | impl->m_CatalogueDao.removeCatalogue(*catalogue); | |
|
194 | } | |
|
195 | ||
|
196 | void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
|
197 | { | |
|
198 | impl->m_CatalogueDao.moveCatalogue(*catalogue, | |
|
199 | impl->toSyncRepository(catalogue->getRepository()), true); | |
|
200 | } | |
|
201 | ||
|
202 | void CatalogueController::saveAll() | |
|
203 | { | |
|
204 | for (auto repository : impl->m_RepositoryList) { | |
|
205 | // Save Event | |
|
206 | auto events = this->retrieveEvents(repository); | |
|
207 | for (auto event : events) { | |
|
208 | this->saveEvent(event); | |
|
209 | } | |
|
210 | ||
|
211 | // Save Catalogue | |
|
212 | auto catalogues = this->retrieveCatalogues(repository); | |
|
213 | for (auto catalogue : catalogues) { | |
|
214 | this->saveCatalogue(catalogue); | |
|
215 | } | |
|
216 | } | |
|
217 | } | |
|
218 | ||
|
127 | 219 | void CatalogueController::initialize() |
|
128 | 220 | { |
|
129 | 221 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") |
@@ -137,8 +229,8 void CatalogueController::initialize() | |||
|
137 | 229 | if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { |
|
138 | 230 | defaultRepositoryLocationDir.cd(defaultRepositoryLocation); |
|
139 | 231 | auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); |
|
140 | qCInfo(LOG_CatalogueController()) | |
|
141 | << tr("Persistant data loading from: ") << defaultRepository; | |
|
232 | qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") | |
|
233 | << defaultRepository; | |
|
142 | 234 | this->addDB(defaultRepository); |
|
143 | 235 | } |
|
144 | 236 | else { |
@@ -159,3 +251,46 void CatalogueController::waitForFinish() | |||
|
159 | 251 | { |
|
160 | 252 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
161 | 253 | } |
|
254 | ||
|
255 | void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom, | |
|
256 | const QString &dbTo) | |
|
257 | { | |
|
258 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; | |
|
259 | auto catalogues = m_CatalogueDao.getCatalogues(dbFrom); | |
|
260 | for (auto catalogue : catalogues) { | |
|
261 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); | |
|
262 | } | |
|
263 | ||
|
264 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
|
265 | auto events = m_CatalogueDao.getEvents(dbFrom); | |
|
266 | for (auto event : events) { | |
|
267 | eventsShared.push_back(std::make_shared<DBEvent>(event)); | |
|
268 | } | |
|
269 | ||
|
270 | for (auto catalogue : cataloguesShared) { | |
|
271 | m_CatalogueDao.copyCatalogue(*catalogue, dbTo, true); | |
|
272 | } | |
|
273 | ||
|
274 | for (auto event : eventsShared) { | |
|
275 | m_CatalogueDao.copyEvent(*event, dbTo, true); | |
|
276 | } | |
|
277 | } | |
|
278 | ||
|
279 | QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository) | |
|
280 | { | |
|
281 | auto syncRepository = toSyncRepository(repository); | |
|
282 | ||
|
283 | return QString("%1_%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX); | |
|
284 | } | |
|
285 | ||
|
286 | QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository) | |
|
287 | { | |
|
288 | auto syncRepository = repository; | |
|
289 | if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) { | |
|
290 | syncRepository.remove(REPOSITORY_WORK_SUFFIX); | |
|
291 | } | |
|
292 | else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) { | |
|
293 | syncRepository.remove(REPOSITORY_TRASH_SUFFIX); | |
|
294 | } | |
|
295 | return syncRepository; | |
|
296 | } |
@@ -97,8 +97,7 struct PluginManager::PluginManagerPrivate { | |||
|
97 | 97 | |
|
98 | 98 | void loadStaticPlugins() |
|
99 | 99 | { |
|
100 | for (QObject *plugin : QPluginLoader::staticInstances()) | |
|
101 | { | |
|
100 | for (QObject *plugin : QPluginLoader::staticInstances()) { | |
|
102 | 101 | qobject_cast<IPlugin *>(plugin)->initialize(); |
|
103 | 102 | m_RegisteredPlugins.insert(plugin->metaObject()->className(), "StaticPlugin"); |
|
104 | 103 | } |
@@ -176,8 +176,8 void TestDataSeriesUtils::testThresholds_data() | |||
|
176 | 176 | << false << 1. << 47.073; |
|
177 | 177 | |
|
178 | 178 | QTest::newRow("thresholds (empty data)") << std::vector<double>{} << false << nan << nan; |
|
179 | QTest::newRow("thresholds (only nan values)") | |
|
180 | << std::vector<double>{nan, nan, nan, nan, nan} << false << nan << nan; | |
|
179 | QTest::newRow("thresholds (only nan values)") << std::vector<double>{nan, nan, nan, nan, nan} | |
|
180 | << false << nan << nan; | |
|
181 | 181 | |
|
182 | 182 | QTest::newRow("thresholds (from file with logarithmic scale)") |
|
183 | 183 | << fromFile(inputFilePath("TestThresholds.txt")) << true << 832.005 << 17655064.730; |
@@ -3,17 +3,29 | |||
|
3 | 3 | |
|
4 | 4 | #include <Common/spimpl.h> |
|
5 | 5 | #include <QAbstractItemModel> |
|
6 | #include <QLoggingCategory> | |
|
7 | #include <unordered_set> | |
|
6 | 8 | |
|
7 | 9 | class DBEvent; |
|
8 | 10 | class DBEventProduct; |
|
9 | 11 | |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsModel) | |
|
13 | ||
|
10 | 14 | class CatalogueEventsModel : public QAbstractItemModel { |
|
15 | Q_OBJECT | |
|
16 | ||
|
17 | signals: | |
|
18 | void modelSorted(); | |
|
19 | ||
|
11 | 20 | public: |
|
12 | 21 | CatalogueEventsModel(QObject *parent = nullptr); |
|
13 | 22 | |
|
23 | enum class Column { Name, TStart, TEnd, Tags, Product, Validation, NbColumn }; | |
|
24 | ||
|
14 | 25 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events); |
|
15 | 26 | void addEvent(const std::shared_ptr<DBEvent> &event); |
|
16 | 27 | void removeEvent(const std::shared_ptr<DBEvent> &event); |
|
28 | QVector<std::shared_ptr<DBEvent> > events() const; | |
|
17 | 29 | |
|
18 | 30 | enum class ItemType { Root, Event, EventProduct }; |
|
19 | 31 | ItemType itemTypeOf(const QModelIndex &index) const; |
@@ -21,8 +33,18 public: | |||
|
21 | 33 | std::shared_ptr<DBEvent> getParentEvent(const QModelIndex &index) const; |
|
22 | 34 | std::shared_ptr<DBEventProduct> getEventProduct(const QModelIndex &index) const; |
|
23 | 35 | |
|
36 | /// Refresh the data for the specified event | |
|
24 | 37 | void refreshEvent(const std::shared_ptr<DBEvent> &event); |
|
25 | 38 | |
|
39 | /// Returns a QModelIndex which represent the specified event | |
|
40 | QModelIndex indexOf(const std::shared_ptr<DBEvent> &event) const; | |
|
41 | ||
|
42 | /// Marks a change flag on the specified event to allow sorting on the validation column | |
|
43 | void setEventHasChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges); | |
|
44 | ||
|
45 | /// Returns true if the specified event has unsaved changes | |
|
46 | bool eventsHasChanges(const std::shared_ptr<DBEvent> &event) const; | |
|
47 | ||
|
26 | 48 | // Model |
|
27 | 49 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; |
|
28 | 50 | QModelIndex parent(const QModelIndex &index) const; |
@@ -36,6 +36,7 public: | |||
|
36 | 36 | |
|
37 | 37 | public slots: |
|
38 | 38 | void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); |
|
39 | void populateWithAllEvents(); | |
|
39 | 40 | |
|
40 | 41 | private: |
|
41 | 42 | Ui::CatalogueEventsWidget *ui; |
@@ -22,6 +22,9 public: | |||
|
22 | 22 | /// changes |
|
23 | 23 | void setHasChanges(bool value); |
|
24 | 24 | |
|
25 | /// Returns true if the widget indicating the event has unsaved changes is displayed | |
|
26 | bool hasChanges(); | |
|
27 | ||
|
25 | 28 | /// Refreshes the data displayed by the item from the catalogue |
|
26 | 29 | void refresh(); |
|
27 | 30 |
@@ -1,4 +1,3 | |||
|
1 | ||
|
2 | 1 | qxorm_dep = dependency('QxOrm', required : true, fallback:['QxOrm','qxorm_dep']) |
|
3 | 2 | catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['CatalogueAPI','CatalogueAPI_dep']) |
|
4 | 3 | |
@@ -26,7 +25,9 gui_moc_headers = [ | |||
|
26 | 25 | 'include/Catalogue/CatalogueExplorer.h', |
|
27 | 26 | 'include/Catalogue/CatalogueEventsWidget.h', |
|
28 | 27 | 'include/Catalogue/CatalogueSideBarWidget.h', |
|
29 | 'include/Catalogue/CatalogueInspectorWidget.h' | |
|
28 | 'include/Catalogue/CatalogueInspectorWidget.h', | |
|
29 | 'include/Catalogue/CatalogueEventsModel.h', | |
|
30 | 'include/Catalogue/CreateEventDialog.h' | |
|
30 | 31 | ] |
|
31 | 32 | |
|
32 | 33 | gui_ui_files = [ |
@@ -47,14 +48,24 gui_ui_files = [ | |||
|
47 | 48 | 'ui/Catalogue/CatalogueExplorer.ui', |
|
48 | 49 | 'ui/Catalogue/CatalogueEventsWidget.ui', |
|
49 | 50 | 'ui/Catalogue/CatalogueSideBarWidget.ui', |
|
50 | 'ui/Catalogue/CatalogueInspectorWidget.ui' | |
|
51 | 'ui/Catalogue/CatalogueInspectorWidget.ui', | |
|
52 | 'ui/Catalogue/CreateEventDialog.ui' | |
|
51 | 53 | ] |
|
52 | 54 | |
|
53 | 55 | gui_qresources = ['resources/sqpguiresources.qrc'] |
|
54 | 56 | |
|
57 | rcc_gen = generator(rcc, | |
|
58 | output : 'qrc_@BASENAME@.cpp', | |
|
59 | arguments : [ | |
|
60 | '--output', | |
|
61 | '@OUTPUT@', | |
|
62 | '@INPUT@', | |
|
63 | '@EXTRA_ARGS@']) | |
|
64 | ||
|
65 | rcc_files = rcc_gen.process(gui_qresources, extra_args : ['-name', 'sqpguiresources']) | |
|
66 | ||
|
55 | 67 | gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers, |
|
56 |
ui_files : gui_ui_files |
|
|
57 | qresources : gui_qresources) | |
|
68 | ui_files : gui_ui_files) | |
|
58 | 69 | |
|
59 | 70 | gui_sources = [ |
|
60 | 71 | 'src/SqpApplication.cpp', |
@@ -108,7 +119,10 gui_sources = [ | |||
|
108 | 119 | 'src/Catalogue/CatalogueSideBarWidget.cpp', |
|
109 | 120 | 'src/Catalogue/CatalogueInspectorWidget.cpp', |
|
110 | 121 | 'src/Catalogue/CatalogueTreeWidgetItem.cpp', |
|
111 | 'src/Catalogue/CatalogueEventsModel.cpp' | |
|
122 | 'src/Catalogue/CatalogueEventsModel.cpp', | |
|
123 | 'src/Catalogue/CatalogueExplorerHelper.cpp', | |
|
124 | 'src/Catalogue/CatalogueActionManager.cpp', | |
|
125 | 'src/Catalogue/CreateEventDialog.cpp' | |
|
112 | 126 | ] |
|
113 | 127 | |
|
114 | 128 | gui_inc = include_directories(['include']) |
@@ -116,6 +130,7 gui_inc = include_directories(['include']) | |||
|
116 | 130 | sciqlop_gui_lib = library('sciqlopgui', |
|
117 | 131 | gui_sources, |
|
118 | 132 | gui_moc_files, |
|
133 | rcc_files, | |
|
119 | 134 | include_directories : [gui_inc], |
|
120 | 135 | dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep], |
|
121 | 136 | install : true |
@@ -125,3 +140,4 sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, | |||
|
125 | 140 | include_directories : gui_inc, |
|
126 | 141 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep]) |
|
127 | 142 | |
|
143 |
@@ -15,38 +15,46 | |||
|
15 | 15 | #include <QHash> |
|
16 | 16 | #include <QMimeData> |
|
17 | 17 | |
|
18 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsModel, "CatalogueEventsModel") | |
|
19 | ||
|
18 | 20 | const auto EVENT_ITEM_TYPE = 1; |
|
19 | 21 | const auto EVENT_PRODUCT_ITEM_TYPE = 2; |
|
20 | 22 | |
|
21 | 23 | struct CatalogueEventsModel::CatalogueEventsModelPrivate { |
|
22 | 24 | QVector<std::shared_ptr<DBEvent> > m_Events; |
|
23 | 25 | std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts; |
|
26 | std::unordered_set<std::shared_ptr<DBEvent> > m_EventsWithChanges; | |
|
24 | 27 | |
|
25 | enum class Column { Name, TStart, TEnd, Tags, Product, NbColumn }; | |
|
26 | 28 | QStringList columnNames() |
|
27 | 29 | { |
|
28 |
return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), |
|
|
30 | return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), | |
|
31 | tr("Tags"), tr("Product"), tr("")}; | |
|
32 | } | |
|
33 | ||
|
34 | QVariant sortData(int col, const std::shared_ptr<DBEvent> &event) const | |
|
35 | { | |
|
36 | if (col == (int)CatalogueEventsModel::Column::Validation) { | |
|
37 | return m_EventsWithChanges.find(event) != m_EventsWithChanges.cend() ? true | |
|
38 | : QVariant(); | |
|
39 | } | |
|
40 | ||
|
41 | return eventData(col, event); | |
|
29 | 42 | } |
|
30 | 43 | |
|
31 | 44 | QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const |
|
32 | 45 | { |
|
33 | 46 | switch (static_cast<Column>(col)) { |
|
34 | case Column::Name: | |
|
47 | case CatalogueEventsModel::Column::Name: | |
|
35 | 48 | return event->getName(); |
|
36 | case Column::TStart: | |
|
37 |
return DateUtils::dateTime(event->getTStart()) |
|
|
38 | case Column::TEnd: | |
|
39 | return DateUtils::dateTime(event->getTEnd()); | |
|
40 | case Column::Product: { | |
|
41 | auto eventProductsIt = m_EventProducts.find(event.get()); | |
|
42 | if (eventProductsIt != m_EventProducts.cend()) { | |
|
43 |
|
|
|
44 | } | |
|
45 | else { | |
|
46 | return "0 product"; | |
|
47 | } | |
|
48 | } | |
|
49 | case Column::Tags: { | |
|
49 | case CatalogueEventsModel::Column::TStart: | |
|
50 | return nbEventProducts(event) > 0 ? DateUtils::dateTime(event->getTStart()) | |
|
51 | : QVariant{}; | |
|
52 | case CatalogueEventsModel::Column::TEnd: | |
|
53 | return nbEventProducts(event) > 0 ? DateUtils::dateTime(event->getTEnd()) | |
|
54 | : QVariant{}; | |
|
55 | case CatalogueEventsModel::Column::Product: | |
|
56 | return QString::number(nbEventProducts(event)) + " product(s)"; | |
|
57 | case CatalogueEventsModel::Column::Tags: { | |
|
50 | 58 | QString tagList; |
|
51 | 59 | auto tags = event->getTags(); |
|
52 | 60 | for (auto tag : tags) { |
@@ -56,6 +64,8 struct CatalogueEventsModel::CatalogueEventsModelPrivate { | |||
|
56 | 64 | |
|
57 | 65 | return tagList; |
|
58 | 66 | } |
|
67 | case CatalogueEventsModel::Column::Validation: | |
|
68 | return QVariant(); | |
|
59 | 69 | default: |
|
60 | 70 | break; |
|
61 | 71 | } |
@@ -71,20 +81,32 struct CatalogueEventsModel::CatalogueEventsModelPrivate { | |||
|
71 | 81 | } |
|
72 | 82 | } |
|
73 | 83 | |
|
84 | int nbEventProducts(const std::shared_ptr<DBEvent> &event) const | |
|
85 | { | |
|
86 | auto eventProductsIt = m_EventProducts.find(event.get()); | |
|
87 | if (eventProductsIt != m_EventProducts.cend()) { | |
|
88 | return m_EventProducts.at(event.get()).count(); | |
|
89 | } | |
|
90 | else { | |
|
91 | return 0; | |
|
92 | } | |
|
93 | } | |
|
94 | ||
|
74 | 95 | QVariant eventProductData(int col, const std::shared_ptr<DBEventProduct> &eventProduct) const |
|
75 | 96 | { |
|
76 | 97 | switch (static_cast<Column>(col)) { |
|
77 | case Column::Name: | |
|
98 | case CatalogueEventsModel::Column::Name: | |
|
78 | 99 | return eventProduct->getProductId(); |
|
79 | case Column::TStart: | |
|
100 | case CatalogueEventsModel::Column::TStart: | |
|
80 | 101 | return DateUtils::dateTime(eventProduct->getTStart()); |
|
81 | case Column::TEnd: | |
|
102 | case CatalogueEventsModel::Column::TEnd: | |
|
82 | 103 | return DateUtils::dateTime(eventProduct->getTEnd()); |
|
83 | case Column::Product: | |
|
104 | case CatalogueEventsModel::Column::Product: | |
|
84 | 105 | return eventProduct->getProductId(); |
|
85 |
case Column::Tags: |
|
|
106 | case CatalogueEventsModel::Column::Tags: | |
|
86 | 107 | return QString(); |
|
87 | } | |
|
108 | case CatalogueEventsModel::Column::Validation: | |
|
109 | return QVariant(); | |
|
88 | 110 | default: |
|
89 | 111 | break; |
|
90 | 112 | } |
@@ -105,6 +127,7 void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &e | |||
|
105 | 127 | |
|
106 | 128 | impl->m_Events = events; |
|
107 | 129 | impl->m_EventProducts.clear(); |
|
130 | impl->m_EventsWithChanges.clear(); | |
|
108 | 131 | for (auto event : events) { |
|
109 | 132 | impl->parseEventProduct(event); |
|
110 | 133 | } |
@@ -159,21 +182,58 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event) | |||
|
159 | 182 | beginRemoveRows(QModelIndex(), index, index); |
|
160 | 183 | impl->m_Events.removeAt(index); |
|
161 | 184 | impl->m_EventProducts.erase(event.get()); |
|
185 | impl->m_EventsWithChanges.erase(event); | |
|
162 | 186 | endRemoveRows(); |
|
163 | 187 | } |
|
164 | 188 | } |
|
165 | 189 | |
|
190 | QVector<std::shared_ptr<DBEvent> > CatalogueEventsModel::events() const | |
|
191 | { | |
|
192 | return impl->m_Events; | |
|
193 | } | |
|
194 | ||
|
166 | 195 | void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event) |
|
167 | 196 | { |
|
168 |
auto |
|
|
169 | if (i >= 0) { | |
|
170 | auto eventIndex = index(i, 0); | |
|
197 | auto eventIndex = indexOf(event); | |
|
198 | if (eventIndex.isValid()) { | |
|
199 | ||
|
200 | // Refreshes the event line | |
|
171 | 201 | auto colCount = columnCount(); |
|
172 |
emit dataChanged(eventIndex, index( |
|
|
202 | emit dataChanged(eventIndex, index(eventIndex.row(), colCount)); | |
|
173 | 203 | |
|
204 | // Also refreshes its children event products | |
|
174 | 205 | auto childCount = rowCount(eventIndex); |
|
175 | 206 | emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex)); |
|
176 | 207 | } |
|
208 | else { | |
|
209 | qCWarning(LOG_CatalogueEventsModel()) << "refreshEvent: event not found."; | |
|
210 | } | |
|
211 | } | |
|
212 | ||
|
213 | QModelIndex CatalogueEventsModel::indexOf(const std::shared_ptr<DBEvent> &event) const | |
|
214 | { | |
|
215 | auto row = impl->m_Events.indexOf(event); | |
|
216 | if (row >= 0) { | |
|
217 | return index(row, 0); | |
|
218 | } | |
|
219 | ||
|
220 | return QModelIndex(); | |
|
221 | } | |
|
222 | ||
|
223 | void CatalogueEventsModel::setEventHasChanges(const std::shared_ptr<DBEvent> &event, | |
|
224 | bool hasChanges) | |
|
225 | { | |
|
226 | if (hasChanges) { | |
|
227 | impl->m_EventsWithChanges.insert(event); | |
|
228 | } | |
|
229 | else { | |
|
230 | impl->m_EventsWithChanges.erase(event); | |
|
231 | } | |
|
232 | } | |
|
233 | ||
|
234 | bool CatalogueEventsModel::eventsHasChanges(const std::shared_ptr<DBEvent> &event) const | |
|
235 | { | |
|
236 | return impl->m_EventsWithChanges.find(event) != impl->m_EventsWithChanges.cend(); | |
|
177 | 237 | } |
|
178 | 238 | |
|
179 | 239 | QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const |
@@ -249,7 +309,7 int CatalogueEventsModel::rowCount(const QModelIndex &parent) const | |||
|
249 | 309 | |
|
250 | 310 | int CatalogueEventsModel::columnCount(const QModelIndex &parent) const |
|
251 | 311 | { |
|
252 |
return static_cast<int>(CatalogueEventsModel |
|
|
312 | return static_cast<int>(CatalogueEventsModel::Column::NbColumn); | |
|
253 | 313 | } |
|
254 | 314 | |
|
255 | 315 | Qt::ItemFlags CatalogueEventsModel::flags(const QModelIndex &index) const |
@@ -296,8 +356,8 void CatalogueEventsModel::sort(int column, Qt::SortOrder order) | |||
|
296 | 356 | { |
|
297 | 357 | std::sort(impl->m_Events.begin(), impl->m_Events.end(), |
|
298 | 358 | [this, column, order](auto e1, auto e2) { |
|
299 |
auto data1 = impl-> |
|
|
300 |
auto data2 = impl-> |
|
|
359 | auto data1 = impl->sortData(column, e1); | |
|
360 | auto data2 = impl->sortData(column, e2); | |
|
301 | 361 | |
|
302 | 362 | auto result = data1.toString() < data2.toString(); |
|
303 | 363 | |
@@ -305,6 +365,7 void CatalogueEventsModel::sort(int column, Qt::SortOrder order) | |||
|
305 | 365 | }); |
|
306 | 366 | |
|
307 | 367 | emit dataChanged(QModelIndex(), QModelIndex()); |
|
368 | emit modelSorted(); | |
|
308 | 369 | } |
|
309 | 370 | |
|
310 | 371 | Qt::DropActions CatalogueEventsModel::supportedDragActions() const |
@@ -3,6 +3,7 | |||
|
3 | 3 | |
|
4 | 4 | #include <Catalogue/CatalogueController.h> |
|
5 | 5 | #include <Catalogue/CatalogueEventsModel.h> |
|
6 | #include <Catalogue/CatalogueExplorerHelper.h> | |
|
6 | 7 | #include <CatalogueDao.h> |
|
7 | 8 | #include <DBCatalogue.h> |
|
8 | 9 | #include <SqpApplication.h> |
@@ -16,8 +17,8 | |||
|
16 | 17 | |
|
17 | 18 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget") |
|
18 | 19 | |
|
19 | /// Format of the dates appearing in the label of a cursor | |
|
20 | const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss"); | |
|
20 | /// Fixed size of the validation column | |
|
21 | const auto VALIDATION_COLUMN_SIZE = 35; | |
|
21 | 22 | |
|
22 | 23 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { |
|
23 | 24 | |
@@ -277,8 +278,20 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |||
|
277 | 278 | }); |
|
278 | 279 | |
|
279 | 280 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); |
|
280 |
ui->treeView->header()->setSectionResizeMode( |
|
|
281 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name, | |
|
282 | QHeaderView::Stretch); | |
|
283 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation, | |
|
284 | QHeaderView::Fixed); | |
|
285 | ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation, | |
|
286 | VALIDATION_COLUMN_SIZE); | |
|
281 | 287 | ui->treeView->header()->setSortIndicatorShown(true); |
|
288 | ||
|
289 | connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() { | |
|
290 | auto allEvents = impl->m_Model->events(); | |
|
291 | for (auto event : allEvents) { | |
|
292 | setEventChanges(event, impl->m_Model->eventsHasChanges(event)); | |
|
293 | } | |
|
294 | }); | |
|
282 | 295 | } |
|
283 | 296 | |
|
284 | 297 | CatalogueEventsWidget::~CatalogueEventsWidget() |
@@ -294,6 +307,25 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualiz | |||
|
294 | 307 | void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges) |
|
295 | 308 | { |
|
296 | 309 | impl->m_Model->refreshEvent(event); |
|
310 | ||
|
311 | auto eventIndex = impl->m_Model->indexOf(event); | |
|
312 | auto validationIndex | |
|
313 | = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation); | |
|
314 | ||
|
315 | if (hasChanges) { | |
|
316 | if (ui->treeView->indexWidget(validationIndex) == nullptr) { | |
|
317 | auto widget = CatalogueExplorerHelper::buildValidationWidget( | |
|
318 | ui->treeView, [this, event]() { setEventChanges(event, false); }, | |
|
319 | [this, event]() { setEventChanges(event, false); }); | |
|
320 | ui->treeView->setIndexWidget(validationIndex, widget); | |
|
321 | } | |
|
322 | } | |
|
323 | else { | |
|
324 | // Note: the widget is destroyed | |
|
325 | ui->treeView->setIndexWidget(validationIndex, nullptr); | |
|
326 | } | |
|
327 | ||
|
328 | impl->m_Model->setEventHasChanges(event, hasChanges); | |
|
297 | 329 | } |
|
298 | 330 | |
|
299 | 331 | void CatalogueEventsWidget::populateWithCatalogues( |
@@ -314,3 +346,15 void CatalogueEventsWidget::populateWithCatalogues( | |||
|
314 | 346 | |
|
315 | 347 | impl->setEvents(events, ui->treeView); |
|
316 | 348 | } |
|
349 | ||
|
350 | void CatalogueEventsWidget::populateWithAllEvents() | |
|
351 | { | |
|
352 | auto allEvents = sqpApp->catalogueController().retrieveAllEvents(); | |
|
353 | ||
|
354 | QVector<std::shared_ptr<DBEvent> > events; | |
|
355 | for (auto event : allEvents) { | |
|
356 | events << event; | |
|
357 | } | |
|
358 | ||
|
359 | impl->setEvents(events, ui->treeView); | |
|
360 | } |
@@ -1,12 +1,16 | |||
|
1 | 1 | #include "Catalogue/CatalogueExplorer.h" |
|
2 | 2 | #include "ui_CatalogueExplorer.h" |
|
3 | 3 | |
|
4 | #include <Catalogue/CatalogueActionManager.h> | |
|
5 | #include <Catalogue/CatalogueController.h> | |
|
6 | #include <SqpApplication.h> | |
|
4 | 7 | #include <Visualization/VisualizationWidget.h> |
|
5 | 8 | |
|
6 | 9 | #include <DBCatalogue.h> |
|
7 | 10 | #include <DBEvent.h> |
|
8 | 11 | |
|
9 | 12 | struct CatalogueExplorer::CatalogueExplorerPrivate { |
|
13 | CatalogueActionManager m_ActionManager; | |
|
10 | 14 | }; |
|
11 | 15 | |
|
12 | 16 | CatalogueExplorer::CatalogueExplorer(QWidget *parent) |
@@ -16,6 +20,8 CatalogueExplorer::CatalogueExplorer(QWidget *parent) | |||
|
16 | 20 | { |
|
17 | 21 | ui->setupUi(this); |
|
18 | 22 | |
|
23 | impl->m_ActionManager.installSelectionZoneActions(); | |
|
24 | ||
|
19 | 25 | connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) { |
|
20 | 26 | if (catalogues.count() == 1) { |
|
21 | 27 | ui->inspector->setCatalogue(catalogues.first()); |
@@ -34,8 +40,10 CatalogueExplorer::CatalogueExplorer(QWidget *parent) | |||
|
34 | 40 | connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected, |
|
35 | 41 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); |
|
36 | 42 | |
|
37 | connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, | |
|
38 |
|
|
|
43 | connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() { | |
|
44 | ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); | |
|
45 | ui->events->populateWithAllEvents(); | |
|
46 | }); | |
|
39 | 47 | |
|
40 | 48 | connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared, |
|
41 | 49 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); |
@@ -62,11 +70,15 CatalogueExplorer::CatalogueExplorer(QWidget *parent) | |||
|
62 | 70 | connect(ui->events, &CatalogueEventsWidget::selectionCleared, |
|
63 | 71 | [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); }); |
|
64 | 72 | |
|
65 | connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, | |
|
66 | [this](auto catalogue) { ui->catalogues->setCatalogueChanges(catalogue, true); }); | |
|
73 | connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated, [this](auto catalogue) { | |
|
74 | sqpApp->catalogueController().updateCatalogue(catalogue); | |
|
75 | ui->catalogues->setCatalogueChanges(catalogue, true); | |
|
76 | }); | |
|
67 | 77 | |
|
68 | connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, | |
|
69 | [this](auto event) { ui->events->setEventChanges(event, true); }); | |
|
78 | connect(ui->inspector, &CatalogueInspectorWidget::eventUpdated, [this](auto event) { | |
|
79 | sqpApp->catalogueController().updateEvent(event); | |
|
80 | ui->events->setEventChanges(event, true); | |
|
81 | }); | |
|
70 | 82 | |
|
71 | 83 | connect(ui->inspector, &CatalogueInspectorWidget::eventProductUpdated, |
|
72 | 84 | [this](auto event, auto eventProduct) { ui->events->setEventChanges(event, true); }); |
@@ -176,11 +176,14 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget( | |||
|
176 | 176 | treeWidget->addTopLevelItem(separatorItem); |
|
177 | 177 | treeWidget->setItemWidget(separatorItem, 0, separator); |
|
178 | 178 | |
|
179 | auto db = addDatabaseItem("Default", treeWidget); | |
|
179 | auto repositories = sqpApp->catalogueController().getRepositories(); | |
|
180 | for (auto dbname : repositories) { | |
|
181 | auto db = addDatabaseItem(dbname, treeWidget); | |
|
180 | 182 | |
|
181 |
auto catalogues = sqpApp->catalogueController(). |
|
|
182 | for (auto catalogue : catalogues) { | |
|
183 | addCatalogueItem(catalogue, db); | |
|
183 | auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname); | |
|
184 | for (auto catalogue : catalogues) { | |
|
185 | addCatalogueItem(catalogue, db); | |
|
186 | } | |
|
184 | 187 | } |
|
185 | 188 | |
|
186 | 189 | treeWidget->expandAll(); |
@@ -1,12 +1,12 | |||
|
1 | 1 | #include "Catalogue/CatalogueTreeWidgetItem.h" |
|
2 | #include <Catalogue/CatalogueExplorerHelper.h> | |
|
3 | ||
|
4 | #include <Catalogue/CatalogueController.h> | |
|
5 | #include <SqpApplication.h> | |
|
2 | 6 | |
|
3 | 7 | #include <memory> |
|
4 | 8 | |
|
5 | 9 | #include <DBCatalogue.h> |
|
6 | #include <QBoxLayout> | |
|
7 | #include <QToolButton> | |
|
8 | ||
|
9 | const auto VALIDATION_BUTTON_ICON_SIZE = 12; | |
|
10 | 10 | |
|
11 | 11 | /// Column in the tree widget where the apply and cancel buttons must appear |
|
12 | 12 | const auto APPLY_CANCEL_BUTTONS_COLUMN = 1; |
@@ -50,6 +50,7 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &valu | |||
|
50 | 50 | if (newName != impl->m_Catalogue->getName()) { |
|
51 | 51 | setText(0, newName); |
|
52 | 52 | impl->m_Catalogue->setName(newName); |
|
53 | sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue); | |
|
53 | 54 | setHasChanges(true); |
|
54 | 55 | } |
|
55 | 56 | } |
@@ -66,29 +67,11 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const | |||
|
66 | 67 | void CatalogueTreeWidgetItem::setHasChanges(bool value) |
|
67 | 68 | { |
|
68 | 69 | if (value) { |
|
69 | if (treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) == nullptr) { | |
|
70 | auto widet = new QWidget{treeWidget()}; | |
|
71 | ||
|
72 | auto layout = new QHBoxLayout{widet}; | |
|
73 | layout->setContentsMargins(0, 0, 0, 0); | |
|
74 | layout->setSpacing(0); | |
|
75 | ||
|
76 | auto btnValid = new QToolButton{widet}; | |
|
77 | btnValid->setIcon(QIcon{":/icones/save"}); | |
|
78 | btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE}); | |
|
79 | btnValid->setAutoRaise(true); | |
|
80 | QObject::connect(btnValid, &QToolButton::clicked, [this]() { setHasChanges(false); }); | |
|
81 | layout->addWidget(btnValid); | |
|
82 | ||
|
83 | auto btnDiscard = new QToolButton{widet}; | |
|
84 | btnDiscard->setIcon(QIcon{":/icones/discard"}); | |
|
85 | btnDiscard->setIconSize( | |
|
86 | QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE}); | |
|
87 | btnDiscard->setAutoRaise(true); | |
|
88 | QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); }); | |
|
89 | layout->addWidget(btnDiscard); | |
|
90 | ||
|
91 | treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, {widet}); | |
|
70 | if (!hasChanges()) { | |
|
71 | auto widget = CatalogueExplorerHelper::buildValidationWidget( | |
|
72 | treeWidget(), [this]() { setHasChanges(false); }, | |
|
73 | [this]() { setHasChanges(false); }); | |
|
74 | treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, widget); | |
|
92 | 75 | } |
|
93 | 76 | } |
|
94 | 77 | else { |
@@ -97,6 +80,11 void CatalogueTreeWidgetItem::setHasChanges(bool value) | |||
|
97 | 80 | } |
|
98 | 81 | } |
|
99 | 82 | |
|
83 | bool CatalogueTreeWidgetItem::hasChanges() | |
|
84 | { | |
|
85 | return treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) != nullptr; | |
|
86 | } | |
|
87 | ||
|
100 | 88 | void CatalogueTreeWidgetItem::refresh() |
|
101 | 89 | { |
|
102 | 90 | emitDataChanged(); |
@@ -5,7 +5,9 | |||
|
5 | 5 | #include <Actions/ActionsGuiController.h> |
|
6 | 6 | #include <SqpApplication.h> |
|
7 | 7 | |
|
8 |
VisualizationActionManager::VisualizationActionManager() |
|
|
8 | VisualizationActionManager::VisualizationActionManager() | |
|
9 | { | |
|
10 | } | |
|
9 | 11 | |
|
10 | 12 | void VisualizationActionManager::installSelectionZoneActions() |
|
11 | 13 | { |
@@ -241,10 +241,9 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget | |||
|
241 | 241 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
242 | 242 | connect(ui->widget, &QCustomPlot::mouseDoubleClick, this, |
|
243 | 243 | &VisualizationGraphWidget::onMouseDoubleClick); |
|
244 | connect( | |
|
245 | ui->widget->xAxis, | |
|
246 | static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(&QCPAxis::rangeChanged), | |
|
247 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |
|
244 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
|
245 | &QCPAxis::rangeChanged), | |
|
246 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |
|
248 | 247 | |
|
249 | 248 | // Activates menu when right clicking on the graph |
|
250 | 249 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
@@ -695,9 +694,9 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |||
|
695 | 694 | |
|
696 | 695 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
697 | 696 | { |
|
698 | qCDebug(LOG_VisualizationGraphWidget()) | |
|
699 | << tr("TORM: VisualizationGraphWidget::onRangeChanged") | |
|
700 | << QThread::currentThread()->objectName() << "DoAcqui" << impl->m_DoAcquisition; | |
|
697 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") | |
|
698 | << QThread::currentThread()->objectName() << "DoAcqui" | |
|
699 | << impl->m_DoAcquisition; | |
|
701 | 700 | |
|
702 | 701 | auto graphRange = SqpRange{t1.lower, t1.upper}; |
|
703 | 702 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
@@ -142,7 +142,9 VisualizationSelectionZoneItem::VisualizationSelectionZoneItem(QCustomPlot *plot | |||
|
142 | 142 | setColor(QColor(DEFAULT_COLOR)); |
|
143 | 143 | } |
|
144 | 144 | |
|
145 |
VisualizationSelectionZoneItem::~VisualizationSelectionZoneItem() |
|
|
145 | VisualizationSelectionZoneItem::~VisualizationSelectionZoneItem() | |
|
146 | { | |
|
147 | } | |
|
146 | 148 | |
|
147 | 149 | VisualizationGraphWidget *VisualizationSelectionZoneItem::parentGraphWidget() const noexcept |
|
148 | 150 | { |
@@ -365,8 +365,8 void TestAmdaResultParser::testReadSpectrogramTxt_data() | |||
|
365 | 365 | {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}, |
|
366 | 366 | {20907.664, 32076.725, 13008.381, 13142.759, 23226.998}}); |
|
367 | 367 | |
|
368 | QTest::newRow("Valid file (four bands)") | |
|
369 | << QStringLiteral("spectro/ValidSpectrogram2.txt") << fourBandsResult; | |
|
368 | QTest::newRow("Valid file (four bands)") << QStringLiteral("spectro/ValidSpectrogram2.txt") | |
|
369 | << fourBandsResult; | |
|
370 | 370 | QTest::newRow("Valid file (four unsorted bands)") |
|
371 | 371 | << QStringLiteral("spectro/ValidSpectrogram3.txt") |
|
372 | 372 | << fourBandsResult; // Bands and values are sorted |
General Comments 0
You need to be logged in to leave comments.
Login now