summaryrefslogtreecommitdiffstats
path: root/archivemodel.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2013-06-23 03:27:31 +0200
committerArno <am@disconnect.de>2013-06-23 03:27:31 +0200
commit5dbcc16c289d7067132d133b374a9b7dcd2c7fd2 (patch)
treeb4ed1bb2720ff5d999ed7148d6855d6844e01cc9 /archivemodel.cpp
parent77b6cc27c7c2a97b0759332cdfa382d4b32b8749 (diff)
downloadSheMov-5dbcc16c289d7067132d133b374a9b7dcd2c7fd2.tar.gz
SheMov-5dbcc16c289d7067132d133b374a9b7dcd2c7fd2.tar.bz2
SheMov-5dbcc16c289d7067132d133b374a9b7dcd2c7fd2.zip
Fix renaming items, protect colletor-vars with Mutexes
This should be 2 commits, really... Fix: write cache after renaming an item Protect: protect the accessors of ArchiveCollector with Mutexes
Diffstat (limited to 'archivemodel.cpp')
-rw-r--r--archivemodel.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/archivemodel.cpp b/archivemodel.cpp
index c169b4d..a5d2298 100644
--- a/archivemodel.cpp
+++ b/archivemodel.cpp
@@ -9,6 +9,7 @@
#include <QSqlQuery>
#include <QFile>
#include <QSettings>
+#include <QMutexLocker>
#include "smtreeitem.h"
#include "archivemodel.h"
@@ -70,6 +71,10 @@ bool ArchiveModel::setData(const QModelIndex &idx, const QVariant &value, int ro
if(role != Qt::EditRole){
return false;
}
+ // any other column is invisible, hence...
+ if(idx.column() != Name){
+ return false;
+ }
SmTreeItem *item = itemAt(idx);
int nodeType = item->data(Type).toInt();
QSqlQuery updateQuery(mDb);
@@ -86,15 +91,14 @@ bool ArchiveModel::setData(const QModelIndex &idx, const QVariant &value, int ro
updateQuery.bindValue(":value", value);
updateQuery.bindValue(":id", id);
if(updateQuery.exec()){
- if(nodeType == GenreNode || nodeType == ActorNode){
- item->setData(Name, value);
- emit dataChanged(idx, idx);
- return true;
- }else if(nodeType == SeriesNode){
- item->setData(Name, value);
+ item->setData(Name, value);
+ emit dataChanged(idx, idx);
+ if(nodeType == SeriesNode){
emit needRefresh();
return true;
}
+ writeCache(mOrder);
+ return true;
}else{
emitDatabaseError(updateQuery.lastError());
}
@@ -333,7 +337,18 @@ ArchiveCollector::ArchiveCollector(int numFields, QObject *parent) : QThread(par
mDb.open();
}
+SmTreeItem *ArchiveCollector::rootItem() {
+ QMutexLocker l(&mAccessMx);
+ return mRootItem;
+}
+
+int ArchiveCollector::sortOrder() {
+ QMutexLocker l(&mAccessMx);
+ return mSortOrder;
+}
+
void ArchiveCollector::populate(int order, SmTreeItem *rootItem){
+ QMutexLocker l(&mAccessMx);
mRootItem = rootItem;
mSortOrder = order;
}