summaryrefslogtreecommitdiffstats
path: root/archivemodel.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2014-04-10 16:14:32 +0200
committerArno <am@disconnect.de>2014-04-10 16:14:32 +0200
commitb0d671fede5adfadad2b465fb4c8ae50b40516f3 (patch)
tree0215645b3be6eea7dd11c72c987222eddc0a0faa /archivemodel.cpp
parent9f314ad26720a925e8e7a7f1a9f61330f3fd29c1 (diff)
downloadSheMov-b0d671fede5adfadad2b465fb4c8ae50b40516f3.tar.gz
SheMov-b0d671fede5adfadad2b465fb4c8ae50b40516f3.tar.bz2
SheMov-b0d671fede5adfadad2b465fb4c8ae50b40516f3.zip
Implement Drag and Drop in Movie Archive
Well, this was actually a bit of a drag. You have read the docs very carefully to get it right. For one, don't construct the drag object in mousePressEvent if you also want a double click, otherwise you end up with very weird behavior. Same goes for the receiving end. Differentiate between dragEnterEvent and dragMoveEvent, otherwise you'll only be able to drop items if you hit the right row on entering. There are some artefacts during the drag, but I guess that's a Qt bug. Didn't bother to look into it.
Diffstat (limited to 'archivemodel.cpp')
-rw-r--r--archivemodel.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/archivemodel.cpp b/archivemodel.cpp
index 5369ff7..578ff5c 100644
--- a/archivemodel.cpp
+++ b/archivemodel.cpp
@@ -62,6 +62,19 @@ ArchiveModel::~ArchiveModel(){
}
}
+Qt::ItemFlags ArchiveModel::flags(const QModelIndex &index) const{
+ SmTreeItem *item = itemAt(index);
+ Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
+ if(item->data(Type).toInt() == ArchiveModel::SeriesPartNode){
+ retval |= Qt::ItemIsDropEnabled;
+ }
+ return retval;
+}
+
+Qt::DropActions ArchiveModel::supportedDragActions() const{
+ return Qt::MoveAction;
+}
+
const QStringList ArchiveModel::availableOrders() const {
QStringList retval = mAvailableOrders.keys();
qSort(retval);
@@ -896,7 +909,7 @@ Qt::ItemFlags ArchiveFilesModel::flags(const QModelIndex &index) const{
return Qt::ItemIsEnabled;
}
}
- return SmTreeModel::flags(index);
+ return (Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
}
int ArchiveFilesModel::nextDvd() const{
@@ -982,6 +995,14 @@ QStringList ArchiveFilesModel::filesForSeriespart(int seriesPartId) const{
return retval;
}
+void ArchiveFilesModel::updateSeriesPartForFile(const QString &md5sum, int newSeriesPart){
+ QSqlQuery q(mDb);
+ q.prepare("UPDATE files SET iseriespart_id = :id WHERE cmd5sum = :md5");
+ q.bindValue(":id", newSeriesPart);
+ q.bindValue(":md5", md5sum);
+ q.exec();
+}
+
void ArchiveFilesModel::refresh(){
populate(mSeriesPartIds);
}