Sun, 08 Sep 2013 19:56:11 +0300
Added a version data editor
src/config.cpp | file | annotate | diff | comparison | revisions | |
src/config.h | file | annotate | diff | comparison | revisions | |
src/misc.cpp | file | annotate | diff | comparison | revisions | |
src/misc.h | file | annotate | diff | comparison | revisions | |
src/ui/addversion.ui | file | annotate | diff | comparison | revisions | |
src/ui/configbox.ui | file | annotate | diff | comparison | revisions | |
src/ui/versionEditor.ui | file | annotate | diff | comparison | revisions | |
src/versionEditor.cpp | file | annotate | diff | comparison | revisions | |
src/versionEditor.h | file | annotate | diff | comparison | revisions |
--- a/src/config.cpp Sun Sep 08 17:44:58 2013 +0300 +++ b/src/config.cpp Sun Sep 08 19:56:11 2013 +0300 @@ -26,6 +26,7 @@ #include "misc.h" #include "demo.h" #include "build/moc_config.cpp" +#include "versionEditor.h" CONFIG (Bool, noprompt, false) CONFIG (List, devBuildNames, cfg::List()) @@ -56,7 +57,9 @@ // ----------------------------------------------------------------------------- ConfigBox::ConfigBox (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f), - ui (new Ui_ConfigBox) + ui (new Ui_ConfigBox), + m_releaseLayout (null), + m_testLayout (null) { ui->setupUi (this); @@ -69,6 +72,8 @@ connect (ui->wad_del, SIGNAL (clicked()), this, SLOT (delPath())); connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)), this, SLOT (buttonPressed (QAbstractButton*))); + connect (ui->m_editVersions, SIGNAL (clicked()), this, SLOT (editBinaries())); + connect (ui->m_editVersions_2, SIGNAL (clicked()), this, SLOT (editBinaries())); setWindowTitle (fmt (APPNAME " %1", versionString())); } @@ -81,8 +86,20 @@ // ============================================================================= // ----------------------------------------------------------------------------- void ConfigBox::initVersions() { - m_releaseLayout = new QFormLayout (ui->zandronumVersions); - m_testLayout = new QFormLayout (ui->betaVersions); + if (m_releaseLayout == null) { + m_releaseLayout = new QFormLayout; + m_testLayout = new QFormLayout; + ui->zandronumVersions->setLayout (m_releaseLayout); + ui->betaVersions->setLayout (m_testLayout); + } else { + // re-init, clear the layouts + QLayoutItem* item; + for (QWidget* w : m_binaryLayoutWidgets) + delete w; + + m_binaryLayoutWidgets.clear(); + m_zanBinaries.clear(); + } for (const QVariant& ver : cfg::devBuildNames) addVersion (ver.toString(), false); @@ -111,6 +128,8 @@ m_releaseLayout->addRow (lb, wdg); else m_testLayout->addRow (lb, wdg); + + m_binaryLayoutWidgets << ledit << btn << wdg << lb; } // ============================================================================= @@ -218,4 +237,15 @@ reject(); elif (btn == ui->buttonBox->button (QDialogButtonBox::Apply)) saveSettings(); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void ConfigBox::editBinaries() { + VersionEditor* dlg = new VersionEditor (this); + + if (dlg->exec()) { + dlg->saveChanges(); + initVersions(); + } } \ No newline at end of file
--- a/src/config.h Sun Sep 08 17:44:58 2013 +0300 +++ b/src/config.h Sun Sep 08 19:56:11 2013 +0300 @@ -50,11 +50,13 @@ void findPath(); void delPath(); void findZanBinary(); + void editBinaries(); void buttonPressed (QAbstractButton* btn); private: Ui_ConfigBox* ui; list<QLineEdit*> m_zanBinaries; + list<QWidget*> m_binaryLayoutWidgets; QFormLayout* m_releaseLayout, * m_testLayout;
--- a/src/misc.cpp Sun Sep 08 17:44:58 2013 +0300 +++ b/src/misc.cpp Sun Sep 08 19:56:11 2013 +0300 @@ -17,6 +17,7 @@ */ #include "misc.h" +#include <QMessageBox> EXTERN_CONFIG (List, devBuildNames) EXTERN_CONFIG (List, releaseNames) @@ -60,4 +61,11 @@ return path.mid (lastpos + 1); return path; +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +bool confirm (str text) { + return QMessageBox::question (null, QObject::tr ("Confirm"), text, + QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::No; } \ No newline at end of file
--- a/src/misc.h Sun Sep 08 17:44:58 2013 +0300 +++ b/src/misc.h Sun Sep 08 19:56:11 2013 +0300 @@ -25,6 +25,7 @@ str binaryConfigName (str ver); str basename (str path); void addVersion (str name, bool isRelease, str binaryPath); +bool confirm (str text); QList<QVariant> getVersions();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ui/addversion.ui Sun Sep 08 19:56:11 2013 +0300 @@ -0,0 +1,113 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>AddVersion</class> + <widget class="QDialog" name="AddVersion"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>149</height> + </rect> + </property> + <property name="windowTitle"> + <string>Add Zandronum Version</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string><b>Add a Zandronum Version</b></string> + </property> + </widget> + </item> + <item> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Name:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="m_binaryName"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Path to Binary:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLineEdit" name="m_binaryPath"/> + </item> + <item> + <widget class="QPushButton" name="m_findBinary"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="2" column="1"> + <widget class="QCheckBox" name="m_release"> + <property name="text"> + <string>Release</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>AddVersion</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>AddVersion</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui>
--- a/src/ui/configbox.ui Sun Sep 08 17:44:58 2013 +0300 +++ b/src/ui/configbox.ui Sun Sep 08 19:56:11 2013 +0300 @@ -136,13 +136,37 @@ <x>0</x> <y>0</y> <width>516</width> - <height>220</height> + <height>225</height> </rect> </property> - <layout class="QVBoxLayout" name="verticalLayout_5"> + <layout class="QVBoxLayout" name="verticalLayout_5" stretch="1,0"> <item> <widget class="QWidget" name="zandronumVersions" native="true"/> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QPushButton" name="m_editVersions"> + <property name="text"> + <string>Edit Versions</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> </layout> </widget> </widget> @@ -168,13 +192,37 @@ <x>0</x> <y>0</y> <width>516</width> - <height>220</height> + <height>225</height> </rect> </property> - <layout class="QVBoxLayout" name="verticalLayout_8"> + <layout class="QVBoxLayout" name="verticalLayout_8" stretch="1,0"> <item> <widget class="QWidget" name="betaVersions" native="true"/> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QPushButton" name="m_editVersions_2"> + <property name="text"> + <string>Edit Versions</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> </layout> </widget> </widget>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ui/versionEditor.ui Sun Sep 08 19:56:11 2013 +0300 @@ -0,0 +1,159 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>VersionEditor</class> + <widget class="QDialog" name="VersionEditor"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>577</width> + <height>450</height> + </rect> + </property> + <property name="windowTitle"> + <string>Edit Zandronum Versions</string> + </property> + <property name="windowIcon"> + <iconset resource="../../zandemo.qrc"> + <normaloff>:/icons/zandemo.ico</normaloff>:/icons/zandemo.ico</iconset> + </property> + <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QTableWidget" name="m_versions"> + <property name="selectionMode"> + <enum>QAbstractItemView::SingleSelection</enum> + </property> + <property name="selectionBehavior"> + <enum>QAbstractItemView::SelectRows</enum> + </property> + <property name="sortingEnabled"> + <bool>true</bool> + </property> + <attribute name="horizontalHeaderStretchLastSection"> + <bool>true</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + <column> + <property name="text"> + <string>Version</string> + </property> + </column> + <column> + <property name="text"> + <string>Release</string> + </property> + </column> + <column> + <property name="text"> + <string>Binary Path</string> + </property> + </column> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QPushButton" name="m_add"> + <property name="text"> + <string>Add...</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="m_edit"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Edit...</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="m_remove"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Remove</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="m_clear"> + <property name="text"> + <string>Clear</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </item> + <item> + <widget class="QDialogButtonBox" name="m_buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources> + <include location="../../zandemo.qrc"/> + </resources> + <connections> + <connection> + <sender>m_buttonBox</sender> + <signal>accepted()</signal> + <receiver>VersionEditor</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>m_buttonBox</sender> + <signal>rejected()</signal> + <receiver>VersionEditor</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/versionEditor.cpp Sun Sep 08 19:56:11 2013 +0300 @@ -0,0 +1,225 @@ +#include "versionEditor.h" +#include "ui_versionEditor.h" +#include "ui_addversion.h" +#include "config.h" +#include "misc.h" +#include "build/moc_versionEditor.cpp" + +EXTERN_CONFIG (Map, binaryPaths) +EXTERN_CONFIG (List, devBuildNames) +EXTERN_CONFIG (List, releaseNames) + +// ============================================================================= +// ----------------------------------------------------------------------------- +VersionEditor::VersionEditor (QWidget* parent, Qt::WindowFlags f) : + QDialog (parent, f), + m_ui (new Ui_VersionEditor) +{ + m_ui->setupUi (this); + + connect (m_ui->m_versions, SIGNAL (currentCellChanged (int, int, int, int)), + this, SLOT (selectionChanged (int))); + + connect (m_ui->m_add, SIGNAL (clicked (bool)), this, SLOT (add())); + connect (m_ui->m_edit, SIGNAL (clicked (bool)), this, SLOT (edit())); + connect (m_ui->m_remove, SIGNAL (clicked (bool)), this, SLOT (remove())); + connect (m_ui->m_clear, SIGNAL (clicked (bool)), this, SLOT (clear())); + + initVersions(); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +VersionEditor::~VersionEditor() { + delete m_ui; +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void VersionEditor::initVersions() { + int i = 0; + + for (const QVariant& ver : (cfg::releaseNames + cfg::devBuildNames)) { + bool isRelease = (i < cfg::releaseNames.size()); + addVersion (ver.toString(), cfg::binaryPaths[ver.toString()].toString(), isRelease); + + ++i; + } +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void VersionEditor::add() { + AddVersionPrompt* dlg = new AddVersionPrompt (this); + if (!dlg->exec()) + return; + + addVersion (dlg->name(), dlg->path(), dlg->release()); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void VersionEditor::edit() { + QTableWidget* const vers = m_ui->m_versions; + int row = vers->currentRow(); + + if (row < 0) + return; + + AddVersionPrompt* dlg = new AddVersionPrompt (this); + dlg->setName (vers->item (row, NameColumn)->text()); + dlg->setPath (vers->item (row, PathColumn)->text()); + dlg->setRelease (getReleaseCheckbox(row)->isChecked()); + + if (!dlg->exec()) + return; + + addVersion (dlg->name(), dlg->path(), dlg->release()); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void VersionEditor::remove() { + QTableWidget* const vers = m_ui->m_versions; + + str name = vers->item (vers->currentRow(), NameColumn)->text(); + if (!confirm (fmt (tr ("Really remove version %1?"), name))) + return; + + vers->removeRow (vers->currentRow()); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void VersionEditor::clear() { + if (!confirm (tr ("Really remove all versions?"))) + return; + + m_ui->m_versions->clear(); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void VersionEditor::addVersion (str name, str path, bool isRelease) { + QTableWidget* const vers = m_ui->m_versions; + + int row = vers->rowCount(); + vers->insertRow (row); + vers->setItem (row, NameColumn, new QTableWidgetItem); + vers->setItem (row, PathColumn, new QTableWidgetItem); + vers->item (row, NameColumn)->setText (name); + vers->item (row, PathColumn)->setText (path); + + QCheckBox* cb = new QCheckBox; + cb->setChecked (isRelease); + vers->setCellWidget (row, ReleaseColumn, cb); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void VersionEditor::saveChanges() { + QTableWidget* const vers = m_ui->m_versions; + + cfg::devBuildNames.clear(); + cfg::releaseNames.clear(); + cfg::binaryPaths.clear(); + + for (int i = 0; i < vers->rowCount(); ++i) { + const QCheckBox* cb = getReleaseCheckbox (i); + bool isRelease = cb->isChecked(); + const str name = vers->item (i, NameColumn)->text(), + path = vers->item (i, PathColumn)->text(); + + if (isRelease) + cfg::releaseNames << QVariant (name); + else + cfg::devBuildNames << QVariant (name); + + cfg::binaryPaths[name] = path; + } + + cfg::save(); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void VersionEditor::selectionChanged (int row) { + bool ok = (row != -1); + m_ui->m_edit->setEnabled (ok); + m_ui->m_remove->setEnabled (ok); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +QCheckBox* VersionEditor::getReleaseCheckbox (int i) { + return static_cast<QCheckBox*> (m_ui->m_versions->cellWidget (i, ReleaseColumn)); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +AddVersionPrompt::AddVersionPrompt (QWidget* parent, Qt::WindowFlags f) : + QDialog (parent, f), + m_ui (new Ui_AddVersion) +{ + m_ui->setupUi (this); + connect (m_ui->m_binaryName, SIGNAL (textChanged (QString)), this, SLOT (fieldsChanged())); + connect (m_ui->m_binaryPath, SIGNAL (textChanged (QString)), this, SLOT (fieldsChanged())); + connect (m_ui->m_findBinary, SIGNAL (clicked (bool)), this, SLOT (findPath())); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +AddVersionPrompt::~AddVersionPrompt() { + delete m_ui; +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void AddVersionPrompt::findPath() { + str path = ConfigBox::getBinaryPath (this); + if (!path.isEmpty()) + m_ui->m_binaryPath->setText (path); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +str AddVersionPrompt::name() { + return m_ui->m_binaryName->text(); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +str AddVersionPrompt::path() { + return m_ui->m_binaryPath->text(); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +bool AddVersionPrompt::release() { + return m_ui->m_release->isChecked(); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void AddVersionPrompt::setName (const str& a) { + m_ui->m_binaryName->setText (a); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void AddVersionPrompt::setPath (const str& a) { + m_ui->m_binaryPath->setText (a); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void AddVersionPrompt::setRelease (bool a) { + m_ui->m_release->setChecked (a); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void AddVersionPrompt::fieldsChanged() { + bool ok = (!m_ui->m_binaryName->text().isEmpty()) && (!m_ui->m_binaryPath->text().isEmpty()); + m_ui->buttonBox->button (QDialogButtonBox::Ok)->setEnabled (ok); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/versionEditor.h Sun Sep 08 19:56:11 2013 +0300 @@ -0,0 +1,63 @@ +#ifndef ZANDEMO_VERSIONEDITOR_H +#define ZANDEMO_VERSIONEDITOR_H + +#include <QDialog> +#include "types.h" + +class QCheckBox; +class Ui_VersionEditor; +class Ui_AddVersion; + +class VersionEditor : public QDialog { + Q_OBJECT + +public: + enum { + NameColumn, + ReleaseColumn, + PathColumn + }; + + explicit VersionEditor (QWidget* parent = 0, Qt::WindowFlags f = 0); + virtual ~VersionEditor(); + +public slots: + void add(); + void edit(); + void remove(); + void clear(); + void saveChanges(); + void selectionChanged (int row); + +private: + Ui_VersionEditor* m_ui; + + void initVersions(); + void addVersion (str name, str path, bool isRelease); + QCheckBox* getReleaseCheckbox (int i); +}; + +class AddVersionPrompt : public QDialog { + Q_OBJECT + +public: + explicit AddVersionPrompt (QWidget* parent = 0, Qt::WindowFlags f = 0); + virtual ~AddVersionPrompt(); + +public: + str name(); + str path(); + bool release(); + void setName (const str& a); + void setPath (const str& a); + void setRelease (bool a); + +public slots: + void findPath(); + void fieldsChanged(); + +private: + Ui_AddVersion* m_ui; +}; + +#endif // ZANDEMO_VERSIONEDITOR_H \ No newline at end of file