Cleaned up ExternalProgramPathDialog

Thu, 09 Feb 2017 21:01:12 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 09 Feb 2017 21:01:12 +0200
changeset 1115
117e4880666e
parent 1114
ffd49a28f49e
child 1116
3b1d2cc6603e

Cleaned up ExternalProgramPathDialog

src/dialogs.cpp file | annotate | diff | comparison | revisions
src/dialogs.h file | annotate | diff | comparison | revisions
src/dialogs/configdialog.cpp file | annotate | diff | comparison | revisions
src/dialogs/configdialog.h file | annotate | diff | comparison | revisions
src/toolsets/extprogramtoolset.cpp file | annotate | diff | comparison | revisions
ui/extprogpath.ui file | annotate | diff | comparison | revisions
--- 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 <QFileDialog>
 #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 ("<PROGRAM>", 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("<PROGRAM>", 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();
 }
--- 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 <QDialog>
 #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;
 };
--- 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;
--- 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<QListWidgetItem*> quickColorItems;
--- 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;
 	}
 
--- 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 @@
     <x>0</x>
     <y>0</y>
     <width>444</width>
-    <height>89</height>
+    <height>101</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -15,7 +15,7 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <widget class="QLabel" name="m_label">
+    <widget class="QLabel" name="programLabel">
      <property name="text">
       <string>Please input a path for &lt;PROGRAM&gt;:</string>
      </property>
@@ -24,10 +24,10 @@
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout">
      <item>
-      <widget class="QLineEdit" name="m_path"/>
+      <widget class="QLineEdit" name="path"/>
      </item>
      <item>
-      <widget class="QPushButton" name="m_findPath">
+      <widget class="QPushButton" name="findPathButton">
        <property name="text">
         <string>...</string>
        </property>

mercurial