From d1607c507b14ee74fe62e3366c2b629881663689 Mon Sep 17 00:00:00 2001 From: Arno Date: Wed, 27 Dec 2017 08:08:51 +0100 Subject: Clean up archivecontroller.cpp * remove deprecation warnings (QModelIndex::child) * replace Q_FOREACH * use type-safe connect syntax --- archivecontroller.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'archivecontroller.cpp') diff --git a/archivecontroller.cpp b/archivecontroller.cpp index af05c7a..ffee2e1 100644 --- a/archivecontroller.cpp +++ b/archivecontroller.cpp @@ -58,9 +58,9 @@ void ArchiveController::setMappingModels(QStandardItemModel *actorModel, QStanda } void ArchiveController::init(){ - connect(mArchiveSelection, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(treeSelectionChanged(QItemSelection,QItemSelection))); - connect(mArchiveFiles, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(fileDoubleClicked(QModelIndex))); - connect(mFileSelection, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(fileSelectionChanged(QItemSelection,QItemSelection))); + connect(mArchiveSelection, &QItemSelectionModel::selectionChanged, this, &ArchiveController::treeSelectionChanged); + connect(mArchiveFiles, &ArchiveFiles::doubleClicked, this, &ArchiveController::fileDoubleClicked); + connect(mFileSelection, &QItemSelectionModel::selectionChanged, this, &ArchiveController::fileSelectionChanged); } void ArchiveController::setSeriesPart(int seriesPartId){ @@ -76,7 +76,7 @@ void ArchiveController::setSeriesPart(int seriesPartId){ void ArchiveController::playSelectedFiles(){ QModelIndexList sel = mFileSelection->selectedRows(); QStringList files; - foreach(QModelIndex i, sel){ + for(const QModelIndex &i : sel){ if(i.data(ArchiveFilesModel::FileTypeRole).toInt() == FT_MOVIE){ QString fullPath = i.data(ArchiveFilesModel::FullPathRole).toString(); QFileInfo fi(fullPath); @@ -101,7 +101,7 @@ void ArchiveController::editQuality(){ bool ok; int quality = QInputDialog::getInt(mParentWidget, tr("Set Quality"), tr("Quality"), 7, 1, 10, 1, &ok); if(ok){ - foreach(QModelIndex i, sel){ + for(const QModelIndex &i : sel){ QModelIndex real = mArchiveFilesProxy->mapToSource(i); if(mArchiveFilesModel->isMovie(real)){ mArchiveFilesModel->setData(real, quality, ArchiveFilesModel::QualityRole); @@ -118,7 +118,7 @@ void ArchiveController::editDvdNo(){ bool ok; int dvdNo = QInputDialog::getInt(mParentWidget, tr("Set DVD no."), tr("Number (-1 for local)"), mArchiveFilesModel->nextDvd(), -1, 1024 * 1024, 1, &ok); if(ok){ - foreach(QModelIndex i, sel){ + for(const QModelIndex &i : sel){ QModelIndex real = mArchiveFilesProxy->mapToSource(i); if(mArchiveFilesModel->isMovie(real)){ mArchiveFilesModel->setData(real, dvdNo, ArchiveFilesModel::DvdNoRole); @@ -147,7 +147,7 @@ void ArchiveController::editFileType(){ newType = FT_GENERALCOVER; } if(newType){ - foreach(QModelIndex i, sel){ + for(const QModelIndex &i : sel){ QModelIndex real = mArchiveFilesProxy->mapToSource(i); mArchiveFilesModel->setData(real, newType, ArchiveFilesModel::FileTypeRole); } @@ -165,7 +165,7 @@ void ArchiveController::editFileNo(){ bool ok; int fileNo = QInputDialog::getInt(mParentWidget, tr("Set DVD no."), tr("Number (-1 for none)"), -1, -1, 1024 * 1024, 1, &ok); if(ok){ - foreach(QModelIndex i, sel){ + for(const QModelIndex &i : sel){ QModelIndex real = mArchiveFilesProxy->mapToSource(i); if(mArchiveFilesModel->isMovie(real)){ mArchiveFilesModel->setData(real, fileNo, ArchiveFilesModel::FileNumberRole); @@ -240,7 +240,7 @@ void ArchiveController::readConfig(){ } void ArchiveController::moveFilesToSeriespart(const QStringList &md5Sums, int newSeriesPart){ - foreach(QString md5, md5Sums){ + for(const QString &md5 : md5Sums){ mArchiveFilesModel->updateSeriesPartForFile(md5, newSeriesPart); } mArchiveFilesModel->refresh(); @@ -254,7 +254,7 @@ void ArchiveController::treeSelectionChanged(const QItemSelection &selected, con return; } QSet ids; - foreach(QModelIndex idx, sel){ + for(const QModelIndex &idx : sel){ ids.unite(mArchiveModel->seriesPartIds(idx)); } mArchiveFilesModel->populate(ids); @@ -262,13 +262,13 @@ void ArchiveController::treeSelectionChanged(const QItemSelection &selected, con mArchiveView->setCurrentArchivePath(mArchiveModel->indexToPath(sel.first())); QStringList actors = mArchiveModel->actors(ids); mActorModel->clear(); - foreach(QString actor, actors){ + for(const QString &actor : actors){ QStandardItem *newItem = new QStandardItem(mActorIcon, actor); mActorModel->appendRow(newItem); } QStringList genres = mArchiveModel->genres(ids); mGenreModel->clear(); - foreach(QString genre, genres){ + for(const QString &genre : genres){ QStandardItem *newItem = new QStandardItem(mGenreIcon, genre); mGenreModel->appendRow(newItem); } @@ -276,7 +276,7 @@ void ArchiveController::treeSelectionChanged(const QItemSelection &selected, con getMetadata(ids); int nodeType = sel.first().data(ArchiveModel::TypeRole).toInt(); - foreach(QAction *a, mActionsForTree){ + for(QAction *a : mActionsForTree){ int aData = a->data().toInt(); bool enabled = aData & nodeType; a->setEnabled(enabled); @@ -360,7 +360,7 @@ void ArchiveController::fileSelectionChanged(const QItemSelection &selected, con qint64 duration = 0; bool maybeMore = false; QSet seriesParts; - foreach(QModelIndex i, sel){ + for(const QModelIndex &i : sel){ seriesParts << i.data(ArchiveFilesModel::SeriesPartIdRole).toInt(); size += i.data(ArchiveFilesModel::SizeRole).toInt(); int type = i.data(ArchiveFilesModel::FileTypeRole).toInt(); @@ -398,14 +398,15 @@ void ArchiveController::fileDoubleClicked(const QModelIndex &idx){ } PictureViewer2 *pv = SmGlobals::instance()->pictureViewer(); QModelIndex parent = idx.parent(); + const QAbstractItemModel *parentModel = parent.model(); QStringList paths; if(parent.isValid()){ int row = 0; - QModelIndex child = parent.child(row, ArchiveFilesModel::FullPath); + QModelIndex child = parentModel->index(row, ArchiveFilesModel::FullPath, parent); while(child.isValid()){ paths << child.data().toString(); ++row; - child = parent.child(row, ArchiveFilesModel::FullPath); + child = parentModel->index(row, ArchiveFilesModel::FullPath, parent); } } pv->setShowMarkItem(false); @@ -416,7 +417,7 @@ void ArchiveController::fileDoubleClicked(const QModelIndex &idx){ QModelIndexList ArchiveController::mapToSource(const QSortFilterProxyModel *proxy, const QModelIndexList idxs) const{ QModelIndexList retval; - foreach(QModelIndex idx, idxs){ + for(const QModelIndex &idx : idxs){ retval << proxy->mapToSource(idx); } return retval; -- cgit v1.2.3-70-g09d2