summaryrefslogtreecommitdiffstats
path: root/mappingtreewidget.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2012-10-05 12:18:14 +0200
committerArno <am@disconnect.de>2012-10-05 12:18:14 +0200
commita682fc799b99653b67f5bbd8f1bed371bcbe48f1 (patch)
tree32d79631b279296f28f31fe1dc1c36b03962c79c /mappingtreewidget.cpp
parent4d2cc1f62de2e097600212f57ef17d222931bbe5 (diff)
downloadSheMov-a682fc799b99653b67f5bbd8f1bed371bcbe48f1.tar.gz
SheMov-a682fc799b99653b67f5bbd8f1bed371bcbe48f1.tar.bz2
SheMov-a682fc799b99653b67f5bbd8f1bed371bcbe48f1.zip
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...
Diffstat (limited to 'mappingtreewidget.cpp')
-rw-r--r--mappingtreewidget.cpp59
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"));