# # # add_file "res/forms/add_edit_variables.ui" # content [e50545a1c61e521b37947cd7169633cc57ba8011] # # add_file "src/model/GetDatabaseVariables.cpp" # content [27cff9e65510e7ce06ec131bee552b2bb236cf6d] # # add_file "src/model/GetDatabaseVariables.h" # content [12358ebfe7da2c6b5bf4d2c28264af387f2f3abc] # # add_file "src/view/dialogs/AddEditDatabaseVariable.cpp" # content [43725bf2f27c81706fe506cbe6a5afd805b2fad2] # # add_file "src/view/dialogs/AddEditDatabaseVariable.h" # content [c400f76015a0bb7fe7c9da0d78e38450c5cc4516] # # patch "guitone.pro" # from [a84bcaf4e5e125fed275b7d70c4d8dc030108c58] # to [3cb7e974e3fa7a3d1967203e0cb9dfb17f1b9a15] # # patch "res/forms/add_edit_attribute.ui" # from [82503020fbedbad0c1879c82e4203aaed9db637a] # to [8503e2456746463e8fc6533c2f3a3a836ce19535] # # patch "res/forms/db_variables.ui" # from [a6fa8671e9b38ce67507fe3fc41ec353425ce531] # to [411a1a308272e830c0ba00967eaff03be8b6023e] # # patch "src/view/DatabaseWindow.cpp" # from [279b0a3ffef1b844f50247b8cfce08770c010910] # to [913fc1e9136f88341115e9d902f8572e9105c00b] # # patch "src/view/DatabaseWindow.h" # from [619c1ab06edb685d2db3381db9ea5bb31481c546] # to [aea7b282e9aa43a7d82f2fd9ead8e094a4f56621] # # patch "src/view/WorkspaceWindow.cpp" # from [48a6117f48cccebabbcd7f580cc0be2e3ada05ac] # to [a23cfb2e04ee1dfa0b4a9198bd9ffb124d893ad1] # # patch "src/view/WorkspaceWindow.h" # from [909f16bd3e598b6f786389c29c115dc64bfd0848] # to [cdb9e70c4d3328d8d963a488efc13c307026843f] # # patch "src/view/dialogs/DatabaseDialogManager.h" # from [0634ee9c6523ae5cf8df8ff7b3a6efa38163dde1] # to [39dfe4f5d0a25022399e0eaf7fa45319ff84ab9c] # # patch "src/view/dialogs/WorkspaceDialogManager.h" # from [abc57b99c46faa051f70c870431e300b2edc4a70] # to [a1782d5d0c84feb1fda2ea9ca6dcebba4da27a90] # # patch "src/view/panels/DatabaseVariables.cpp" # from [f6a69a4a3cdb36396813204fc5c9e2601ad909cf] # to [e14ae08795371b4605f0bd1ad95bf5b0cd13fa1c] # # patch "src/view/panels/DatabaseVariables.h" # from [e86e4bb48f04db7f59a9c2927f89d36d3c234321] # to [e391c11ecb671270ceb1b3e5064186b94b984491] # ============================================================ --- res/forms/add_edit_variables.ui e50545a1c61e521b37947cd7169633cc57ba8011 +++ res/forms/add_edit_variables.ui e50545a1c61e521b37947cd7169633cc57ba8011 @@ -0,0 +1,128 @@ + + AddEditDatabaseVariable + + + + 0 + 0 + 393 + 135 + + + + Add / edit a database variable + + + :/icons/guitone.png + + + + + + + + + + Domain + + + + + + + Key + + + + + + + Value + + + + + + + + + + + true + + + + + + + true + + + + + + + + 0 + 0 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + false + + + + + + + + + + + buttonBox + rejected() + AddEditDatabaseVariable + reject() + + + 271 + 109 + + + 236 + 122 + + + + + buttonBox + accepted() + AddEditDatabaseVariable + accept() + + + 353 + 107 + + + 379 + 127 + + + + + ============================================================ --- src/model/GetDatabaseVariables.cpp 27cff9e65510e7ce06ec131bee552b2bb236cf6d +++ src/model/GetDatabaseVariables.cpp 27cff9e65510e7ce06ec131bee552b2bb236cf6d @@ -0,0 +1,224 @@ +/*************************************************************************** + * Copyright (C) 2006 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#include "GetDatabaseVariables.h" +#include "BasicIOParser.h" +#include "MonotoneUtil.h" + +GetDatabaseVariables::GetDatabaseVariables(QObject * parent) + : QAbstractItemModel(parent), AutomateCommand(0) +{} + +GetDatabaseVariables::~GetDatabaseVariables() {} + +void GetDatabaseVariables::setDatabaseFile(const DatabaseFile & db) +{ + databaseFile = db; +} + +void GetDatabaseVariables::readVariables() +{ + I(!databaseFile.isEmpty()); + MonotoneTask task(QStringList() << "get_db_variables"); + AutomateCommand::enqueueDatabaseTask(databaseFile, task); +} + +void GetDatabaseVariables::processTaskResult(const MonotoneTask & task) +{ + if (task.getReturnCode() != 0) + { + C(QString("Command returned with a non-zero return code (%1)") + .arg(task.getOutputUtf8())); + return; + } + + reset(); + variables.clear(); + + BasicIOParser parser(task.getOutputUtf8()); + I(parser.parse()); + StanzaList list = parser.getStanzas(); + + for (int i=0, size = list.size(); i < size; ++i) + { + Stanza stanza = list.at(i); + + QString domain; + QList > entries; + + for (int j=0, size2 = stanza.size(); j < size2; j++) + { + StanzaEntry entry = stanza.at(j); + + if (entry.sym == "domain") + { + domain = entry.vals.at(0); + continue; + } + + if (entry.sym == "entry") + { + I(entry.vals.size() == 2); + entries.push_back( + QPair(entry.vals.at(0), entry.vals.at(1)) + ); + continue; + } + + W(QString("Unknown symbol %1.").arg(entry.sym)); + } + + I(!domain.isEmpty()); + I(entries.size() > 0); + variables.insert(domain, entries); + } + + reset(); + emit variablesRead(); +} + +int GetDatabaseVariables::columnCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return 2; +} + +QVariant GetDatabaseVariables::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) + { + return QVariant(); + } + + if (role != Qt::DisplayRole) + { + return QVariant(); + } + + int row = index.row(); + + QStringList keys = variables.keys(); + + if (!index.parent().isValid()) + { + I(row < keys.size()); + return QVariant(keys.at(row)); + } + + int parentRow = index.internalId(); + I(parentRow < keys.size()); + QString domain = keys.at(parentRow); + QPair entry = variables.value(domain).at(row); + + switch (index.column()) + { + case 0: return QVariant(entry.first); + case 1: return QVariant(entry.second); + } + + return QVariant(); +} + +Qt::ItemFlags GetDatabaseVariables::flags(const QModelIndex & index) const +{ + if (index.isValid() && index.parent().isValid()) + { + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + } + return Qt::ItemIsEnabled; +} + +QVariant GetDatabaseVariables::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + switch (section) + { + case 0: return QVariant(tr("Domain / Key")); + case 1: return QVariant(tr("Value")); + } + } + return QVariant(); +} + +int GetDatabaseVariables::rowCount(const QModelIndex & parent) const +{ + QStringList keys = variables.keys(); + + if (parent.isValid()) + { + if (parent.internalId() == -1) + { + int row = parent.row(); + I(row < keys.size()); + return variables.value(keys.at(row)).size(); + } + // an entry node + return 0; + } + + return keys.size(); +} + +QModelIndex GetDatabaseVariables::index(int row, int column, const QModelIndex & parent) const +{ + if (!hasIndex(row, column, parent)) + { + return QModelIndex(); + } + + if (parent.isValid()) + { + QStringList keys = variables.keys(); + int parentRow = parent.row(); + I(parentRow < keys.size()); + return createIndex(row, column, parentRow); + } + return createIndex(row, column, -1); +} + +QModelIndex GetDatabaseVariables::parent(const QModelIndex & index) const +{ + if (!index.isValid() || index.internalId() == -1) + { + return QModelIndex(); + } + + int row = index.internalId(); + return createIndex(row, 0, -1); +} + + +bool GetDatabaseVariables::setVariable(const QString & domain, const QString & key, const QString & value) +{ + MonotoneTask out = MonotoneUtil::runSynchronousDatabaseTask( + databaseFile, + MonotoneTask(QStringList() << "set_db_variable" << domain << key << value) + ); + return out.getReturnCode() == 0; +} + +bool GetDatabaseVariables::dropVariable(const QString & domain, const QString & key) +{ + MonotoneTask out = MonotoneUtil::runSynchronousDatabaseTask( + databaseFile, + MonotoneTask(QStringList() << "drop_db_variables" << domain << key) + ); + return out.getReturnCode() == 0; +} + ============================================================ --- src/model/GetDatabaseVariables.h 12358ebfe7da2c6b5bf4d2c28264af387f2f3abc +++ src/model/GetDatabaseVariables.h 12358ebfe7da2c6b5bf4d2c28264af387f2f3abc @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2008 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#ifndef GET_DATABASE_VARIABLES_H +#define GET_DATABASE_VARIABLES_H + +#include "AutomateCommand.h" + +#include + +class GetDatabaseVariables : public QAbstractItemModel, public AutomateCommand +{ + Q_OBJECT +public: + GetDatabaseVariables(QObject *); + virtual ~GetDatabaseVariables(); + + // needed Qt Model methods + QVariant data(const QModelIndex &, int) const; + Qt::ItemFlags flags(const QModelIndex &) const; + QVariant headerData(int, Qt::Orientation, int) const; + QModelIndex index(int, int, const QModelIndex &) const; + QModelIndex parent(const QModelIndex &) const; + int rowCount(const QModelIndex &) const; + int columnCount(const QModelIndex &) const; + + bool setVariable(const QString &, const QString &, const QString &); + bool dropVariable(const QString &, const QString &); + +public slots: + void setDatabaseFile(const DatabaseFile &); + void readVariables(); + +signals: + void variablesRead(); + +private: + void processTaskResult(const MonotoneTask &); + DatabaseFile databaseFile; + // technically we could rewrite the QList> as QMap<...>, + // but this structure would be harder to serve the model methods + QMap > > variables; +}; + +#endif + ============================================================ --- src/view/dialogs/AddEditDatabaseVariable.cpp 43725bf2f27c81706fe506cbe6a5afd805b2fad2 +++ src/view/dialogs/AddEditDatabaseVariable.cpp 43725bf2f27c81706fe506cbe6a5afd805b2fad2 @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (C) 2008 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#include "AddEditDatabaseVariable.h" + +AddEditDatabaseVariable::AddEditDatabaseVariable( + QWidget * parent, const QString & domain, + const QString & key, const QString & value) + : Dialog(parent) +{ + setupUi(this); + Dialog::init(); + + connect( + varDomain, SIGNAL(currentIndexChanged(const QString &)), + this, SLOT(updatePossibleKeys(const QString &)) + ); + + QStringList domains; + domains << "database" << "known-servers"; + varDomain->addItems(domains); + + int domPos = varDomain->findText(domain); + if (domPos == -1) + { + varDomain->insertItem(0, domain); + domPos = 0; + } + varDomain->setCurrentIndex(domPos); + + int keyPos = varKey->findText(key); + if (keyPos == -1) + { + varKey->insertItem(0, key); + keyPos = 0; + } + varKey->setCurrentIndex(keyPos); + + varValue->setText(value); +} + +AddEditDatabaseVariable::~AddEditDatabaseVariable() {} + +void AddEditDatabaseVariable::updatePossibleKeys(const QString & domain) +{ + varKey->clear(); + + QStringList keys; + + if (domain == "database") + { + keys << "default-exclude-pattern" + << "default-include-pattern" + << "default-server"; + } + + varKey->addItems(keys); +} + ============================================================ --- src/view/dialogs/AddEditDatabaseVariable.h c400f76015a0bb7fe7c9da0d78e38450c5cc4516 +++ src/view/dialogs/AddEditDatabaseVariable.h c400f76015a0bb7fe7c9da0d78e38450c5cc4516 @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2008 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#ifndef ADDEDITVARIABLE_H +#define ADDEDITVARIABLE_H + +#include "ui_add_edit_variables.h" +#include "Dialog.h" +#include "vocab.h" + +class AddEditDatabaseVariable : public Dialog, private Ui::AddEditDatabaseVariable +{ + Q_OBJECT + +public: + AddEditDatabaseVariable(QWidget *, const QString & domain = QString(), + const QString & key = QString(), const QString & value = QString()); + ~AddEditDatabaseVariable(); + + QString getDomain() const { return varDomain->currentText(); } + QString getKey() const { return varKey->currentText(); } + QString getValue() const { return varValue->text(); } + +private slots: + void updatePossibleKeys(const QString &); +}; + +#endif + ============================================================ --- guitone.pro a84bcaf4e5e125fed275b7d70c4d8dc030108c58 +++ guitone.pro 3cb7e974e3fa7a3d1967203e0cb9dfb17f1b9a15 @@ -53,6 +53,7 @@ HEADERS = src/view/TreeView.h \ src/view/dialogs/UnaccountedRenames.h \ src/view/dialogs/AddEditAttribute.h \ src/view/dialogs/OpenPrompt.h \ + src/view/dialogs/AddEditDatabaseVariable.h \ src/view/panels/IconHelp.h \ src/view/panels/DatabaseVariables.h \ src/monotone/FileExporter.h \ @@ -81,6 +82,7 @@ HEADERS = src/view/TreeView.h \ src/model/GetBranchLog.h \ src/model/GetRevision.h \ src/model/GetContentChanged.h \ + src/model/GetDatabaseVariables.h \ src/util/IconProvider.h \ src/util/AbstractParser.h \ src/util/BasicIOParser.h \ @@ -125,6 +127,7 @@ SOURCES += src/view/TreeView.cpp \ src/view/dialogs/UnaccountedRenames.cpp \ src/view/dialogs/AddEditAttribute.cpp \ src/view/dialogs/OpenPrompt.cpp \ + src/view/dialogs/AddEditDatabaseVariable.cpp \ src/view/panels/IconHelp.cpp \ src/view/panels/DatabaseVariables.cpp \ src/monotone/FileExporter.cpp \ @@ -153,6 +156,7 @@ SOURCES += src/view/TreeView.cpp \ src/model/GetBranchLog.cpp \ src/model/GetRevision.cpp \ src/model/GetContentChanged.cpp \ + src/model/GetDatabaseVariables.cpp \ src/util/IconProvider.cpp \ src/util/AbstractParser.cpp \ src/util/BasicIOParser.cpp \ @@ -185,7 +189,8 @@ FORMS += res/forms/select_revision.ui res/forms/add_edit_attribute.ui \ res/forms/open_prompt.ui \ res/forms/icon_help.ui \ - res/forms/db_variables.ui + res/forms/db_variables.ui \ + res/forms/add_edit_variables.ui UI_DIR = tmp OBJECTS_DIR = tmp ============================================================ --- res/forms/add_edit_attribute.ui 82503020fbedbad0c1879c82e4203aaed9db637a +++ res/forms/add_edit_attribute.ui 8503e2456746463e8fc6533c2f3a3a836ce19535 @@ -16,36 +16,57 @@ :/icons/guitone.png - - 9 - - - 6 - - + + 6 + + 0 - - 6 + + 0 + + 0 + + + 0 + - + + 6 + + 0 - - 6 + + 0 + + 0 + + + 0 + - + + 6 + + 0 - - 6 + + 0 + + 0 + + + 0 + @@ -64,12 +85,21 @@ - + + 6 + + 0 - - 6 + + 0 + + 0 + + + 0 + @@ -80,9 +110,7 @@ - - 3 - 0 + 0 0 ============================================================ --- res/forms/db_variables.ui a6fa8671e9b38ce67507fe3fc41ec353425ce531 +++ res/forms/db_variables.ui 411a1a308272e830c0ba00967eaff03be8b6023e @@ -5,8 +5,8 @@ 0 0 - 457 - 212 + 456 + 253 @@ -23,8 +23,46 @@ - + + + + + + + + + + + + + + + - + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Update + + + + + ============================================================ --- src/view/DatabaseWindow.cpp 279b0a3ffef1b844f50247b8cfce08770c010910 +++ src/view/DatabaseWindow.cpp 913fc1e9136f88341115e9d902f8572e9105c00b @@ -55,6 +55,11 @@ void DatabaseWindow::init() if (!dialogManager) { dialogManager = new DatabaseDialogManager(this); + + connect( + this, SIGNAL(databaseSelected(const DatabaseFile &)), + dialogManager, SLOT(init(const DatabaseFile &)) + ); } connect( @@ -79,6 +84,11 @@ void DatabaseWindow::init() databaseVariables = new DatabaseVariables(this); + connect( + this, SIGNAL(databaseSelected(const DatabaseFile &)), + databaseVariables, SLOT(setDatabaseFile(const DatabaseFile &)) + ); + dynamic_cast(menuBar) ->addDockWidgetAction(databaseVariables->toggleViewAction()); @@ -141,9 +151,6 @@ void DatabaseWindow::load(const QString databaseFile = path; - // initialize the dialog manager - reinterpret_cast(dialogManager)->init(path); - loadedDbLabel->setText(path); QFileInfo fi(path); @@ -152,5 +159,7 @@ void DatabaseWindow::load(const QString ); Settings::addItemToList("RecentDatabaseList", path, 5); + + emit databaseSelected(databaseFile); } ============================================================ --- src/view/DatabaseWindow.h 619c1ab06edb685d2db3381db9ea5bb31481c546 +++ src/view/DatabaseWindow.h aea7b282e9aa43a7d82f2fd9ead8e094a4f56621 @@ -37,6 +37,9 @@ public: //! throws GuitoneException virtual void load(const QString &); +signals: + void databaseSelected(const DatabaseFile &); + protected: DatabaseFile databaseFile; ============================================================ --- src/view/WorkspaceWindow.cpp 48a6117f48cccebabbcd7f580cc0be2e3ada05ac +++ src/view/WorkspaceWindow.cpp a23cfb2e04ee1dfa0b4a9198bd9ffb124d893ad1 @@ -70,6 +70,11 @@ void WorkspaceWindow::init() if (!dialogManager) { dialogManager = new WorkspaceDialogManager(this); + + connect( + this, SIGNAL(workspaceSelected(const WorkspacePath &)), + dialogManager, SLOT(init(const WorkspacePath &)) + ); } connect( @@ -190,7 +195,17 @@ void WorkspaceWindow::setup() // models invModel = new Inventory(this); + connect( + this, SIGNAL(workspaceSelected(const WorkspacePath &)), + invModel, SLOT(setWorkspacePath(const WorkspacePath &)) + ); + attrModel = new GetAttributes(this); + connect( + this, SIGNAL(workspaceSelected(const WorkspacePath &)), + attrModel, SLOT(setWorkspacePath(const WorkspacePath &)) + ); + proxyModelFolderTree = new InventoryProxyModel(this, true); proxyModelFileList = new InventoryProxyModel(this, false); @@ -251,21 +266,15 @@ void WorkspaceWindow::load(const QString workspacePath = MonotoneManager::normalizeWorkspacePath(path); APP->manager()->getThreadForWorkspace(workspacePath); - invModel->setWorkspacePath(workspacePath); - attrModel->setWorkspacePath(workspacePath); - - // read the base set of the inventory - invModel->refresh(); - - // initialize the dialog manager - reinterpret_cast(dialogManager)->init(workspacePath); - setWindowTitle( tr("%1 - workspace mode - guitone"). arg(MonotoneUtil::getBranchNameShort(workspacePath)) ); Settings::addItemToList("RecentWorkspaceList", workspacePath, 5); + + emit workspaceSelected(workspacePath); + emit databaseSelected(APP->manager()->getDatabaseFilePath(workspacePath)); } void WorkspaceWindow::openFile(const QString & filePath) ============================================================ --- src/view/WorkspaceWindow.h 909f16bd3e598b6f786389c29c115dc64bfd0848 +++ src/view/WorkspaceWindow.h cdb9e70c4d3328d8d963a488efc13c307026843f @@ -44,6 +44,9 @@ public: //! throws GuitoneException virtual void load(const QString &); +signals: + void workspaceSelected(const WorkspacePath &); + protected: WorkspacePath workspacePath; ============================================================ --- src/view/dialogs/DatabaseDialogManager.h 0634ee9c6523ae5cf8df8ff7b3a6efa38163dde1 +++ src/view/dialogs/DatabaseDialogManager.h 39dfe4f5d0a25022399e0eaf7fa45319ff84ab9c @@ -37,13 +37,12 @@ public: DatabaseDialogManager(QWidget *); ~DatabaseDialogManager(); - void init(const DatabaseFile &); - //! delegated signals signals: void revisionCheckedOut(const QString &); public slots: + void init(const DatabaseFile &); void showChangesetBrowser(); void showCheckoutRevision(); virtual void showFileDiff(const QString &, const QString &, const QString &); ============================================================ --- src/view/dialogs/WorkspaceDialogManager.h abc57b99c46faa051f70c870431e300b2edc4a70 +++ src/view/dialogs/WorkspaceDialogManager.h a1782d5d0c84feb1fda2ea9ca6dcebba4da27a90 @@ -34,13 +34,12 @@ public: WorkspaceDialogManager(QWidget *); ~WorkspaceDialogManager(); - void init(const WorkspacePath &); - //! delegated signals signals: void revisionCommitted(const QString &); public slots: + void init(const WorkspacePath &); void showCommitRevision(); void showCommitRevision(const QStringList &); void showUnaccountedRenames(const QMap &); ============================================================ --- src/view/panels/DatabaseVariables.cpp f6a69a4a3cdb36396813204fc5c9e2601ad909cf +++ src/view/panels/DatabaseVariables.cpp e14ae08795371b4605f0bd1ad95bf5b0cd13fa1c @@ -17,16 +17,153 @@ ***************************************************************************/ #include "DatabaseVariables.h" +#include "AddEditDatabaseVariable.h" -DatabaseVariables::DatabaseVariables(QWidget * parent) : QDockWidget(parent) +#include + +DatabaseVariables::DatabaseVariables(QWidget * parent) + : QDockWidget(parent) { QWidget * parentWidget = new QWidget(this); setupUi(parentWidget); setWidget(parentWidget); + databaseVariables = new GetDatabaseVariables(this); + variableTree->setModel(databaseVariables); + + connect( + databaseVariables, SIGNAL(variablesRead()), + this, SLOT(variablesRead()) + ); + + connect( + updateVariables, SIGNAL(clicked()), + databaseVariables, SLOT(readVariables()) + ); + + connect( + addVariable, SIGNAL(clicked()), + this, SLOT(openVariableEditor()) + ); + + connect( + removeVariable, SIGNAL(clicked()), + this, SLOT(removeCurrentVariable()) + ); + + connect( + variableTree, SIGNAL(doubleClicked(const QModelIndex &)), + this, SLOT(variableDoubleClicked(const QModelIndex &)) + ); + setWindowTitle(tr("Database variables")); setAllowedAreas(Qt::BottomDockWidgetArea); } -DatabaseVariables::~DatabaseVariables() {} +DatabaseVariables::~DatabaseVariables() +{ + delete databaseVariables; +} +void DatabaseVariables::setDatabaseFile(const DatabaseFile & db) +{ + databaseVariables->setDatabaseFile(db); + databaseVariables->readVariables(); +} + +/** + * This is an ugly hack because Qt does not figure out column spanning + * itself when columnCount() returns different values for this tree view + */ +void DatabaseVariables::variablesRead() +{ + QModelIndex parent; + + int count = databaseVariables->rowCount(parent); + for (int row=0; rowsetFirstColumnSpanned(row, parent, true); + } + + variableTree->expandAll(); +} + +void DatabaseVariables::variableDoubleClicked(const QModelIndex & index) +{ + if (!index.isValid() || !index.parent().isValid()) return; + + QString domain, key, value; + + domain = index.parent().data().toString(); + + if (index.column() == 0) + { + key = index.data().toString(); + value = index.sibling(index.row(), 1).data().toString(); + } + else + if (index.column() == 1) + { + value = index.data().toString(); + key = index.sibling(index.row(), 0).data().toString(); + } + else + I(false); + + openVariableEditor(domain, key, value); +} + +void DatabaseVariables::openVariableEditor(const QString & domain, + const QString & key, + const QString & value) +{ + AddEditDatabaseVariable dlg(this, domain, key, value); + + if (dlg.exec() == QDialog::Accepted) + { + if (!databaseVariables->setVariable(dlg.getDomain(), dlg.getKey(), dlg.getValue())) + { + C("could not store new database variable"); + } + databaseVariables->readVariables(); + } +} + +void DatabaseVariables::removeCurrentVariable() +{ + QModelIndex index = variableTree->currentIndex(); + + if (!index.isValid() || !index.parent().isValid()) return; + + QString domain, key; + + domain = index.parent().data().toString(); + + if (index.column() == 0) + { + key = index.data().toString(); + } + else + if (index.column() == 1) + { + key = index.sibling(index.row(), 0).data().toString(); + } + else + I(false); + + QMessageBox msgBox(this); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setWindowTitle(tr("Attention")); + msgBox.setText(tr("Are you sure you want to remove the " + "variable '%1' from the domain '%2'?").arg(key).arg(domain)); + + if (msgBox.exec() == QMessageBox::Yes) + { + if (!databaseVariables->dropVariable(domain, key)) + { + C("could not remove database variable"); + } + databaseVariables->readVariables(); + } +} + ============================================================ --- src/view/panels/DatabaseVariables.h e86e4bb48f04db7f59a9c2927f89d36d3c234321 +++ src/view/panels/DatabaseVariables.h e391c11ecb671270ceb1b3e5064186b94b984491 @@ -22,6 +22,7 @@ #include #include "ui_db_variables.h" +#include "GetDatabaseVariables.h" class DatabaseVariables : public QDockWidget, private Ui::DatabaseVariables { @@ -29,6 +30,20 @@ public: public: DatabaseVariables(QWidget *); ~DatabaseVariables(); + +public slots: + void setDatabaseFile(const DatabaseFile &); + +private slots: + void variablesRead(); + void openVariableEditor(const QString & domain = QString(), + const QString & key = QString(), + const QString & value= QString()); + void variableDoubleClicked(const QModelIndex &); + void removeCurrentVariable(); + +private: + GetDatabaseVariables * databaseVariables; }; #endif