summaryrefslogtreecommitdiffstats
path: root/archivemodel.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2013-07-13 06:42:57 +0200
committerArno <am@disconnect.de>2013-07-13 06:42:57 +0200
commit057da448ad06de20b8054ae1ba5ed7f6fb656c1b (patch)
treec410672b3ebe17536fe0e8a8fd9abc8e9c9c3e5e /archivemodel.cpp
parente8edacfc5175e91d27d6fcba8e3ffa1b1c80754c (diff)
downloadSheMov-057da448ad06de20b8054ae1ba5ed7f6fb656c1b.tar.gz
SheMov-057da448ad06de20b8054ae1ba5ed7f6fb656c1b.tar.bz2
SheMov-057da448ad06de20b8054ae1ba5ed7f6fb656c1b.zip
Make all NodeTypes editable
Use plpgsql functions to edit nodes. Makes the program logic much easier. Also, rename rename() to edit() :)
Diffstat (limited to 'archivemodel.cpp')
-rw-r--r--archivemodel.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/archivemodel.cpp b/archivemodel.cpp
index cbca042..59d1e74 100644
--- a/archivemodel.cpp
+++ b/archivemodel.cpp
@@ -112,18 +112,20 @@ bool ArchiveModel::setData(const QModelIndex &idx, const QVariant &value, int ro
}
SmTreeItem *item = itemAt(idx);
int nodeType = item->data(Type).toInt();
- // handle duplicate key error!!!
+ QVariant id = item->data(GenericId);
QSqlQuery updateQuery(mDb);
if(nodeType == GenreNode){
- updateQuery.prepare("UPDATE genres SET tgenrename = :value WHERE igenres_id = :id");
+ updateQuery.prepare("SELECT update_genres(:value, :id)");
}else if(nodeType == ActorNode){
- updateQuery.prepare("UPDATE actors SET tactorname = :value WHERE iactors_id = :id");
+ updateQuery.prepare("SELECT update_actors(:value, :id)");
}else if(nodeType == SeriesNode){
- updateQuery.prepare("UPDATE series SET tseries_name = :value WHERE iseries_id = :id");
+ updateQuery.prepare("SELECT update_series(:value, :id)");
+ }else if(nodeType == SeriesPartNode){
+ updateQuery.prepare("SELECT move_to_series(:value, :id)");
+ id = item->data(SeriesPartId);
}else{
return false;
}
- QVariant id = item->data(GenericId);
updateQuery.bindValue(":value", value);
updateQuery.bindValue(":id", id);
mDb.transaction();
@@ -131,12 +133,10 @@ bool ArchiveModel::setData(const QModelIndex &idx, const QVariant &value, int ro
mDb.commit();
item->setData(Name, value);
emit dataChanged(idx, idx);
- if(nodeType == SeriesNode){
- emit needRefresh();
- return true;
- }
+ emit needRefresh();
writeCache(mOrder, root());
}else{
+ // cannot happen!
mDb.rollback();
emitDatabaseError(updateQuery.lastError());
}