# HG changeset patch # User Teemu Piippo # Date 1486666872 -7200 # Node ID 117e4880666ef45517bc152f7a5546581e78c05d # Parent ffd49a28f49edf9ea01aa5983d3d2f5ef0bcd3b3 Cleaned up ExternalProgramPathDialog diff -r ffd49a28f49e -r 117e4880666e src/dialogs.cpp --- a/src/dialogs.cpp Thu Feb 09 20:54:21 2017 +0200 +++ b/src/dialogs.cpp Thu Feb 09 21:01:12 2017 +0200 @@ -19,47 +19,50 @@ #include #include "dialogs.h" #include "mainwindow.h" +#include "dialogs/configdialog.h" #include "glRenderer.h" #include "documentation.h" #include "dialogs.h" #include "ui_overlay.h" #include "ui_extprogpath.h" -extern const char* g_extProgPathFilter; - -// ============================================================================= -// ============================================================================= -ExtProgPathPrompt::ExtProgPathPrompt (QString progName, QWidget* parent, Qt::WindowFlags f) : - QDialog (parent, f), - ui (new Ui_ExtProgPath) +/* + * Constructs a new external program path dialog. + */ +ExternalProgramPathDialog::ExternalProgramPathDialog(QString programName, QWidget* parent, Qt::WindowFlags flags) : + QDialog {parent, flags}, + ui {*new Ui_ExtProgPath} { - ui->setupUi (this); - QString labelText = ui->m_label->text(); - labelText.replace ("", progName); - ui->m_label->setText (labelText); - connect (ui->m_findPath, SIGNAL (clicked (bool)), this, SLOT (findPath())); + ui.setupUi (this); + QString labelText = ui.programLabel->text(); + labelText.replace("", programName); + ui.programLabel->setText(labelText); + connect(ui.findPathButton, SIGNAL(clicked (bool)), this, SLOT(findPath())); } -// ============================================================================= -// ============================================================================= -ExtProgPathPrompt::~ExtProgPathPrompt() +/* + * Destructs the UI pointer when the dialog is deleted. + */ +ExternalProgramPathDialog::~ExternalProgramPathDialog() { - delete ui; + delete &ui; } -// ============================================================================= -// ============================================================================= -void ExtProgPathPrompt::findPath() +/* + * Handler for the button in the dialog, shows a modal dialog for the user to locate the program. + */ +void ExternalProgramPathDialog::findPath() { - QString path = QFileDialog::getOpenFileName (nullptr, "", "", g_extProgPathFilter); + QString path = QFileDialog::getOpenFileName(nullptr, "", "", ConfigDialog::externalProgramPathFilter); if (not path.isEmpty()) - ui->m_path->setText (path); + ui.path->setText(path); } -// ============================================================================= -// ============================================================================= -QString ExtProgPathPrompt::getPath() const +/* + * Returns the path specified by the user in this dialog. + */ +QString ExternalProgramPathDialog::path() const { - return ui->m_path->text(); + return ui.path->text(); } diff -r ffd49a28f49e -r 117e4880666e src/dialogs.h --- a/src/dialogs.h Thu Feb 09 20:54:21 2017 +0200 +++ b/src/dialogs.h Thu Feb 09 21:01:12 2017 +0200 @@ -19,38 +19,21 @@ #pragma once #include #include "main.h" -#include "basics.h" -class Ui_ExtProgPath; -class QRadioButton; -class QCheckBox; -class QProgressBar; -class QGroupBox; -class QDialogButtonBox; -class QDoubleSpinBox; -class QPushButton; -class QLineEdit; -class QSpinBox; -class RadioGroup; -class QLabel; -class QAbstractButton; -class Ui_OverlayUI; -class Ui_LDPathUI; -class Ui_OpenProgressUI; - -// ============================================================================= -class ExtProgPathPrompt : public QDialog +/* + * Prompts the user for a path to an external program. + */ +class ExternalProgramPathDialog : public QDialog { Q_OBJECT public: - explicit ExtProgPathPrompt (QString progName, QWidget* parent = 0, Qt::WindowFlags f = 0); - virtual ~ExtProgPathPrompt(); - QString getPath() const; + explicit ExternalProgramPathDialog(QString programName, QWidget* parent = nullptr, Qt::WindowFlags f = 0); + ~ExternalProgramPathDialog(); -public slots: - void findPath(); + Q_SLOT void findPath(); + QString path() const; private: - Ui_ExtProgPath* ui; + class Ui_ExtProgPath& ui; }; diff -r ffd49a28f49e -r 117e4880666e src/dialogs/configdialog.cpp --- a/src/dialogs/configdialog.cpp Thu Feb 09 20:54:21 2017 +0200 +++ b/src/dialogs/configdialog.cpp Thu Feb 09 21:01:12 2017 +0200 @@ -41,7 +41,7 @@ #include "configdialog.h" #include "ui_configdialog.h" -const char* g_extProgPathFilter = +const char* const ConfigDialog::externalProgramPathFilter = #ifdef _WIN32 "Applications (*.exe)(*.exe);;" #endif @@ -614,7 +614,7 @@ ExternalProgramWidgets& widgets = m_externalProgramWidgets[program]; QString filepath = QFileDialog::getOpenFileName (this, format ("Path to %1", toolset->externalProgramName (program)), - widgets.input->text(), g_extProgPathFilter); + widgets.input->text(), externalProgramPathFilter); if (filepath.isEmpty()) return; diff -r ffd49a28f49e -r 117e4880666e src/dialogs/configdialog.h --- a/src/dialogs/configdialog.h Thu Feb 09 20:54:21 2017 +0200 +++ b/src/dialogs/configdialog.h Thu Feb 09 21:01:12 2017 +0200 @@ -68,6 +68,8 @@ explicit ConfigDialog (QWidget* parent = nullptr, Tab defaulttab = (Tab) 0, Qt::WindowFlags f = 0); virtual ~ConfigDialog(); + static const char* const externalProgramPathFilter; + private: class Ui_ConfigDialog& ui; QList quickColorItems; diff -r ffd49a28f49e -r 117e4880666e src/toolsets/extprogramtoolset.cpp --- a/src/toolsets/extprogramtoolset.cpp Thu Feb 09 20:54:21 2017 +0200 +++ b/src/toolsets/extprogramtoolset.cpp Thu Feb 09 21:01:12 2017 +0200 @@ -121,11 +121,11 @@ if (not path.isEmpty()) return true; - ExtProgPathPrompt* dialog = new ExtProgPathPrompt (externalProgramName (program)); + ExternalProgramPathDialog* dialog = new ExternalProgramPathDialog (externalProgramName (program)); - if (dialog->exec() and not dialog->getPath().isEmpty()) + if (dialog->exec() and not dialog->path().isEmpty()) { - setPathSetting (program, dialog->getPath()); + setPathSetting (program, dialog->path()); return true; } diff -r ffd49a28f49e -r 117e4880666e ui/extprogpath.ui --- a/ui/extprogpath.ui Thu Feb 09 20:54:21 2017 +0200 +++ b/ui/extprogpath.ui Thu Feb 09 21:01:12 2017 +0200 @@ -7,7 +7,7 @@ 0 0 444 - 89 + 101 @@ -15,7 +15,7 @@ - + Please input a path for <PROGRAM>: @@ -24,10 +24,10 @@ - + - + ...