VersionGuiEntry is now a proper class.

Sun, 07 Jun 2015 19:55:06 +0300

author
Teemu Piippo <tsapii@utu.fi>
date
Sun, 07 Jun 2015 19:55:06 +0300
changeset 54
0b3a5bc4e8a8
parent 53
a5b53cc10436
child 55
cf43a8610b07

VersionGuiEntry is now a proper class.
Release versions are now bolded in the version table.

CMakeLists.txt file | annotate | diff | comparison | revisions
config/addversionprompt.cpp file | annotate | diff | comparison | revisions
config/addversionprompt.h file | annotate | diff | comparison | revisions
config/configwindow.cpp file | annotate | diff | comparison | revisions
config/configwindow.h file | annotate | diff | comparison | revisions
config/versionguientry.cpp file | annotate | diff | comparison | revisions
config/versionguientry.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sun Jun 07 19:15:12 2015 +0300
+++ b/CMakeLists.txt	Sun Jun 07 19:55:06 2015 +0300
@@ -27,6 +27,7 @@
 	config/configwindow.cpp
 	config/addversionprompt.cpp
 	config/main.cpp
+	config/versionguientry.cpp
 )
 
 set (ZCINEMA_HEADERS
@@ -36,6 +37,7 @@
 	commonlib/version.h
 	config/addversionprompt.h
 	config/configwindow.h
+	config/versionguientry.h
 	launcher/demo.h
 	launcher/prompts.h
 )
--- a/config/addversionprompt.cpp	Sun Jun 07 19:15:12 2015 +0300
+++ b/config/addversionprompt.cpp	Sun Jun 07 19:55:06 2015 +0300
@@ -20,6 +20,7 @@
 #include <commonlib/misc.h>
 #include "addversionprompt.h"
 #include "configwindow.h"
+#include "versionguientry.h"
 #include "ui_addversion.h"
 
 //
@@ -36,9 +37,9 @@
 	connect (ui.buttonBox, SIGNAL (rejected()), this, SLOT (reject()));
 	connect (ui.findExeButton, SIGNAL (clicked()), this, SLOT (findExePath()));
 
-	ui.nameField->setText (entry->name);
-	ui.exePathField->setText (entry->pathItem->text());
-	ui.releaseCheckbox->setChecked (entry->isRelease);
+	ui.nameField->setText (entry->name());
+	ui.exePathField->setText (entry->pathItem()->text());
+	ui.releaseCheckbox->setChecked (entry->isRelease());
 }
 
 //
@@ -47,10 +48,9 @@
 
 void AddVersionPrompt::acceptPressed()
 {
-	m_entry->name = ui.nameField->text();
-	m_entry->isRelease = ui.releaseCheckbox->isChecked();
-	m_entry->labelItem->setText (m_entry->name);
-	m_entry->pathItem->setText (ui.exePathField->text());
+	m_entry->setName (ui.nameField->text());
+	m_entry->setRelease (ui.releaseCheckbox->isChecked());
+	m_entry->pathItem()->setText (ui.exePathField->text());
 	accept();
 }
 
--- a/config/addversionprompt.h	Sun Jun 07 19:15:12 2015 +0300
+++ b/config/addversionprompt.h	Sun Jun 07 19:55:06 2015 +0300
@@ -27,9 +27,9 @@
 	Q_OBJECT
 
 public:
-	AddVersionPrompt (struct VersionGuiEntry* entry, QWidget* parent = NULL, Qt::WindowFlags f = 0);
+	AddVersionPrompt (class VersionGuiEntry* entry, QWidget* parent = NULL, Qt::WindowFlags f = 0);
 	virtual ~AddVersionPrompt();
-	VersionGuiEntry* getVersionInfo();
+	class VersionGuiEntry* getVersionInfo();
 
 private slots:
 	void acceptPressed();
@@ -37,5 +37,5 @@
 
 private:
 	class Ui_AddVersion& ui;
-	struct VersionGuiEntry* m_entry;
+	class VersionGuiEntry* m_entry;
 };
\ No newline at end of file
--- a/config/configwindow.cpp	Sun Jun 07 19:15:12 2015 +0300
+++ b/config/configwindow.cpp	Sun Jun 07 19:55:06 2015 +0300
@@ -18,10 +18,12 @@
 
 #include <QFileDialog>
 #include <QMessageBox>
+#include <QLabel>
 #include <commonlib/config.h>
 #include <commonlib/version.h>
 #include "addversionprompt.h"
 #include "configwindow.h"
+#include "versionguientry.h"
 #include "ui_configbox.h"
 
 //
@@ -35,6 +37,16 @@
 }
 
 //
+// -----------------------------------------------------------------------------
+//
+
+void VersionGuiEntry::setName (const QString& a)
+{
+	m_name = a;
+	m_label->setText (a);
+}
+
+//
 // -------------------------------------------------------------------------------------------------
 //
 
@@ -91,20 +103,17 @@
 
 VersionGuiEntry* ConfigWindow::addVersion (const ZandronumVersion& version)
 {
-	QTableWidgetItem* labelItem = new QTableWidgetItem (version.name);
+	QLabel* label = new QLabel (version.name);
+
 	QTableWidgetItem* pathItem = new QTableWidgetItem (version.binaryPath);
 	int rownum = ui.exePaths->rowCount();
 	ui.exePaths->setSortingEnabled (false);
 	ui.exePaths->insertRow (rownum);
-	ui.exePaths->setItem (rownum, LabelColumn, labelItem);
+	ui.exePaths->setCellWidget (rownum, LabelColumn, label);
 	ui.exePaths->setItem (rownum, PathColumn, pathItem);
 	ui.exePaths->setSortingEnabled (true);
 
-	VersionGuiEntry* entry = new VersionGuiEntry;
-	entry->isRelease = version.isRelease;
-	entry->name = version.name;
-	entry->labelItem = labelItem;
-	entry->pathItem = pathItem;
+	VersionGuiEntry* entry = new VersionGuiEntry (version.name, version.isRelease, label, pathItem);
 	m_versionEntries.append (entry);
 	m_versionEntryMap[pathItem] = entry;
 	return entry;
@@ -125,8 +134,8 @@
 		}
 	}
 
-	m_versionEntryMap.remove (entry->pathItem);
-	ui.exePaths->removeRow (entry->pathItem->row());
+	m_versionEntryMap.remove (entry->pathItem());
+	ui.exePaths->removeRow (entry->pathItem()->row());
 	delete entry;
 }
 
@@ -190,7 +199,7 @@
 
 ZandronumVersion VersionGuiEntry::toNonGuiVersion() const
 {
-	return ZandronumVersion (name, isRelease, pathItem->text());
+	return ZandronumVersion (m_name, m_isRelease, m_pathItem->text());
 }
 
 //
--- a/config/configwindow.h	Sun Jun 07 19:15:12 2015 +0300
+++ b/config/configwindow.h	Sun Jun 07 19:55:06 2015 +0300
@@ -23,22 +23,6 @@
 //
 // -------------------------------------------------------------------------------------------------
 //
-// A ZandronumVersion represented in the config window.
-//
-
-struct VersionGuiEntry
-{
-	class QTableWidgetItem* labelItem;
-	class QTableWidgetItem* pathItem;
-	QString name;
-	bool isRelease;
-
-	ZandronumVersion toNonGuiVersion() const;
-};
-
-//
-// -------------------------------------------------------------------------------------------------
-//
 
 class ConfigWindow : public QDialog
 {
@@ -51,7 +35,7 @@
 		PathColumn,
 	};
 
-	typedef QMap<class QTableWidgetItem*, VersionGuiEntry*> VersionEntryMap;
+	typedef QMap<class QTableWidgetItem*, class VersionGuiEntry*> VersionEntryMap;
 
 	ConfigWindow (QWidget* parent = NULL, Qt::WindowFlags f = 0);
 	virtual ~ConfigWindow();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/versionguientry.cpp	Sun Jun 07 19:55:06 2015 +0300
@@ -0,0 +1,72 @@
+#include <QLabel>
+#include <QTableWidget>
+#include "versionguientry.h"
+
+//
+// -----------------------------------------------------------------------------
+//
+
+VersionGuiEntry::VersionGuiEntry (const QString& name, bool isRelease,
+	QLabel* label, QTableWidgetItem* pathItem)
+	: m_name (name),
+	  m_isRelease (isRelease),
+	  m_label (label),
+	  m_pathItem (pathItem)
+{
+	updateStyleSheet();
+}
+
+//
+// -----------------------------------------------------------------------------
+//
+
+void VersionGuiEntry::setRelease (bool a)
+{
+	m_isRelease = a;
+	updateStyleSheet();
+}
+
+//
+// -----------------------------------------------------------------------------
+//
+
+void VersionGuiEntry::updateStyleSheet()
+{
+	m_label->setStyleSheet (m_isRelease ? "font-weight: bold" : "");
+}
+
+//
+// -----------------------------------------------------------------------------
+//
+
+class QLabel* VersionGuiEntry::label()
+{
+	return m_label;
+}
+
+//
+// -----------------------------------------------------------------------------
+//
+
+class QTableWidgetItem* VersionGuiEntry::pathItem()
+{
+	return m_pathItem;
+}
+
+//
+// -----------------------------------------------------------------------------
+//
+
+const QString& VersionGuiEntry::name()
+{
+	return m_name;
+}
+
+//
+// -----------------------------------------------------------------------------
+//
+
+bool VersionGuiEntry::isRelease()
+{
+	return m_isRelease;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/versionguientry.h	Sun Jun 07 19:55:06 2015 +0300
@@ -0,0 +1,33 @@
+#pragma once
+
+class QString;
+class QLabel;
+class QTableWidgetItem;
+struct ZandronumVersion;
+
+//
+// -------------------------------------------------------------------------------------------------
+//
+// A ZandronumVersion represented in the config window.
+//
+
+class VersionGuiEntry
+{
+public:
+	VersionGuiEntry (const QString& name, bool isRelease,
+					 QLabel* label, QTableWidgetItem* pathItem);
+	ZandronumVersion toNonGuiVersion() const;
+	QLabel* label();
+	QTableWidgetItem* pathItem();
+	const QString& name();
+	void updateStyleSheet();
+	bool isRelease();
+	void setRelease (bool a);
+	void setName (const QString& a);
+
+private:
+	QLabel* m_label;
+	QTableWidgetItem* m_pathItem;
+	QString m_name;
+	bool m_isRelease;
+};
\ No newline at end of file

mercurial