summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2012-11-17 05:14:56 +0100
committerArno <am@disconnect.de>2012-11-17 05:14:56 +0100
commit2defc44300bd18917e6e5e2327ebb72f951ff7b1 (patch)
tree0f8e622deb1ae29d36113fe49a1758e5164278ae
parent23692f9a516c21676829275c82b415957fc2dec3 (diff)
downloadSheMov-2defc44300bd18917e6e5e2327ebb72f951ff7b1.tar.gz
SheMov-2defc44300bd18917e6e5e2327ebb72f951ff7b1.tar.bz2
SheMov-2defc44300bd18917e6e5e2327ebb72f951ff7b1.zip
Finally { fix MappingTreeModel }!!!
I think I did it! Fixed MappingTreeModel to make it usable, avoid all the traps with the insane column and variable names! Now we can actually have the same mapping with different parents! Yay! Hope it won't come back and bite me!
-rw-r--r--mappingtreemodel.cpp23
-rw-r--r--mappingtreemodel.h3
-rw-r--r--mappingtreewidget.cpp2
-rw-r--r--picfilesmodel.cpp7
4 files changed, 14 insertions, 21 deletions
diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp
index ddfd5e2..cf8bfc0 100644
--- a/mappingtreemodel.cpp
+++ b/mappingtreemodel.cpp
@@ -219,7 +219,7 @@ bool MappingTreeModel::setData(const QModelIndex &index, const QVariant &value,
}
bool MappingTreeModel::move(const QModelIndex &source, const QModelIndex &dest){
- QVariant sourceId = source.data(DescIdRole);
+ QVariant sourceId = source.data(MappingIdRole);
QVariant destId = dest.data(MappingIdRole);
mDb.transaction();
mUpdateParentQ->bindValue(":id", destId);
@@ -295,7 +295,7 @@ bool MappingTreeModel::deleteChild(const QModelIndex &idx){
if(item->childCount() > 0){
return false;
}
- mDeleteMappingParentQ->bindValue(":id", item->data(DescId));
+ mDeleteMappingParentQ->bindValue(":id", item->data(MappingId));
if(mDeleteMappingParentQ->exec()){
removeRows(idx.row(), 1, idx.parent());
return true;
@@ -311,7 +311,7 @@ MappingData MappingTreeModel::mappingDataFromIndex(QModelIndex &idx) const{
}
retval.mappingId = idx.data(MappingTreeModel::MappingIdRole).toInt();
retval.parentId = idx.data(MappingTreeModel::MappingParentIdRole).toInt();
- retval.myId = idx.data(MappingTreeModel::DescIdRole).toInt();
+ retval.descId = idx.data(MappingTreeModel::DescIdRole).toInt();
retval.name = idx.data(MappingTreeModel::NameRole).toString();
retval.path << path(idx);
return retval;
@@ -336,10 +336,10 @@ void MappingTreeModel::populate(){
SmTreeItem *rootItem = new SmTreeItem(NumFields);
rootItem->setData(DescId, -1);
rootItem->setData(MappingId, -1);
- mSeen.clear();
+ rootItem->setData(MappingParentId, -1);
while(rootQ.next()){
QList<QVariant> childData;
- childData << rootQ.value(2) << rootQ.value(1) << rootQ.value(3) << rootQ.value(0) << rootQ.value(4);
+ childData << rootQ.value(2) << rootQ.value(0) << rootQ.value(3) << rootQ.value(1) << rootQ.value(4);
SmTreeItem *childItem = new SmTreeItem(childData, rootItem);
rootItem->appendChild(childItem);
getChildrenRecursive(childItem);
@@ -398,7 +398,6 @@ void MappingTreeModel::getMappingTypes(){
}
void MappingTreeModel::getChildrenRecursive(SmTreeItem *item){
- //static QList<QVariant> seenIds;
QSqlQuery cq(mDb);
cq.prepare(mSParentsQ);
cq.bindValue(":type", mType);
@@ -406,11 +405,7 @@ void MappingTreeModel::getChildrenRecursive(SmTreeItem *item){
if(cq.exec()){
while(cq.next()){
QList<QVariant> childData;
- childData << cq.value(2) << cq.value(1) << cq.value(3) << cq.value(0) << cq.value(4);
- if(mSeen.contains(childData.at((DescId)))){
- return;
- }
- mSeen << childData.at(DescId);
+ childData << cq.value(2) << cq.value(0) << cq.value(3) << cq.value(1) << cq.value(4);
SmTreeItem *child = new SmTreeItem(childData, item);
item->appendChild(child);
getChildrenRecursive(child);
@@ -518,7 +513,7 @@ void MappingTreeResultModel::addItem(const MappingData &data){
if(i == p.count() - 1){
mappingId = data.mappingId;
parentId = data.parentId;
- myId = data.myId;
+ myId = data.descId;
}
QModelIndex curIdx = insertChild(p.at(i), mappingId, parentId, myId, curItem);
curItem = itemAt(curIdx);
@@ -580,8 +575,8 @@ QList<QVariant> MappingTreeResultModel::columnValuesRecursive(SmTreeItem *parent
return retval;
}
-MappingData::MappingData() : mappingId(-1), parentId(-1), myId(-1) {}
+MappingData::MappingData() : mappingId(-1), parentId(-1), descId(-1) {}
bool MappingData::isValid(){
- return !(mappingId == -1 && parentId == -1 && myId == -1);
+ return !(mappingId == -1 && parentId == -1 && descId == -1);
}
diff --git a/mappingtreemodel.h b/mappingtreemodel.h
index ad4ff85..90eca8c 100644
--- a/mappingtreemodel.h
+++ b/mappingtreemodel.h
@@ -90,7 +90,6 @@ class MappingTreeModel : public SmTreeModel {
const QString mForbidden;
int mType;
QSqlError mLastError;
- QList<QVariant> mSeen;
};
class MappingTreeResultModel : public SmTreeModel {
@@ -121,7 +120,7 @@ struct MappingData {
bool isValid();
int mappingId;
int parentId;
- int myId;
+ int descId;
QString name;
QList<QStringList> path;
};
diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp
index 0881e3c..4cde673 100644
--- a/mappingtreewidget.cpp
+++ b/mappingtreewidget.cpp
@@ -227,7 +227,7 @@ void MappingTreeWidget::editChild(){
void MappingTreeWidget::selectionChanged(){
QModelIndex sel = selected();
QModelIndex real = mProxy->mapToSource(sel);
- emit mappingChanged(real.data(MappingTreeModel::DescIdRole).toInt());
+ emit mappingChanged(real.data(MappingTreeModel::MappingIdRole).toInt());
}
void MappingTreeWidget::moveChild(){
diff --git a/picfilesmodel.cpp b/picfilesmodel.cpp
index 4114eb5..6b8153f 100644
--- a/picfilesmodel.cpp
+++ b/picfilesmodel.cpp
@@ -40,7 +40,7 @@ PicFilesModel::~PicFilesModel(){
}
void PicFilesModel::setMapping(int pMapId){
- QList<QVariant> ids = mMappingTreeModel->childList(pMapId, MappingTreeModel::DescId);
+ QList<QVariant> ids = mMappingTreeModel->childList(pMapId, MappingTreeModel::MappingId);
mMappingIds.clear();
foreach(QVariant i, ids){
mMappingIds << i.toInt();
@@ -170,13 +170,12 @@ QList<MappingData> PicFilesModel::mappingDataFromFiles(const QList<int> fileIds)
}
QList<MappingData> retval;
foreach(int pId, parentIds){
- QModelIndex curIdx = mMappingTreeModel->findRecursive(pId, MappingTreeModel::DescId, mMappingTreeModel->rootIndex());
+ QModelIndex curIdx = mMappingTreeModel->findRecursive(pId, MappingTreeModel::MappingId, mMappingTreeModel->rootIndex());
MappingData curData;
- //curData.id = curIdx.data(MappingTreeModel::MyIdRole).toInt();
curData.mappingId = curIdx.data(MappingTreeModel::MappingIdRole).toInt();
curData.parentId = curIdx.data(MappingTreeModel::MappingParentIdRole).toInt();
curData.name = curIdx.data(MappingTreeModel::NameRole).toString();
- curData.path << mMappingTreeModel->path(curIdx); //.join("/");
+ curData.path << mMappingTreeModel->path(curIdx);
retval << curData;
}
return retval;