summaryrefslogtreecommitdiffstats
path: root/mappingtreemodel.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 /mappingtreemodel.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 'mappingtreemodel.cpp')
-rw-r--r--mappingtreemodel.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp
index 1babac1..eed686b 100644
--- a/mappingtreemodel.cpp
+++ b/mappingtreemodel.cpp
@@ -38,7 +38,7 @@ MappingTreeModel::MappingTreeModel(QStringList &headers, QObject *parent) : SmTr
mSelectChildQ = new QSqlQuery(mDb);
mSelectChildQ->prepare("SELECT imapping_id, tmapping_name, tscreated FROM mappings WHERE tmapping_name = :name AND imapping_type = :type");
mAddParentQ = new QSqlQuery(mDb);
- mAddParentQ->prepare("INSERT INTO mappings_parents (imapping_id, iparent_id) VALUES(:id, :parentid)");
+ mAddParentQ->prepare("INSERT INTO mappings_parents2 (imapping_id, iparent_id) VALUES(:id, :parentid)");
mDeleteChildQ = new QSqlQuery(mDb);
mDeleteChildQ->prepare("DELETE FROM mappings WHERE imapping_id = :id");
mUpdateParentQ = new QSqlQuery(mDb);
@@ -301,18 +301,30 @@ bool MappingTreeModel::addChild(const QVariant &name, const QModelIndex &parent)
id = addChild(name.toString(), mType);
}
//now check if we already have a mapping with the same parent
+ mDb.transaction();
mAddParentQ->bindValue(":id", id);
- mAddParentQ->bindValue(":parentid", parent.data(IdRole));
+ // seems we're a child of root
+ QVariant ppId = parent.data(IdRole).isValid() ? parent.data(IdRole) : -1;
+ mAddParentQ->bindValue(":parentid", ppId);
if(!mAddParentQ->exec()){
+ mLastError = mAddParentQ->lastError();
+ mDb.rollback();
return false;
}
//we're good now... db makes sure we're unique
SmTreeItem *pItem = itemAt(parent);
int where = lowerBound(pItem, name, Name);
if(insertRows(where, 1, parent)){
+ QSqlQuery pIdQuery = QSqlQuery("SELECT currval('mappings_parents_id__seq')", mDb);
+ int parentId = -1;
+ while(pIdQuery.next()){
+ parentId = pIdQuery.value(0).toInt();
+ }
QModelIndex newIdx = index(where, 0, parent);
setData(newIdx, name, NameRole);
setData(newIdx, id, IdRole);
+ setData(newIdx, parentId, MapParentIdRole);
+ mDb.commit();
return true;
}
return false;