diff options
author | Arno <am@disconnect.de> | 2013-07-12 10:39:31 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2013-07-12 10:39:31 +0200 |
commit | 96df0c7b20a6f3e8c118d373f52193f71ab4b521 (patch) | |
tree | ee2e7f7a612a3becfda3a78fc02dd9ad1a063814 | |
parent | e989a412665303f37f950584370db4b6e5eb7198 (diff) | |
download | SheMov-96df0c7b20a6f3e8c118d373f52193f71ab4b521.tar.gz SheMov-96df0c7b20a6f3e8c118d373f52193f71ab4b521.tar.bz2 SheMov-96df0c7b20a6f3e8c118d373f52193f71ab4b521.zip |
Split MappingEditor into two classes
Split MappingEditor into a Dialog and the actual MappingEditorWidget.
Turns out that we need the Widget in NewMovieWizard, also. No need for
code duplication.
NB: Before this I tried to convert the WizardTreeModel to a
QStandardItemModel, but it had severe performance problems. Most likely
I would have ended up subclassing QStandardItemModel anyway, so leave it
as it is.
-rw-r--r-- | archiveview.cpp | 70 | ||||
-rw-r--r-- | archiveview.h | 25 |
2 files changed, 67 insertions, 28 deletions
diff --git a/archiveview.cpp b/archiveview.cpp index 20ce072..1d0502a 100644 --- a/archiveview.cpp +++ b/archiveview.cpp @@ -291,14 +291,14 @@ void ArchiveTree::remove(){ void ArchiveTree::editActors(){ MappingEditor e(tr("Actors"), this); QStringList actors = mModel->allActors(); - e.fillCompleter(actors); + e.widget()->fillCompleter(actors); QModelIndex idx = currentIndex(); int pId = idx.data(ArchiveModel::SeriesPartIdRole).toInt(); QStringList curActors = mModel->actors(QSet<int>() << pId); - e.setCurrentItems(curActors); + e.widget()->setCurrentItems(curActors); int res = e.exec(); if(res == QDialog::Accepted){ - QStringList selActors = e.items(); + QStringList selActors = e.widget()->items(); mModel->setActors(pId, selActors); ArchiveController *c = SmGlobals::instance()->archiveController(); c->treeSelectionChanged(QItemSelection(), QItemSelection()); @@ -308,14 +308,14 @@ void ArchiveTree::editActors(){ void ArchiveTree::editGenres(){ MappingEditor e(tr("Genres"), this); QStringList genres = mModel->allGenres(); - e.fillCompleter(genres); + e.widget()->fillCompleter(genres); QModelIndex idx = currentIndex(); int pId = idx.data(ArchiveModel::SeriesPartIdRole).toInt(); QStringList curGenres = mModel->genres(QSet<int>() << pId); - e.setCurrentItems(curGenres); + e.widget()->setCurrentItems(curGenres); int res = e.exec(); if(res == QDialog::Accepted){ - QStringList selGenres = e.items(); + QStringList selGenres = e.widget()->items(); mModel->setGenres(pId, selGenres); ArchiveController *c = SmGlobals::instance()->archiveController(); c->treeSelectionChanged(QItemSelection(), QItemSelection()); @@ -393,9 +393,10 @@ QWidget *FileTypeDelegate::createEditor(QWidget *parent, const QStyleOptionViewI return retval; } -/* Mapping Editor */ +/* Mapping Editor Widget */ -MappingEditor::MappingEditor(const QString &caption, QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) { +MappingEditorWidget::MappingEditorWidget(const QString &caption, QWidget *parent) : QWidget(parent){ + // the view mModel = new QStandardItemModel(this); mModel->setHorizontalHeaderLabels(QStringList() << caption); mProxy = new QSortFilterProxyModel(this); @@ -406,6 +407,7 @@ MappingEditor::MappingEditor(const QString &caption, QWidget *parent, Qt::Window mView->setModel(mProxy); mView->setSortingEnabled(true); + // line editor QHBoxLayout *editLayout = new QHBoxLayout; QLabel *l2 = new QLabel(tr("Add:")); mEditor = new QLineEdit; @@ -416,6 +418,7 @@ MappingEditor::MappingEditor(const QString &caption, QWidget *parent, Qt::Window editLayout->addWidget(l2); editLayout->addWidget(mEditor); + // edit buttons QHBoxLayout *editButtonLayout = new QHBoxLayout; mRemove = new QPushButton(tr("Remove")); connect(mRemove, SIGNAL(clicked()), this, SLOT(removeItem())); @@ -424,29 +427,19 @@ MappingEditor::MappingEditor(const QString &caption, QWidget *parent, Qt::Window connect(mAdd, SIGNAL(clicked()), this, SLOT(addItem())); editButtonLayout->addWidget(mAdd); - QHBoxLayout *buttonLayout = new QHBoxLayout; - buttonLayout->addStretch(); - mCancel = new QPushButton(tr("Cancel")); - connect(mCancel, SIGNAL(clicked()), this, SLOT(reject())); - buttonLayout->addWidget(mCancel); - mAccept = new QPushButton(tr("Accept")); - connect(mAccept, SIGNAL(clicked()), this, SLOT(accept())); - buttonLayout->addWidget(mAccept); - + // main layout QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(viewLayout); mainLayout->addLayout(editLayout); mainLayout->addLayout(editButtonLayout); - mainLayout->addLayout(buttonLayout); setLayout(mainLayout); - setMinimumWidth(400); } -void MappingEditor::fillCompleter(const QStringList &completions){ +void MappingEditorWidget::fillCompleter(const QStringList &completions){ mCompleterModel->setStringList(completions); } -void MappingEditor::setCurrentItems(const QStringList &items){ +void MappingEditorWidget::setCurrentItems(const QStringList &items){ foreach(QString i, items){ QStandardItem *item = new QStandardItem(i); item->setIcon(QIcon(":/huge_bra.png")); @@ -454,7 +447,7 @@ void MappingEditor::setCurrentItems(const QStringList &items){ } } -QStringList MappingEditor::items() const{ +QStringList MappingEditorWidget::items() const{ QStringList retval; for(int i = 0; i < mModel->rowCount(); ++i){ QStandardItem *item = mModel->item(i); @@ -463,7 +456,7 @@ QStringList MappingEditor::items() const{ return retval; } -void MappingEditor::addItem(){ +void MappingEditorWidget::addItem(){ QString itemName = mEditor->text(); if(itemName.isEmpty()){ return; @@ -479,7 +472,7 @@ void MappingEditor::addItem(){ mEditor->clear(); } -void MappingEditor::removeItem(){ +void MappingEditorWidget::removeItem(){ QModelIndexList sel = mView->selectionModel()->selectedRows(); if(sel.isEmpty()){ return; @@ -488,6 +481,35 @@ void MappingEditor::removeItem(){ mModel->removeRow(real.row()); } +/* Mapping Editor */ + +MappingEditor::MappingEditor(const QString &caption, QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) { + // Mapping Editor Widget + mWidget = new MappingEditorWidget(caption); + + // buttons + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addStretch(); + mCancel = new QPushButton(tr("Cancel")); + connect(mCancel, SIGNAL(clicked()), this, SLOT(reject())); + buttonLayout->addWidget(mCancel); + mAccept = new QPushButton(tr("Accept")); + connect(mAccept, SIGNAL(clicked()), this, SLOT(accept())); + buttonLayout->addWidget(mAccept); + + // dialog layout + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(mWidget); + mainLayout->addLayout(buttonLayout); + setLayout(mainLayout); + setMinimumWidth(300); +} + + + + + + /* Metadata Editor */ MetadataEditor::MetadataEditor(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ diff --git a/archiveview.h b/archiveview.h index 1359e88..36c3eb4 100644 --- a/archiveview.h +++ b/archiveview.h @@ -133,10 +133,13 @@ class FileTypeDelegate : public QStyledItemDelegate { QHash<int, QString> mFiletypeMap; }; -class MappingEditor : public QDialog { +/* separate widget since we need it in NewMovieWizard + * and editing genres, actors in the new ArchiveView */ + +class MappingEditorWidget : public QWidget { Q_OBJECT public: - explicit MappingEditor(const QString &caption, QWidget *parent = 0, Qt::WindowFlags f = 0); + explicit MappingEditorWidget(const QString &caption, QWidget *parent = 0); void fillCompleter(const QStringList &completions); void setCurrentItems(const QStringList &items); QStringList items() const; @@ -151,13 +154,27 @@ class MappingEditor : public QDialog { SmTreeView *mView; QPushButton *mAdd; QPushButton *mRemove; - QPushButton *mAccept; - QPushButton *mCancel; QLineEdit *mEditor; QCompleter *mCompleter; QStringListModel *mCompleterModel; }; +/* dialog putting MappingEditorWidget and + * Cancel, Accept buttons together. Used when editing + * ArchiveView */ + +class MappingEditor : public QDialog { + Q_OBJECT + public: + explicit MappingEditor(const QString &caption, QWidget *parent = 0, Qt::WindowFlags f = 0); + MappingEditorWidget *widget() { return mWidget; } + + private: + QPushButton *mAccept; + QPushButton *mCancel; + MappingEditorWidget *mWidget; +}; + class MetadataEditor : public QDialog { Q_OBJECT public: |