dbselect
Loading...
Searching...
No Matches
dbselectView.h
Go to the documentation of this file.
1#pragma once
2
3// gemc
5#include "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
47class DBSelectView : public QWidget, public GBase<DBSelectView> {
48 Q_OBJECT
49public:
63 explicit DBSelectView(const std::shared_ptr<GOptions>& gopts,
65 QWidget* parent = nullptr);
66
73 ~DBSelectView() override { if (db) sqlite3_close(db); }
74
87
88private:
99 void setupUI();
100
107 void loadExperiments();
108
120 void loadSystemsForExperiment(QStandardItem* experimentItem);
121
130 QStringList getAvailableVariations(const std::string& system) const;
131
140 QStringList getAvailableRuns(const std::string& system);
141
153 int getGeometryCount(const std::string& system, const std::string& variation, int run) const;
154
164 void updateSystemItemAppearance(QStandardItem* systemItem);
165
176 bool systemAvailable(const std::string& system, const std::string& variation, int run);
177
183 void updateExperimentHeader();
184
192 void updateModifiedUI();
193
200 QIcon createStatusIcon(const QColor& color);
201
211 bool isGeometryTableValid() const;
212
223 void applyGSystemSelections();
224
225private:
227 bool modified = false;
228
230 QLabel* titleLabel = nullptr;
231
233 QPushButton* reloadButton = nullptr;
234
236 sqlite3* db = nullptr;
237
239 std::string dbhost;
240
242 std::string experiment;
243
245 QTreeView* experimentTree = nullptr;
246
248 QStandardItemModel* experimentModel = nullptr;
249
251 QLabel* experimentHeaderLabel = nullptr;
252
254 bool m_ignoreItemChange = false;
255
257 GDetectorConstruction* gDetectorConstruction = nullptr;
258
260 std::shared_ptr<GOptions> gopt;
261
262private slots:
273 void onItemChanged(QStandardItem* item);
274
275public slots:
284 void reload_geometry();
285};
286
287
288//
289// A custom delegate for drop-down editing (for both variations and runs).
290//
300class ComboDelegate : public QStyledItemDelegate {
301 Q_OBJECT
302public:
307 explicit ComboDelegate(QObject* parent = nullptr) : QStyledItemDelegate(parent) {}
308
319 QWidget* createEditor(QWidget* parent,
320 const QStyleOptionViewItem& option,
321 const QModelIndex& index) const override {
322 Q_UNUSED(option);
323 Q_UNUSED(index);
324 auto editor = new QComboBox(parent);
325 return editor;
326 }
327
337 void setEditorData(QWidget* editor, const QModelIndex& index) const override {
338 auto combo = qobject_cast<QComboBox*>(editor);
339 if (!combo)
340 return;
341
342 // Retrieve list from UserRole.
343 QVariant var = index.model()->data(index, Qt::UserRole);
344 QStringList opts = var.toStringList();
345
346 combo->clear();
347 combo->addItems(opts);
348
349 QString currentText = index.model()->data(index, Qt::EditRole).toString();
350 int idx = combo->findText(currentText);
351 if (idx >= 0)
352 combo->setCurrentIndex(idx);
353 }
354
364 void setModelData(QWidget* editor, QAbstractItemModel* model,
365 const QModelIndex& index) const override {
366 auto combo = qobject_cast<QComboBox*>(editor);
367 if (!combo)
368 return;
369
370 QString value = combo->currentText();
371 model->setData(index, value, Qt::EditRole);
372 }
373
381 void updateEditorGeometry(QWidget* editor,
382 const QStyleOptionViewItem& option,
383 const QModelIndex& index) const override {
384 Q_UNUSED(index);
385 editor->setGeometry(option.rect);
386 }
387};
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.
SystemList get_gsystems()
Build and return the list of selected systems as a SystemList.
~DBSelectView() override
Destructor.
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