From a682fc799b99653b67f5bbd8f1bed371bcbe48f1 Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 5 Oct 2012 12:18:14 +0200 Subject: Fixed adding and deleting children from MappingTreeModel Another fix to MappingTreeModel's new database layout. I think we're getting there... Insert the mappings into mapping_parents2 and add the MapParentId to the newly created index in the model. For now, the added date remains invalid. Make it possible (again?) to add root items to MappingTreeModel. For this I had to design a new QDialog with a checkbox. This one fixes another bug in SmTreeModel: Don't call parent() on a null pointer. Sometimes I'm getting random SIGBUS-Signals, but maybe that's because of the debug build of qt I'm using. Couldn't track it down yet... --- mappingtreewidget.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) (limited to 'mappingtreewidget.cpp') diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index 7e62ba3..1897cf1 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -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 &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")); -- cgit v1.2.3-70-g09d2