summaryrefslogtreecommitdiffstats
path: root/archiveview.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2013-07-27 10:23:18 +0200
committerArno <am@disconnect.de>2013-07-27 10:23:18 +0200
commitfa4f4952b11b94ffa899e40c4f22070280a4a399 (patch)
tree775efd3e1081e57a2e2a73ae8c7c3a0cd492b743 /archiveview.cpp
parentb8b0cdeebbc7e6c7df905291974ed9612125fe55 (diff)
downloadSheMov-fa4f4952b11b94ffa899e40c4f22070280a4a399.tar.gz
SheMov-fa4f4952b11b94ffa899e40c4f22070280a4a399.tar.bz2
SheMov-fa4f4952b11b94ffa899e40c4f22070280a4a399.zip
Change new archive edit menu
Put actions for files and tree in submenus and use selectionModel instead of currentIndex for retrieving the selected item in the tree.
Diffstat (limited to 'archiveview.cpp')
-rw-r--r--archiveview.cpp60
1 files changed, 42 insertions, 18 deletions
diff --git a/archiveview.cpp b/archiveview.cpp
index 7684d47..9ca131d 100644
--- a/archiveview.cpp
+++ b/archiveview.cpp
@@ -262,24 +262,28 @@ void ArchiveTree::setModel(ArchiveProxy *model){
}
void ArchiveTree::edit(){
- QModelIndex idx = currentIndex();
- QString currentName = idx.data(ArchiveModel::NameRole).toString();
- QString question = QString(tr("Rename %1 to:")).arg(currentName);
- QString newName = QInputDialog::getText(this, tr("Rename"), question, QLineEdit::Normal, currentName);
- if(!newName.isEmpty()){
- QModelIndex realIdx = mProxy->mapToSource(idx);
- mModel->setData(realIdx, newName, Qt::EditRole);
+ QModelIndex idx = firstSelected();
+ if(idx.isValid()){
+ QString currentName = idx.data(ArchiveModel::NameRole).toString();
+ QString question = QString(tr("Rename %1 to:")).arg(currentName);
+ QString newName = QInputDialog::getText(this, tr("Rename"), question, QLineEdit::Normal, currentName);
+ if(!newName.isEmpty()){
+ QModelIndex realIdx = mProxy->mapToSource(idx);
+ mModel->setData(realIdx, newName, Qt::EditRole);
+ }
}
}
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();
+ QModelIndex idx = firstSelected();
+ if(idx.isValid()){
+ 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){
+ QModelIndex realIdx = mProxy->mapToSource(idx);
+ if(!mModel->removeNode(realIdx)){
+ impossible();
+ }
}
}
}
@@ -288,7 +292,10 @@ void ArchiveTree::editActors(){
MappingEditor e(tr("Actors"), this);
QStringList actors = mModel->allActors();
e.widget()->fillCompleter(actors);
- QModelIndex idx = currentIndex();
+ QModelIndex idx = firstSelected();
+ if(!idx.isValid()){
+ return;
+ }
int pId = idx.data(ArchiveModel::SeriesPartIdRole).toInt();
QStringList curActors = mModel->actors(QSet<int>() << pId);
e.widget()->setDecorationItem(SmGlobals::instance()->iconFor("actor"));
@@ -306,7 +313,10 @@ void ArchiveTree::editGenres(){
MappingEditor e(tr("Genres"), this);
QStringList genres = mModel->allGenres();
e.widget()->fillCompleter(genres);
- QModelIndex idx = currentIndex();
+ QModelIndex idx = firstSelected();
+ if(!idx.isValid()){
+ return;
+ }
int pId = idx.data(ArchiveModel::SeriesPartIdRole).toInt();
QStringList curGenres = mModel->genres(QSet<int>() << pId);
e.widget()->setDecorationItem(SmGlobals::instance()->iconFor("genre"));
@@ -321,13 +331,16 @@ void ArchiveTree::editGenres(){
}
void ArchiveTree::editMetadata(){
+ QModelIndex idx = firstSelected();
+ if(!idx.isValid()){
+ return;
+ }
MetadataEditor e(this);
ArchiveController *c = SmGlobals::instance()->archiveController();
QStringList sources = c->archiveTreeModel()->allSources();
e.widget()->setSources(sources);
QStringList relGroups = c->archiveTreeModel()->allReleaseGroups();
e.widget()->setReleaseGroups(relGroups);
- QModelIndex idx = currentIndex();
int pId = idx.data(ArchiveModel::SeriesPartIdRole).toInt();
QList<QVariant> curMetadata = c->archiveTreeModel()->metadataList(pId);
e.widget()->setMetadata(curMetadata);
@@ -340,7 +353,10 @@ void ArchiveTree::editMetadata(){
}
void ArchiveTree::editSeriesPart(){
- QModelIndex idx = currentIndex();
+ QModelIndex idx = firstSelected();
+ if(!idx.isValid()){
+ return;
+ }
int curPart = idx.data(ArchiveModel::SeriesPartRole).toInt();
QString subtitle = idx.data(ArchiveModel::SubtitleRole).toString();
PartEditor e(this);
@@ -359,6 +375,14 @@ void ArchiveTree::impossible(const QString msg){
QMessageBox::critical(this, tr("Error"), msg);
}
+QModelIndex ArchiveTree::firstSelected(){
+ QModelIndexList idxs = selectionModel()->selectedRows();
+ if(idxs.isEmpty()){
+ QModelIndex();
+ }
+ return idxs.first();
+}
+
ArchiveFiles::ArchiveFiles(const QString &headerSettings, QWidget *parent) : SmTreeView(headerSettings, parent){
setEditTriggers(QAbstractItemView::NoEditTriggers);
}