summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2012-10-10 18:28:45 +0200
committerArno <am@disconnect.de>2012-10-10 18:28:45 +0200
commitdab3f05dcb2975c07247e3bebd8e9a7e8b9e83ce (patch)
tree70ee72f169620d5a6b07b7c116a0455183f6ef26
parentd562d4a3527044aaeb36534bc2d4b65b587c9bb3 (diff)
downloadSheMov-dab3f05dcb2975c07247e3bebd8e9a7e8b9e83ce.tar.gz
SheMov-dab3f05dcb2975c07247e3bebd8e9a7e8b9e83ce.tar.bz2
SheMov-dab3f05dcb2975c07247e3bebd8e9a7e8b9e83ce.zip
SeriesTreeModel fix
* make it possible to delete whole series again. No code fix, just the database layout: add on delete cascade to metadata * get rid of propertiesdialog.{cpp,h}. It was useless and called from the "Edit.." context menu. Code bloat, I guess... * Do something useful when calling "Edit...". Rename Series or ask for a new SeriesPart
-rw-r--r--propertiesdialog.cpp142
-rw-r--r--propertiesdialog.h51
-rw-r--r--seriestreewidget.cpp38
-rw-r--r--seriestreewidget.h2
-rw-r--r--shemov.cpp6
-rw-r--r--shemov.h1
-rw-r--r--shemov.pro2
7 files changed, 17 insertions, 225 deletions
diff --git a/propertiesdialog.cpp b/propertiesdialog.cpp
deleted file mode 100644
index 2068cdf..0000000
--- a/propertiesdialog.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version
- 2 of the License, or (at your option) any later version.
-*/
-
-#include <QSqlDatabase>
-#include <QSqlQuery>
-#include <QLabel>
-#include <QHBoxLayout>
-#include <QVBoxLayout>
-#include <QSplitter>
-#include <QTreeView>
-#include <QTabWidget>
-#include <QPushButton>
-#include <QScrollArea>
-
-#include "propertiesdialog.h"
-#include "smtreemodel.h"
-#include "smtreeitem.h"
-#include "filestreemodel.h"
-#include "seriestreemodel.h"
-#include "smglobals.h"
-
-PropertiesDialog::PropertiesDialog(QWidget *parent, Qt::WindowFlags f) : SmDialog(parent, f), mCurrentId(-1) {
- //init model
- const QStringList headers = QStringList() << "Name" << "Id" << "NodeType";
- mDisplayModel = new SmTreeModel(headers, this);
- mFilesModel = static_cast<FilesTreeModel*>(SmGlobals::instance()->model("FilesModel"));
- mSeriesModel = static_cast<SeriesTreeModel*>(SmGlobals::instance()->model("SeriesModel"));
- setupGui();
-}
-
-PropertiesDialog::~PropertiesDialog() {}
-
-void PropertiesDialog::populate(int seriesPartId){
- //prepare items
- mCurrentId = seriesPartId;
- SmTreeItem *root = new SmTreeItem(3);
- SmTreeItem *movieDummy = new SmTreeItem(QList<QVariant>() << "Movies" << -1 << DummyNode, root);
- root->appendChild(movieDummy);
- SmTreeItem *pictureDummy = new SmTreeItem(QList<QVariant>() << "Covers" << -1 << DummyNode, root);
- root->appendChild(pictureDummy);
-
- //populate model
- QSqlDatabase db = QSqlDatabase::database("treedb");
- QSqlQuery filesQuery(db);
- filesQuery.prepare("SELECT tfilename, ifiles_id, sifiletype FROM files WHERE iseriespart_id = :id");
- filesQuery.bindValue(":id", mCurrentId);
- if(filesQuery.exec()){
- while(filesQuery.next()){
- QList<QVariant> data;
- data << filesQuery.value(0) << filesQuery.value(1);
- if(filesQuery.value(2).toInt() == FilesTreeModel::Movie){
- data << MovieFileNode;
- SmTreeItem *dataItem = new SmTreeItem(data, movieDummy);
- movieDummy->appendChild(dataItem);
- }else{
- data << PictureFileNode;
- SmTreeItem *dataItem = new SmTreeItem(data, pictureDummy);
- pictureDummy->appendChild(dataItem);
- }
- }
- }
- mDisplayModel->setRoot(root);
-
- //setup caption
- QModelIndex seriesIdx = mSeriesModel->findRecursive(seriesPartId, SeriesTreeModel::SeriesPartId, mSeriesModel->rootIndex());
- Q_ASSERT(seriesIdx.isValid());
- QString captionString = QString(tr("Properties for %1")).arg(mSeriesModel->index(seriesIdx.row(), SeriesTreeModel::Name, seriesIdx.parent()).data().toString());
- mCaption->setText(captionString);
-
- //make it usable
- mFileView->expandAll();
- mFileView->setColumnHidden(1, true);
- mFileView->setColumnHidden(2, true);
- mFileView->resizeColumnToContents(0);
-}
-
-void PropertiesDialog::showPicture(QModelIndex current, QModelIndex previous){
- Q_UNUSED(previous);
- QModelIndex fileIdIdx = mDisplayModel->index(current.row(), 1, current.parent());
- int fileId = fileIdIdx.data().toInt();
- QModelIndex nodeTypeIdx = mDisplayModel->index(current.row(), 2, current.parent());
- int nodeType = nodeTypeIdx.data().toInt();
- if(nodeType == MovieFileNode){
- QPixmap pic = SmGlobals::instance()->frameCache()->entry(current.data().toString());
- mPictureLabel->setPixmap(pic);
- }else if(nodeType == PictureFileNode){
- QModelIndex fileIdx = mFilesModel->findRecursive(fileId, FilesTreeModel::FilesId, mFilesModel->rootIndex());
- if(fileIdx.isValid()){
- QString fullPath = fileIdx.data(FilesTreeModel::FullPathRole).toString();
- mPictureLabel->setPixmap(fullPath);
- }
- }
-}
-
-void PropertiesDialog::setupGui(){
- //white caption
- QVBoxLayout *mainLayout = new QVBoxLayout;
- QString topStyleSheet = QString("QFrame#caption { background-color: white; border: 1px solid black; font-weight: bold; padding-left: 10px; padding-top: 4px; padding-bottom: 4px;}");
- mCaption = new QLabel;
- mCaption->setFrameShape(QFrame::StyledPanel);
- mCaption->setObjectName("caption");
- mCaption->setStyleSheet(topStyleSheet);
- mainLayout->addWidget(mCaption);
-
- //data
- QSplitter *mSplitter = new QSplitter;
- mTab = new QTabWidget;
- mFileView = new QTreeView;
- mFileView->setModel(mDisplayModel);
- mFileView->setSelectionBehavior(QAbstractItemView::SelectRows);
- mFileView->setSelectionMode(QAbstractItemView::SingleSelection);
- connect(mFileView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(showPicture(QModelIndex,QModelIndex)));
- mSplitter->addWidget(mFileView);
- mPicTab = new QWidget;
- QScrollArea *picScroll = new QScrollArea;
- mPictureLabel = new QLabel;
- //mPictureLabel->setScaledContents(true);
- picScroll->setWidget(mPictureLabel);
- QHBoxLayout *pictureLayout = new QHBoxLayout;
- pictureLayout->addWidget(mPictureLabel);
- mPicTab->setLayout(pictureLayout);
- mTab->addTab(mPicTab, "Picture");
- mSplitter->addWidget(mTab);
- mSplitter->setStretchFactor(0, 1);
- mSplitter->setStretchFactor(1, 3);
- mainLayout->addWidget(mSplitter);
-
- //button bar
- QHBoxLayout *buttonLayout = new QHBoxLayout;
- mOk = new QPushButton(tr("Ok"));
- mCancel = new QPushButton(tr("Cancel"));
- buttonLayout->addStretch();
- buttonLayout->addWidget(mOk);
- buttonLayout->addWidget(mCancel);
- connect(mCancel, SIGNAL(clicked()), this, SLOT(reject()));
- mainLayout->addLayout(buttonLayout);
- setLayout(mainLayout);
-}
diff --git a/propertiesdialog.h b/propertiesdialog.h
deleted file mode 100644
index 9d23dbd..0000000
--- a/propertiesdialog.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version
- 2 of the License, or (at your option) any later version.
-*/
-
-#ifndef PROPERTIESDIALOG_H
-#define PROPERTIESDIALOG_H
-
-#include <QModelIndex>
-
-#include "smdialog.h"
-
-class SmTreeModel;
-class FilesTreeModel;
-class SeriesTreeModel;
-class QLabel;
-class QSplitter;
-class QTreeView;
-class QTabWidget;
-class QPushButton;
-
-class PropertiesDialog : public SmDialog {
- Q_OBJECT
- public:
- enum NodeType { PictureFileNode, MovieFileNode, ScreenshotNode, DummyNode };
- explicit PropertiesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
- virtual ~PropertiesDialog();
- void populate(int seriesPartId);
-
- private slots:
- void showPicture(QModelIndex current, QModelIndex previous);
-
- private:
- void setupGui();
- SmTreeModel *mDisplayModel;
- FilesTreeModel *mFilesModel;
- SeriesTreeModel *mSeriesModel;
- int mCurrentId;
- QLabel *mCaption;
- QSplitter *mSplitter;
- QWidget *mPicTab;
- QLabel *mPictureLabel;
- QTreeView *mFileView;
- QTabWidget *mTab;
- QPushButton *mOk;
- QPushButton *mCancel;
-};
-
-#endif // PROPERTIESDIALOG_H
diff --git a/seriestreewidget.cpp b/seriestreewidget.cpp
index 2a487fb..49d5792 100644
--- a/seriestreewidget.cpp
+++ b/seriestreewidget.cpp
@@ -21,6 +21,7 @@
#include <QSettings>
#include <QFileInfo>
#include <QComboBox>
+#include <QInputDialog>
#include <QFile>
#include <QEvent>
#include <QHoverEvent>
@@ -44,7 +45,6 @@
#include "filestreemodel.h"
#include "helper.h"
#include "hoverwindow.h"
-#include "propertiesdialog.h"
SeriesTreeWidget::SeriesTreeWidget(QWidget *parent) : QWidget(parent){
//filter bar
@@ -107,19 +107,6 @@ SeriesTreeWidget::~SeriesTreeWidget(){
delete mCompleterProducer;
}
-void SeriesTreeWidget::newSeries(){
- QList<QVariant> data;
- data << tr("<New series>") << QVariant() << QVariant() << QVariant() << SeriesTreeModel::NewSeries;
- if(mModel->addRow(data, QModelIndex())){
- QModelIndex newRow = mModel->index(mModel->rowCount(QModelIndex()) - 1, 0, QModelIndex());
- if(newRow.isValid()){
- QModelIndex proxyIndex = mProxy->mapFromSource(newRow);
- mView->selectionModel()->select(proxyIndex, QItemSelectionModel::ClearAndSelect);
- mView->edit(proxyIndex);
- }
- }
-}
-
void SeriesTreeWidget::seriesAdded(QString seriesName, int seriesPart, bool resort){
if(resort){
mProxy->invalidate();
@@ -350,15 +337,20 @@ void SeriesTreeWidget::expandItems(const QStringList &items){
void SeriesTreeWidget::editItem(){
QModelIndex current = mView->selectionModel()->currentIndex();
- QModelIndex real = mProxy->mapToSource(current);
- if(real.data(SeriesTreeModel::TypeRole).toInt() == SeriesTreeModel::Part){
- PropertiesDialog dlg(this);
- dlg.populate(real.data(SeriesTreeModel::SeriesPartIdRole).toInt());
- dlg.exec();
- }
- /*QModelIndex real = mProxy->mapToSource(current);
- EditSeriesDialog dlg(real, this);
- dlg.exec();*/
+ if(current.data(SeriesTreeModel::TypeRole).toInt() == SeriesTreeModel::Series){
+ seriesTree()->edit(current);
+ return;
+ }
+ if(current.data(SeriesTreeModel::TypeRole).toInt() == SeriesTreeModel::Part){
+ int currentPart = current.data(SeriesTreeModel::SeriesPartRole).toInt();
+ bool dlgOk = false;
+ int newPart = QInputDialog::getInt(this, tr("Enter new series part"), tr("New series part"), currentPart, 1, 1000, 1, &dlgOk);
+ if(dlgOk){
+ QModelIndex real = mProxy->mapToSource(current);
+ QModelIndex part = mModel->index(real.row(), SeriesTreeModel::SeriesPart, real.parent());
+ mModel->setData(part, newPart, Qt::EditRole);
+ }
+ }
}
void SeriesTreeWidget::producerFinished(QStringListModel *model){
diff --git a/seriestreewidget.h b/seriestreewidget.h
index f68e10c..48f40a0 100644
--- a/seriestreewidget.h
+++ b/seriestreewidget.h
@@ -46,10 +46,8 @@ class SeriesTreeWidget : public QWidget {
virtual ~SeriesTreeWidget();
SeriesTreeView *seriesTree() { return mView; }
SeriesTreeSortModel *seriesProxy() { return mProxy; }
- int filterMode() const { return mFilterMode; }
public slots:
- void newSeries();
void seriesAdded(const QString seriesName, int seriesPart, bool resort = true);
void toggleFavorite();
void deleteFromSeries();
diff --git a/shemov.cpp b/shemov.cpp
index 130bd66..e8dfeae 100644
--- a/shemov.cpp
+++ b/shemov.cpp
@@ -433,8 +433,6 @@ void SheMov::createActions(){
connect(mStatisticsA, SIGNAL(triggered()), this, SLOT(showStatistics()));
//Tree series context menu
- mNewSeriesA = new QAction(tr("New series..."), this);
- connect(mNewSeriesA, SIGNAL(triggered()), mATree->seriesWidget(), SLOT(newSeries()));
mDeleteFromSeriesA = new QAction(tr("Delete entries..."), this);
connect(mDeleteFromSeriesA, SIGNAL(triggered()), mATree->seriesWidget(), SLOT(deleteFromSeries()));
mPlaySelectedAVA = new QAction(tr("Play selected movies..."), this);
@@ -832,9 +830,9 @@ void SheMov::createMenus(){
mFSWidget->fileView()->addAction(mArchiveSelectedMovsA);
//ArchiveTreeView context menu
- mATree->seriesWidget()->seriesTree()->addAction(mNewSeriesA);
+ mATree->seriesWidget()->seriesTree()->addAction(mEditItemA);
+ mATree->seriesWidget()->seriesTree()->addAction(createSeparator());
mATree->seriesWidget()->seriesTree()->addAction(mDeleteFromSeriesA);
- mATree->seriesWidget()->seriesTree()->addAction(mEditItemA);
mATree->seriesWidget()->seriesTree()->addAction(createSeparator());
mOpenWithMenuAV = new QMenu(tr("Open with"), this);
diff --git a/shemov.h b/shemov.h
index f20cc77..dab1c84 100644
--- a/shemov.h
+++ b/shemov.h
@@ -117,7 +117,6 @@ class SheMov : public QMainWindow {
//TreeView Actions
//Series Actions
- QAction *mNewSeriesA;
QAction *mDeleteFromSeriesA;
QAction *mExpandAllSeriesA;
QAction *mCollapseAllSeriesA;
diff --git a/shemov.pro b/shemov.pro
index adf6f6c..e61ffc8 100644
--- a/shemov.pro
+++ b/shemov.pro
@@ -33,7 +33,6 @@ SOURCES = main.cpp \
seriesmetadatamodel.cpp \
mappingtableeditor.cpp \
smdialog.cpp \
- propertiesdialog.cpp \
dbanalyzer.cpp \
mappingtreemodel.cpp \
mappingtreewidget.cpp \
@@ -69,7 +68,6 @@ HEADERS = \
seriesmetadatamodel.h \
mappingtableeditor.h \
smdialog.h \
- propertiesdialog.h \
dbanalyzer.h \
mappingtreemodel.h \
mappingtreewidget.h \