# HG changeset patch # User Teemu Piippo # Date 1378659371 -10800 # Node ID 256bb5c6b77fa777fdd357ce1e3e42c0769f136e # Parent 61e2752dd7cd8632795b66311e31305be011ffc0 Added a version data editor diff -r 61e2752dd7cd -r 256bb5c6b77f src/config.cpp --- 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 diff -r 61e2752dd7cd -r 256bb5c6b77f src/config.h --- 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 m_zanBinaries; + list m_binaryLayoutWidgets; QFormLayout* m_releaseLayout, * m_testLayout; diff -r 61e2752dd7cd -r 256bb5c6b77f src/misc.cpp --- 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 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 diff -r 61e2752dd7cd -r 256bb5c6b77f src/misc.h --- 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 getVersions(); diff -r 61e2752dd7cd -r 256bb5c6b77f src/ui/addversion.ui --- /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 @@ + + + AddVersion + + + + 0 + 0 + 400 + 149 + + + + Add Zandronum Version + + + + + + <b>Add a Zandronum Version</b> + + + + + + + + + Name: + + + + + + + + + + Path to Binary: + + + + + + + + + + + + ... + + + + + + + + + Release + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AddVersion + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AddVersion + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff -r 61e2752dd7cd -r 256bb5c6b77f src/ui/configbox.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 @@ 0 0 516 - 220 + 225 - + + + + + + + Edit Versions + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -168,13 +192,37 @@ 0 0 516 - 220 + 225 - + + + + + + + Edit Versions + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff -r 61e2752dd7cd -r 256bb5c6b77f src/ui/versionEditor.ui --- /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 @@ + + + VersionEditor + + + + 0 + 0 + 577 + 450 + + + + Edit Zandronum Versions + + + + :/icons/zandemo.ico:/icons/zandemo.ico + + + + + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + + true + + + false + + + + Version + + + + + Release + + + + + Binary Path + + + + + + + + + + Add... + + + + + + + false + + + Edit... + + + + + + + false + + + Remove + + + + + + + Clear + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + m_buttonBox + accepted() + VersionEditor + accept() + + + 248 + 254 + + + 157 + 274 + + + + + m_buttonBox + rejected() + VersionEditor + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff -r 61e2752dd7cd -r 256bb5c6b77f src/versionEditor.cpp --- /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 (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 diff -r 61e2752dd7cd -r 256bb5c6b77f src/versionEditor.h --- /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 +#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