diff options
-rw-r--r-- | archivemodel.cpp | 48 | ||||
-rw-r--r-- | archivemodel.h | 2 | ||||
-rw-r--r-- | archiveview.cpp | 12 | ||||
-rw-r--r-- | archiveview.h | 1 | ||||
-rw-r--r-- | shemov.cpp | 5 | ||||
-rw-r--r-- | shemov.h | 1 |
6 files changed, 64 insertions, 5 deletions
diff --git a/archivemodel.cpp b/archivemodel.cpp index 21ee015..9ef2eac 100644 --- a/archivemodel.cpp +++ b/archivemodel.cpp @@ -94,11 +94,42 @@ bool ArchiveModel::setData(const QModelIndex &idx, const QVariant &value, int ro return true; } }else{ - QSqlError e = updateQuery.lastError(); - QString databaseText = e.databaseText().isEmpty() ? tr("(none)") : e.databaseText(); - QString driverText = e.driverText().isEmpty() ? tr("(none)") : e.driverText(); - QString errormsg = QString(tr("<b>Database error:</b><br/><ul><li>driverText(): %1</li><li>databaseText(): %2</li></ul>")).arg(driverText).arg(databaseText); - emit databaseError(errormsg); + emitDatabaseError(updateQuery.lastError()); + } + return false; +} + +bool ArchiveModel::removeNode(const QModelIndex &idx){ + if(!idx.isValid()){ + return false; + } + SmTreeItem *item = itemAt(idx); + if(item->childCount()){ + return false; + } + int nodeType = item->data(Type).toInt(); + QSqlQuery removeQuery(mDb); + if(nodeType == GenreNode){ + removeQuery.prepare("DELETE FROM genres WHERE igenres_id = :id"); + }else if(nodeType == ActorNode){ + removeQuery.prepare("DELETE FROM actors WHERE iactors_id = :id"); + }else if(nodeType == SeriesNode){ + removeQuery.prepare("DELETE FROM series WHERE iseries_id = :id"); + }else{ + return false; + } + QVariant id = item->data(GenericId); + removeQuery.bindValue(":id", id); + if(removeQuery.exec()){ + if(nodeType == GenreNode || nodeType == ActorNode){ + removeRows(idx.row(), 1, idx.parent()); + return true; + }else if(nodeType == SeriesNode){ + emit needRefresh(); + return true; + } + }else{ + emitDatabaseError(removeQuery.lastError()); } return false; } @@ -151,6 +182,13 @@ void ArchiveModel::collectorFinished(){ setRoot(item); } +void ArchiveModel::emitDatabaseError(const QSqlError &e){ + QString databaseText = e.databaseText().isEmpty() ? tr("(none)") : e.databaseText(); + QString driverText = e.driverText().isEmpty() ? tr("(none)") : e.driverText(); + QString errormsg = QString(tr("<b>Database error:</b><br/><ul><li>driverText(): %1</li><li>databaseText(): %2</li></ul>")).arg(driverText).arg(databaseText); + emit databaseError(errormsg); +} + ArchiveCollector::ArchiveCollector(int numFields, QObject *parent) : QThread(parent), mNumFields(numFields) { mDb = QSqlDatabase::cloneDatabase(QSqlDatabase::database("treedb"), "archivedb"); mDb.open(); diff --git a/archivemodel.h b/archivemodel.h index 946bb3c..8055c31 100644 --- a/archivemodel.h +++ b/archivemodel.h @@ -30,6 +30,7 @@ class ArchiveModel : public SmTreeModel { ArchiveCollector *collector() { return mCollector; } virtual QVariant data(const QModelIndex &index, int role) const; virtual bool setData(const QModelIndex &idx, const QVariant &value, int role); + virtual bool removeNode(const QModelIndex &idx); QStringList indexToPath(const QModelIndex &idx) const; QModelIndexList pathToIndex(const QStringList &path) const; @@ -46,6 +47,7 @@ class ArchiveModel : public SmTreeModel { void collectorFinished(); private: + void emitDatabaseError(const QSqlError &e); QSqlDatabase mDb; QHash<QString, int> mAvailableOrders; ArchiveCollector *mCollector; diff --git a/archiveview.cpp b/archiveview.cpp index 4d9e370..96bf01b 100644 --- a/archiveview.cpp +++ b/archiveview.cpp @@ -185,6 +185,18 @@ void ArchiveTree::rename(){ } } +void ArchiveTree::remove(){ + QModelIndex idx = currentIndex(); + QModelIndex realIdx = mProxy->mapToSource(idx); + QString warningMsg = QString("Really remove %1?").arg(idx.data().toString()); + int retval = QMessageBox::warning(this, tr("Question"), warningMsg, QMessageBox::Yes | QMessageBox::No); + if(retval == QMessageBox::Yes){ + if(!mModel->removeNode(realIdx)){ + impossible(); + } + } +} + void ArchiveTree::impossible(const QString msg){ QMessageBox::critical(this, tr("Error"), msg); } diff --git a/archiveview.h b/archiveview.h index 540db29..9e3e666 100644 --- a/archiveview.h +++ b/archiveview.h @@ -72,6 +72,7 @@ class ArchiveTree : public SmTreeView { public slots: void rename(); + void remove(); private: void impossible(const QString msg = tr("Unable to perform function!")); @@ -738,9 +738,14 @@ void SheMov::createActions(){ /* picView(er) END Actions! */ // ArchiveView actions + // rename mArchiveViewRenameA = new QAction(tr("Rename..."), this); connect(mArchiveViewRenameA, SIGNAL(triggered()), mArchive->archiveTree(), SLOT(rename())); mArchive->archiveTree()->addAction(mArchiveViewRenameA); + // remove + mArchiveViewRemoveA = new QAction(tr("Remove..."), this); + connect(mArchiveViewRemoveA, SIGNAL(triggered()), mArchive->archiveTree(), SLOT(remove())); + mArchive->archiveTree()->addAction(mArchiveViewRemoveA); //don't add actions with checkable(true) unless you know what you're doing! mPicActionGroup = new QActionGroup(this); @@ -187,6 +187,7 @@ class SheMov : public QMainWindow { //ArchiveView actions QAction *mArchiveViewRenameA; + QAction *mArchiveViewRemoveA; QSignalMapper *mOpenWithMapperFS; QSignalMapper *mOpenWithMapperAV; |