dbselect
Loading...
Searching...
No Matches
dbselectView.h
Go to the documentation of this file.
1#pragma once
2
3// gemc
4#include <gemc/gdetector/gdetectorConstruction.h>
5#include <gemc/gbase/gbase.h>
6
7// qt
8#include <QWidget>
9#include <QTreeView>
10#include <QStandardItem>
11#include <QLabel>
12#include <QPushButton>
13#include <QComboBox>
14#include <QStyledItemDelegate>
15
16// c++
17#include <sqlite3.h>
18#include <string>
19#include <vector>
20
21
46class DBSelectView : public QWidget, public GBase<DBSelectView> {
47 Q_OBJECT
48public:
62 explicit DBSelectView(const std::shared_ptr<GOptions>& gopts,
64 QWidget* parent = nullptr);
65
72 ~DBSelectView() override { if (db) sqlite3_close(db); }
73
86
87private:
98 void setupUI();
99
106 void loadExperiments();
107
119 void loadSystemsForExperiment(QStandardItem* experimentItem);
120
130 QStringList getAvailableRuns(const std::string& system, const std::string& variation) const;
131
143 int getGeometryCount(const std::string& system, const std::string& variation, int run) const;
144
154 void updateSystemItemAppearance(QStandardItem* systemItem);
155
166 bool systemAvailable(const std::string& system, const std::string& variation, int run);
167
173 void updateExperimentHeader();
174
182 void updateModifiedUI();
183
190 void resizeExperimentColumns();
191
198 QIcon createStatusIcon(const QColor& color);
199
209 bool isGeometryTableValid() const;
210
221 void applyGSystemSelections();
222
223private:
225 bool modified = false;
226
228 QLabel* titleLabel = nullptr;
229
231 QPushButton* reloadButton = nullptr;
232
234 sqlite3* db = nullptr;
235
237 std::string dbhost;
238
240 std::string experiment;
241
243 QTreeView* experimentTree = nullptr;
244
246 QStandardItemModel* experimentModel = nullptr;
247
249 QLabel* experimentHeaderLabel = nullptr;
250
252 bool m_ignoreItemChange = false;
253
255 GDetectorConstruction* gDetectorConstruction = nullptr;
256
258 std::shared_ptr<GOptions> gopt;
259
260private slots:
271 void onItemChanged(QStandardItem* item);
272
273public slots:
282 void reload_geometry();
283
284signals:
292
300};
301
302
303//
304// A custom delegate for drop-down editing.
305//
315class ComboDelegate : public QStyledItemDelegate {
316 Q_OBJECT
317public:
322 explicit ComboDelegate(QObject* parent = nullptr) : QStyledItemDelegate(parent) {}
323
334 QWidget* createEditor(QWidget* parent,
335 const QStyleOptionViewItem& option,
336 const QModelIndex& index) const override {
337 Q_UNUSED(option);
338 Q_UNUSED(index);
339 auto editor = new QComboBox(parent);
340 return editor;
341 }
342
352 void setEditorData(QWidget* editor, const QModelIndex& index) const override {
353 auto combo = qobject_cast<QComboBox*>(editor);
354 if (!combo)
355 return;
356
357 // Retrieve list from UserRole.
358 QVariant var = index.model()->data(index, Qt::UserRole);
359 QStringList opts = var.toStringList();
360
361 combo->clear();
362 combo->addItems(opts);
363
364 QString currentText = index.model()->data(index, Qt::EditRole).toString();
365 int idx = combo->findText(currentText);
366 if (idx >= 0)
367 combo->setCurrentIndex(idx);
368 }
369
379 void setModelData(QWidget* editor, QAbstractItemModel* model,
380 const QModelIndex& index) const override {
381 auto combo = qobject_cast<QComboBox*>(editor);
382 if (!combo)
383 return;
384
385 QString value = combo->currentText();
386 model->setData(index, value, Qt::EditRole);
387 }
388
396 void updateEditorGeometry(QWidget* editor,
397 const QStyleOptionViewItem& option,
398 const QModelIndex& index) const override {
399 Q_UNUSED(index);
400 editor->setGeometry(option.rect);
401 }
402};
Item delegate that edits a cell using a QComboBox populated from Qt::UserRole.
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Write the selected editor value back to the model.
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Create a QComboBox editor for the given cell.
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Populate the editor from the model.
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Position the editor within the cell rectangle.
ComboDelegate(QObject *parent=nullptr)
Construct the delegate.
Qt widget used to select experiment/system configurations from an SQLite geometry database.
void geometryReloaded()
Emitted after detector construction has reloaded geometry from the selected systems.
SystemList get_gsystems()
Build and return the list of selected systems as a SystemList.
~DBSelectView() override
Destructor.
void geometryAboutToReload()
Emitted immediately before detector construction replaces the current geometry.
DBSelectView(const std::shared_ptr< GOptions > &gopts, GDetectorConstruction *dc, QWidget *parent=nullptr)
Construct the view and populate the experiment/system model from the database.
void reload_geometry()
Slot invoked by the Reload button to reload geometry based on current selections.
std::vector< SystemPtr > SystemList