diff options
author | Arno <am@disconnect.de> | 2010-12-06 19:10:19 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-12-06 19:10:19 +0100 |
commit | a87e4d8c3c2102e9728dd5df303acca7ae08b343 (patch) | |
tree | 29b2b7d2c5f532da2ea18152e7cf34ad51b1016f /filestreewidget.cpp | |
parent | cb4d80e6a642ef0cd3180aed2155d86144c83395 (diff) | |
download | SheMov-a87e4d8c3c2102e9728dd5df303acca7ae08b343.tar.gz SheMov-a87e4d8c3c2102e9728dd5df303acca7ae08b343.tar.bz2 SheMov-a87e4d8c3c2102e9728dd5df303acca7ae08b343.zip |
Edit values in archive
This commit introduces QInputDialogs for all values editable in the
archive. Inline editing in the view doesn't seem the right choice
regarding usability.
Fixed a long standing bug in nextDvdNo(). That was off by one. Return
one more than max(value). Also got rid of DvdNoDialog, replaced by a
QInputDialog.
Diffstat (limited to 'filestreewidget.cpp')
-rw-r--r-- | filestreewidget.cpp | 120 |
1 files changed, 47 insertions, 73 deletions
diff --git a/filestreewidget.cpp b/filestreewidget.cpp index 9ca20d0..941c7ac 100644 --- a/filestreewidget.cpp +++ b/filestreewidget.cpp @@ -22,6 +22,7 @@ #include <QEvent> #include <QSettings> #include <QHeaderView> +#include <QInputDialog> #include "filestreewidget.h" #include "smglobals.h" @@ -106,29 +107,6 @@ void FilesTreeWidget::moveToBurn(){ } } -void FilesTreeWidget::setDvdNo(){ - DvdNoDialog dlg(this); - int retval = dlg.exec(); - if(retval == QDialog::Accepted){ - QModelIndexList selected = mView->selectionModel()->selectedRows(); - if(selected.isEmpty()){ - return; - } - int dvdNo = dlg.dvdNo(); - foreach(QModelIndex i, selected){ - int type = i.data(FilesTreeModel::FileTypeRole).toInt(); - if(type != FilesTreeModel::Movie){ - continue; - } - QModelIndex real = mProxy->mapToSource(i); - if(real.isValid()){ - QModelIndex dvdColumn = mModel->index(real.row(), FilesTreeModel::DvdNo, real.parent()); - mModel->setData(dvdColumn, dvdNo, Qt::EditRole); - } - } - } -} - void FilesTreeWidget::removeFiles(){ QModelIndexList selected = mView->selectionModel()->selectedRows(); if(selected.isEmpty()){ @@ -195,22 +173,55 @@ void FilesTreeWidget::fileProperties(){ } dlg.exec(); } - } -void FilesTreeWidget::editQuality(){ - QModelIndex current = mView->selectionModel()->currentIndex(); - if(current.isValid()){ - QModelIndex qualityIndex = mView->model()->index(current.row(), FilesTreeModel::Quality, current.parent()); - mView->edit(qualityIndex); +void FilesTreeWidget::edit(int column){ + QModelIndexList currentSel = mView->selectionModel()->selectedRows(); + if(currentSel.isEmpty()){ + return; } -} - -void FilesTreeWidget::editPart(){ - QModelIndex current = mView->selectionModel()->currentIndex(); - if(current.isValid()){ - QModelIndex qualityIndex = mView->model()->index(current.row(), FilesTreeModel::PartNo, current.parent()); - mView->edit(qualityIndex); + const QHash<QString, int> cols = mModel->editableColumns(); + if(!cols.values().contains(column)){ + return; + } + QModelIndexList sIdxes; + foreach(QModelIndex idx, currentSel){ + QModelIndex pIdx = filesTree()->model()->index(idx.row(), column, idx.parent()); + if(pIdx.isValid()){ + sIdxes << mProxy->mapToSource(pIdx); + } + } + QString msg = cols.key(column); + if(column == FilesTreeModel::FileType){ + QStringList fileTypes = mModel->fileTypes().values(); + qSort(fileTypes); + int inputIdx = fileTypes.indexOf(sIdxes.first().data().toString()); + QString item = QInputDialog::getItem(this, msg, msg, fileTypes, inputIdx, false); + if(!item.isEmpty()){ + int fileTypeInt = mModel->fileTypes().key(item); + foreach(QModelIndex curIdx, sIdxes){ + mModel->setData(curIdx, fileTypeInt, Qt::EditRole); + } + } + return; + } + bool dialogOk = false; + int value = -1; + if(column == FilesTreeModel::PartNo){ + value = QInputDialog::getInt(this, msg, msg, sIdxes.first().data().toInt(), -1, 2147483647, 1, &dialogOk); + } + if(column == FilesTreeModel::Quality){ + value = QInputDialog::getInt(this, msg, msg, sIdxes.first().data().toInt(), -1, 10, 1, &dialogOk); + } + if(column == FilesTreeModel::DvdNo){ + SeriesTreeModel *seriesModel = static_cast<SeriesTreeModel*>(SmGlobals::instance()->model("SeriesModel")); + int nextDvdNo = seriesModel->findNextDvdNo(); + value = QInputDialog::getInt(this, msg, msg, nextDvdNo, -1, 2147483647, 1, &dialogOk); + } + if(dialogOk){ + foreach(QModelIndex curIdx, sIdxes){ + mModel->setData(curIdx, value, Qt::EditRole); + } } } @@ -288,7 +299,6 @@ void FilesTreeView::setModel(QAbstractItemModel *model){ header()->setSectionHidden(i, true); } readHeaderConfig(); - connect(header(), SIGNAL(sectionMoved(int,int,int)), this, SLOT(sectionHasMoved(int,int,int))); } void FilesTreeView::readConfig(){ @@ -402,39 +412,3 @@ bool FilesTreeSortModel::lessThan(const QModelIndex &left, const QModelIndex &ri } return QSortFilterProxyModel::lessThan(left, right); } - -DvdNoDialog::DvdNoDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ - //spin box - QHBoxLayout *spinBoxLayout = new QHBoxLayout; - QLabel *l1 = new QLabel(tr("Select &Dvd no.")); - mDvdNo = new QSpinBox; - l1->setBuddy(mDvdNo); - spinBoxLayout->addWidget(l1); - spinBoxLayout->addWidget(mDvdNo); - mDvdNo->setMinimum(-1); - SeriesTreeModel *seriesModel = static_cast<SeriesTreeModel*>(SmGlobals::instance()->model("SeriesModel")); - int nextDvdNo = seriesModel->findNextDvdNo(); - mDvdNo->setValue(nextDvdNo); - - //buttons - QHBoxLayout *buttonLayout = new QHBoxLayout; - mOk = new QPushButton(tr("Ok")); - connect(mOk, SIGNAL(clicked()), this, SLOT(accept())); - buttonLayout->addStretch(); - buttonLayout->addWidget(mOk); - mCancel = new QPushButton(tr("Cancel")); - connect(mCancel, SIGNAL(clicked()), this, SLOT(reject())); - buttonLayout->addWidget(mCancel); - - //main layout - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addLayout(spinBoxLayout); - mainLayout->addLayout(buttonLayout); - setLayout(mainLayout); - - setWindowTitle(tr("Select Dvd no.")); -} - -int DvdNoDialog::dvdNo() const { - return mDvdNo->value(); -} |