Skip to content

Commit 8f22563

Browse files
committed
removed shadowed method arguments experiments and db
1 parent 3a2af0a commit 8f22563

2 files changed

Lines changed: 42 additions & 33 deletions

File tree

dbselect/dbselectView.cc

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ DBSelectView::DBSelectView(const std::shared_ptr<GOptions>& gopts, GDetectorCons
2323
dbhost = gopts->getScalarString("sql");
2424
experiment = gopts->getScalarString("experiment");
2525

26-
if (sqlite3_open(dbhost.c_str(), &db) != SQLITE_OK || !isGeometryTableValid(db)) {
26+
if (sqlite3_open(dbhost.c_str(), &db) != SQLITE_OK || !isGeometryTableValid()) {
2727
std::cerr << "Database Warning: Failed to open or validate database: " << dbhost << std::endl;
2828
sqlite3_close(db);
2929
db = nullptr;
3030

3131
std::filesystem::path gemcRoot = gutilities::gemc_root();
3232
dbhost = gemcRoot.string() + "/examples/gemc.db";
3333

34-
if (sqlite3_open(dbhost.c_str(), &db) != SQLITE_OK || !isGeometryTableValid(db)) {
34+
if (sqlite3_open(dbhost.c_str(), &db) != SQLITE_OK || !isGeometryTableValid()) {
3535
std::cerr << "Database Error: Failed to open or validate backup database: " << dbhost << std::endl;
3636
sqlite3_close(db);
3737
db = nullptr;
@@ -62,7 +62,7 @@ DBSelectView::DBSelectView(const std::shared_ptr<GOptions>& gopts, GDetectorCons
6262
}
6363

6464
// Apply selections from GSystem objects.
65-
applyGSystemSelections(gopts);
65+
applyGSystemSelections();
6666

6767
// Update system appearances initially.
6868
for (int i = 0; i < experimentModel->rowCount(); ++i) {
@@ -83,7 +83,7 @@ DBSelectView::DBSelectView(const std::shared_ptr<GOptions>& gopts, GDetectorCons
8383

8484

8585
// Checks that the database has a non-empty "geometry" table.
86-
bool DBSelectView::isGeometryTableValid(sqlite3* db) {
86+
bool DBSelectView::isGeometryTableValid() const {
8787
if (!db) return false;
8888
sqlite3_stmt* stmt = nullptr;
8989
const char* sql_query = "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='geometry'";
@@ -107,8 +107,8 @@ bool DBSelectView::isGeometryTableValid(sqlite3* db) {
107107
}
108108

109109
// Applies selections from the GSystem vector to update the UI.
110-
void DBSelectView::applyGSystemSelections(std::shared_ptr<GOptions> gopts) {
111-
auto gsystems = gsystem::getSystems(gopts); // Get vector of GSystem objects.
110+
void DBSelectView::applyGSystemSelections() {
111+
auto gsystems = gsystem::getSystems(gopt); // Get vector of GSystem objects.
112112
for (int i = 0; i < experimentModel->rowCount(); ++i) {
113113
QStandardItem* expItem = experimentModel->item(i, 0);
114114
if (!expItem) continue;
@@ -162,7 +162,7 @@ void DBSelectView::setupUI() {
162162
mainLayout->setContentsMargins(10, 10, 10, 10);
163163
mainLayout->setSpacing(10);
164164

165-
// Header layout: left side holds labels, right side holds the Reload button.
165+
// Header layout: the left side holds labels, the right side holds the Reload button.
166166
auto headerLayout = new QHBoxLayout();
167167

168168
// Vertical layout for the two labels.
@@ -191,7 +191,7 @@ void DBSelectView::setupUI() {
191191
reloadButton = new QPushButton("Reload", this);
192192
reloadButton->setEnabled(false); // initially disabled (modified is false)
193193
headerLayout->addWidget(reloadButton);
194-
connect(reloadButton, &QPushButton::clicked, this, &DBSelectView::reload_geometry);
194+
connect(reloadButton, &QPushButton::pressed, this, &DBSelectView::reload_geometry);
195195

196196
mainLayout->addLayout(headerLayout);
197197

@@ -229,21 +229,22 @@ void DBSelectView::loadExperiments() {
229229
const char* expText = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
230230
if (expText) {
231231
QString expName = QString::fromUtf8(expText);
232-
auto* expItem = new QStandardItem(expName);
232+
experiment = expName.toStdString();
233+
auto* expItem = new QStandardItem(expName);
233234
expItem->setFlags(expItem->flags() & ~Qt::ItemIsEditable);
234235
expItem->setCheckable(true);
235236
expItem->setCheckState(Qt::Unchecked);
236237
auto* dummyEntries = new QStandardItem("");
237238
auto* dummyVar = new QStandardItem("");
238239
auto* dummyRun = new QStandardItem("");
239-
loadSystemsForExperiment(expItem, expName.toStdString());
240+
loadSystemsForExperiment(expItem);
240241
experimentModel->appendRow(QList<QStandardItem*>() << expItem << dummyEntries << dummyVar << dummyRun);
241242
}
242243
}
243244
sqlite3_finalize(stmt);
244245
}
245246

246-
void DBSelectView::loadSystemsForExperiment(QStandardItem* experimentItem, const std::string& experiment) {
247+
void DBSelectView::loadSystemsForExperiment(QStandardItem* experimentItem) {
247248
sqlite3_stmt* stmt = nullptr;
248249
const char* sql_query = "SELECT DISTINCT system FROM geometry WHERE experiment = ?";
249250
if (sqlite3_prepare_v2(db, sql_query, -1, &stmt, nullptr) == SQLITE_OK) {
@@ -282,7 +283,7 @@ void DBSelectView::loadSystemsForExperiment(QStandardItem* experimentItem, const
282283
sqlite3_finalize(stmt);
283284
}
284285

285-
int DBSelectView::getGeometryCount(const std::string& experiment, const std::string& system, const std::string& variation, int run) {
286+
int DBSelectView::getGeometryCount(const std::string& system, const std::string& variation, int run) const {
286287
int count = 0;
287288
std::string query = "SELECT COUNT(*) FROM geometry WHERE experiment = ? AND system = ? AND variation = ? AND run = ?";
288289
sqlite3_stmt* stmt = nullptr;
@@ -298,7 +299,7 @@ int DBSelectView::getGeometryCount(const std::string& experiment, const std::str
298299
return count;
299300
}
300301

301-
QStringList DBSelectView::getAvailableVariations(const std::string& system) {
302+
QStringList DBSelectView::getAvailableVariations(const std::string& system) const {
302303
QStringList varList;
303304
sqlite3_stmt* stmt = nullptr;
304305
const char* sql_query = "SELECT DISTINCT variation FROM geometry WHERE system = ?";
@@ -357,18 +358,19 @@ void DBSelectView::updateSystemItemAppearance(QStandardItem* systemItem) {
357358
QStandardItem* parentItem = systemItem->parent();
358359
if (!parentItem)
359360
return;
360-
int row = systemItem->row();
361-
QStandardItem* varItem = parentItem->child(row, 2); // Variation column.
362-
QStandardItem* runItem = parentItem->child(row, 3); // Run column.
363-
QString varStr = varItem ? varItem->data(Qt::EditRole).toString() : "";
364-
QString runStr = runItem ? runItem->data(Qt::EditRole).toString() : "";
365-
int run = runStr.toInt();
366-
QString expStr = parentItem->text();
367-
std::string experimentName = expStr.toStdString();
368-
std::string systemName = systemItem->text().toStdString();
369-
std::string variation = varStr.toStdString();
370-
int count = getGeometryCount(experimentName, systemName, variation, run);
371-
QStandardItem* entriesItem = parentItem->child(row, 1);
361+
362+
int row = systemItem->row();
363+
QStandardItem* varItem = parentItem->child(row, 2); // Variation column.
364+
QStandardItem* runItem = parentItem->child(row, 3); // Run column.
365+
QString varStr = varItem ? varItem->data(Qt::EditRole).toString() : "";
366+
QString runStr = runItem ? runItem->data(Qt::EditRole).toString() : "";
367+
int run = runStr.toInt();
368+
QString expStr = parentItem->text();
369+
experiment = expStr.toStdString();
370+
std::string systemName = systemItem->text().toStdString();
371+
std::string variation = varStr.toStdString();
372+
int count = getGeometryCount(systemName, variation, run);
373+
QStandardItem* entriesItem = parentItem->child(row, 1);
372374
if (entriesItem) { entriesItem->setText(QString::number(count)); }
373375
bool available = (count > 0);
374376
QColor statusColor = available ? QColor("green") : QColor("red");
@@ -481,6 +483,7 @@ void DBSelectView::updateModifiedUI() {
481483
titleLabel->setText("Experiment Selection* (modified)");
482484
else
483485
titleLabel->setText("Experiment Selection");
486+
484487
reloadButton->setEnabled(modified);
485488

486489
experimentTree->resizeColumnToContents(0);
@@ -493,12 +496,19 @@ void DBSelectView::updateModifiedUI() {
493496

494497
/**
495498
* reload_geometry() is the slot for the Reload button.
496-
* Currently it resets the modified flag and updates the UI.
499+
* Currently, it resets the modified flag and updates the UI.
497500
* (Geometry reloading logic can be added here.)
498501
*/
499502
void DBSelectView::reload_geometry() {
503+
log->info(0, SFUNCTION_NAME, ": Reloading geometry...");
504+
505+
auto reloaded_system = get_gsystems();
506+
for (auto& gsys : reloaded_system) {
507+
log->info(2, SFUNCTION_NAME, ": reloaded system: ", gsys->getName());
508+
}
509+
500510
// Reload the geometry using the updated GSystem objects.
501-
gDetectorConstruction->reload_geometry(get_gsystems());
511+
gDetectorConstruction->reload_geometry(reloaded_system);
502512

503513
// Reset the modified flag.
504514
modified = false;

dbselect/dbselectView.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class DBSelectView : public QWidget, public GBase<DBSelectView> {
4545
// UI setup and update methods.
4646
void setupUI();
4747
void loadExperiments();
48-
void loadSystemsForExperiment(QStandardItem *experimentItem, const std::string &experiment);
49-
QStringList getAvailableVariations(const std::string &system);
48+
void loadSystemsForExperiment(QStandardItem *experimentItem);
49+
QStringList getAvailableVariations(const std::string &system) const;
5050
QStringList getAvailableRuns(const std::string &system);
51-
int getGeometryCount(const std::string &experiment, const std::string &system, const std::string &variation, int run);
51+
int getGeometryCount(const std::string &system, const std::string &variation, int run) const;
5252
void updateSystemItemAppearance(QStandardItem *systemItem);
5353
bool systemAvailable(const std::string &system, const std::string &variation, int run);
5454
void updateExperimentHeader();
@@ -78,8 +78,8 @@ class DBSelectView : public QWidget, public GBase<DBSelectView> {
7878

7979
// Helper functions.
8080
QIcon createStatusIcon(const QColor &color);
81-
bool isGeometryTableValid(sqlite3 *db);
82-
void applyGSystemSelections(std::shared_ptr<GOptions> gopts);
81+
bool isGeometryTableValid() const;
82+
void applyGSystemSelections();
8383

8484
// Pointer to the detector construction (geometry reloading).
8585
GDetectorConstruction *gDetectorConstruction;
@@ -92,7 +92,6 @@ private slots:
9292
void onItemChanged(QStandardItem *item);
9393

9494
public slots:
95-
9695
/// Slot for the Reload button.
9796
void reload_geometry();
9897
};

0 commit comments

Comments
 (0)