diff options
Diffstat (limited to 'mappingtreewidget.cpp')
-rw-r--r-- | mappingtreewidget.cpp | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index 7e62ba3..1897cf1 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -12,6 +12,8 @@ #include <QVBoxLayout> #include <QHBoxLayout> #include <QInputDialog> +#include <QCheckBox> +#include <QLabel> #include <QStringListModel> #include <QMessageBox> #include <QSettings> @@ -103,8 +105,12 @@ MappingData MappingTreeWidget::selectedItem() const { } void MappingTreeWidget::addChild(){ - QModelIndex sel = selected(); - QString value = QInputDialog::getText(this, tr("Mapping name"), tr("Enter mapping name")); + MappingInputDialog dlg(this); + int retval = dlg.exec(); + if(retval != QDialog::Accepted){ + return; + } + QString value = dlg.mappingName(); if(value.isEmpty()){ return; } @@ -113,8 +119,16 @@ void MappingTreeWidget::addChild(){ QMessageBox::critical(this, tr("Error"), msg); return; } - QModelIndex real = mProxy->mapToSource(sel); - mModel->addChild(value, real); + QModelIndex sel = selected(); + QModelIndex parent = mModel->rootIndex(); + if(!dlg.createRoot()){ + QModelIndex sel = selected(); + parent = mProxy->mapToSource(sel); + } + if(!mModel->addChild(value, parent)){ + QString err = QString(tr("Error: Database said: %1")).arg(mModel->lastError().text()); + QMessageBox::critical(this, tr("Error"), err); + } } void MappingTreeWidget::addType(){ @@ -311,6 +325,43 @@ void MappingEditWidget::setMappings(const QList<MappingData> &mappings){ mMappingResult->expandAll(); } +MappingInputDialog::MappingInputDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ + mOk = new QPushButton(tr("Ok")); + connect(mOk, SIGNAL(clicked()), this, SLOT(accept())); + mCancel = new QPushButton(tr("Cancel")); + connect(mCancel, SIGNAL(clicked()), this, SLOT(reject())); + mIsRoot = new QCheckBox(tr("Create root item")); + mEditor = new QLineEdit; + + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addStretch(); + buttonLayout->addWidget(mOk); + buttonLayout->addWidget(mCancel); + + QVBoxLayout* inputLayout = new QVBoxLayout; + QLabel *caption = new QLabel(tr("Enter mapping name")); + inputLayout->addWidget(caption); + inputLayout->addWidget(mEditor); + + QHBoxLayout *cbLayout = new QHBoxLayout; + cbLayout->addStretch(); + cbLayout->addWidget(mIsRoot); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(inputLayout); + mainLayout->addLayout(cbLayout); + mainLayout->addLayout(buttonLayout); + setLayout(mainLayout); +} + +QString MappingInputDialog::mappingName() const{ + return mEditor->text(); +} + +bool MappingInputDialog::createRoot() const { + return mIsRoot->checkState() == Qt::Checked; +} + MappingEditDialog::MappingEditDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ mEditWidget = new MappingEditWidget; mOk = new QPushButton(tr("Ok")); |