Skip to content

Commit

Permalink
Refactor VolbxMain methods to improve const correctness and enhance c…
Browse files Browse the repository at this point in the history
…ode clarity.
  • Loading branch information
przemek83 committed Jan 14, 2025
1 parent 34c0e85 commit 3fff4a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
35 changes: 17 additions & 18 deletions src/GUI/VolbxMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ VolbxMain::VolbxMain()

void VolbxMain::setStandardIcons()
{
QStyle* style{QApplication::style()};
const QStyle* style{QApplication::style()};
ui_->actionImportData->setIcon(
style->standardIcon(QStyle::SP_DialogOpenButton));
ui_->actionSaveDatasetAs->setIcon(
Expand All @@ -65,7 +65,7 @@ void VolbxMain::setStandardIcons()
style->standardIcon(QStyle::QStyle::SP_FileDialogInfoView));
}

void VolbxMain::connectFilter()
void VolbxMain::connectFilter() const
{
connect(&filters_, &FiltersDock::filterNames, &tabWidget_,
&TabWidget::setTextFilter);
Expand All @@ -75,7 +75,7 @@ void VolbxMain::connectFilter()
&TabWidget::setNumericFilter);
}

void VolbxMain::connectPlots()
void VolbxMain::connectPlots() const
{
connect(ui_->actionBasic_plot, &QAction::triggered, &tabWidget_,
&TabWidget::addBasicPlot);
Expand Down Expand Up @@ -124,7 +124,7 @@ void VolbxMain::setupFilters()
filters_.titleBarWidget()->height());
}

void VolbxMain::setupNetworkManager()
void VolbxMain::setupNetworkManager() const
{
connect(&networkManager_, &QNetworkAccessManager::finished, this,
&VolbxMain::updateCheckReplyFinished);
Expand Down Expand Up @@ -168,7 +168,7 @@ void VolbxMain::addStylesSectionToMenu()
ui_->menuOptions->addActions(actionsGroup->actions());
}

void VolbxMain::addStylesFoundInAppDir(QActionGroup* actionsGroup)
void VolbxMain::addStylesFoundInAppDir(QActionGroup* actionsGroup) const
{
const QStringList nameFilter(QStringLiteral("*.css"));
const QDir directory(QCoreApplication::applicationDirPath());
Expand All @@ -177,7 +177,7 @@ void VolbxMain::addStylesFoundInAppDir(QActionGroup* actionsGroup)
addStyleToMenu(styleFile.baseName(), actionsGroup);
}

void VolbxMain::addStandardQtStyles(QActionGroup* actionsGroup)
void VolbxMain::addStandardQtStyles(QActionGroup* actionsGroup) const
{
const QStringList qtStylesList{QStyleFactory::keys()};
for (const QString& style : qtStylesList)
Expand All @@ -188,8 +188,8 @@ bool VolbxMain::doesUserWantsToCheckForUpdates()
{
bool shouldCheckForUpdates{false};
CheckUpdates dialog(this);
const int reply{dialog.exec()};
if (reply == QDialog::Accepted)

if (dialog.exec() == QDialog::Accepted)
shouldCheckForUpdates = true;

if (dialog.isSaveFlagSet())
Expand Down Expand Up @@ -283,9 +283,9 @@ void VolbxMain::manageActions(bool tabExists)
setTooltipsForChartsActions(activateCharts);
}

void VolbxMain::saveDataset(const QString& datasetName)
void VolbxMain::saveDataset(const QString& datasetName) const
{
DataView* view{tabWidget_.getCurrentDataView()};
const DataView* view{tabWidget_.getCurrentDataView()};
if (view == nullptr)
return;

Expand Down Expand Up @@ -381,17 +381,16 @@ void VolbxMain::importDataset(std::unique_ptr<Dataset> dataset)

void VolbxMain::actionImportDataTriggered()
{
ImportData import(this);
if (import.exec() == QDialog::Accepted)
importDataset(import.getSelectedDataset());
ImportData importData(this);
if (importData.exec() == QDialog::Accepted)
importDataset(importData.getSelectedDataset());
}

QString VolbxMain::createNameForTab(const std::unique_ptr<Dataset>& dataset)
{
QString nameForTabBar{dataset->getName()};
if (auto [ok, column] = dataset->getTaggedColumn(ColumnTag::VALUE); ok)
nameForTabBar.append(
" (" + dataset->getHeaderName(static_cast<int>(column)) + ")");
if (auto [ok, column]{dataset->getTaggedColumn(ColumnTag::VALUE)}; ok)
nameForTabBar.append(" (" + dataset->getHeaderName(column) + ")");
return nameForTabBar;
}

Expand Down Expand Up @@ -483,9 +482,9 @@ void VolbxMain::actionUpdateAutoToggled(bool alwaysCheck)
Configuration::getInstance().setUpdatePolicy(alwaysCheck);
}

void VolbxMain::styleChanged()
void VolbxMain::styleChanged() const
{
auto* action{qobject_cast<QAction*>(sender())};
const auto* action{qobject_cast<QAction*>(sender())};
const QString style{action->text()};
if (QStyleFactory::keys().contains(style))
Application::setQtStyle(style);
Expand Down
14 changes: 7 additions & 7 deletions src/GUI/VolbxMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ class VolbxMain : public QMainWindow
void closeEvent(QCloseEvent* event) override;

private:
void connectFilter();
void connectFilter() const;

void connectPlots();
void connectPlots() const;

void connectActions();

void setupTabWidget();

void setupFilters();

void setupNetworkManager();
void setupNetworkManager() const;

void addStyleToMenu(const QString& name, QActionGroup* actionsGroup) const;

Expand All @@ -51,17 +51,17 @@ class VolbxMain : public QMainWindow

void addStylesSectionToMenu();

void addStylesFoundInAppDir(QActionGroup* actionsGroup);
void addStylesFoundInAppDir(QActionGroup* actionsGroup) const;

void addStandardQtStyles(QActionGroup* actionsGroup);
void addStandardQtStyles(QActionGroup* actionsGroup) const;

void setStandardIcons();

bool doesUserWantsToCheckForUpdates();

void setTooltipsForChartsActions(bool chartsActive);

void saveDataset(const QString& datasetName);
void saveDataset(const QString& datasetName) const;

void importDataset(std::unique_ptr<Dataset> dataset);

Expand Down Expand Up @@ -101,5 +101,5 @@ private Q_SLOTS:

static void actionUpdateAutoToggled(bool alwaysCheck);

void styleChanged();
void styleChanged() const;
};

0 comments on commit 3fff4a3

Please sign in to comment.