diff --git a/core/app/CMakeLists.txt b/core/app/CMakeLists.txt --- a/core/app/CMakeLists.txt +++ b/core/app/CMakeLists.txt @@ -350,6 +350,7 @@ utils/contextmenuhelper.cpp utils/digikam_debug.cpp utils/componentsinfo.cpp + utils/groupingviewimplementation.cpp views/tableview/tableview.cpp views/tableview/tableview_treeview.cpp diff --git a/core/app/items/digikamimageview.h b/core/app/items/digikamimageview.h --- a/core/app/items/digikamimageview.h +++ b/core/app/items/digikamimageview.h @@ -27,15 +27,18 @@ // Local includes +#include "applicationsettings.h" #include "imagecategorizedview.h" #include "imageviewutilities.h" +#include "groupingviewimplementation.h" namespace Digikam { class ImageViewUtilities; +class ImageInfoList; -class DigikamImageView : public ImageCategorizedView +class DigikamImageView : public ImageCategorizedView, public GroupingViewImplementation { Q_OBJECT @@ -50,6 +53,12 @@ virtual void setThumbnailSize(const ThumbnailSize& size); + ImageInfoList allImageInfos(bool grouping = false) const; + ImageInfoList selectedImageInfos(bool grouping = false) const; + ImageInfoList selectedImageInfosCurrentFirst(bool grouping = false) const; + bool allNeedGroupResolving(const ApplicationSettings::OperationType type) const; + bool selectedNeedGroupResolving(const ApplicationSettings::OperationType type) const; + public Q_SLOTS: void openFile(const ImageInfo& info); @@ -95,6 +104,12 @@ virtual void showContextMenu(QContextMenuEvent* event); virtual void slotSetupChanged(); + virtual bool hasHiddenGroupedImages(const ImageInfo& info) const; + + ImageInfoList imageInfos(const QList& indexes, + ApplicationSettings::OperationType type + = ApplicationSettings::Unspecified) const; + private Q_SLOTS: void slotRotateLeft(const QList&); diff --git a/core/app/items/digikamimageview.cpp b/core/app/items/digikamimageview.cpp --- a/core/app/items/digikamimageview.cpp +++ b/core/app/items/digikamimageview.cpp @@ -179,6 +179,46 @@ ImageCategorizedView::setThumbnailSize(size); } +ImageInfoList DigikamImageView::allImageInfos(bool grouping) const +{ + if (grouping) + { + return resolveGrouping(ImageCategorizedView::allImageInfos()); + } + + return ImageCategorizedView::allImageInfos(); +} + +ImageInfoList DigikamImageView::selectedImageInfos(bool grouping) const +{ + if (grouping) + { + return resolveGrouping(ImageCategorizedView::selectedImageInfos()); + } + + return ImageCategorizedView::selectedImageInfos(); +} + +ImageInfoList DigikamImageView::selectedImageInfosCurrentFirst(bool grouping) const +{ + if (grouping) + { + return resolveGrouping(ImageCategorizedView::selectedImageInfosCurrentFirst()); + } + + return ImageCategorizedView::selectedImageInfosCurrentFirst(); +} + +bool DigikamImageView::allNeedGroupResolving(const ApplicationSettings::OperationType type) const +{ + return needGroupResolving(type, allImageInfos()); +} + +bool DigikamImageView::selectedNeedGroupResolving(const ApplicationSettings::OperationType type) const +{ + return needGroupResolving(type, selectedImageInfos()); +} + int DigikamImageView::fitToWidthIcons() { return delegate()->calculatethumbSizeToFit(viewport()->size().width()); @@ -195,6 +235,24 @@ ImageCategorizedView::slotSetupChanged(); } +bool DigikamImageView::hasHiddenGroupedImages(const ImageInfo& info) const +{ + return info.hasGroupedImages() && !imageFilterModel()->isGroupOpen(info.id()); +} + +ImageInfoList DigikamImageView::imageInfos(const QList& indexes, + ApplicationSettings::OperationType type) const +{ + ImageInfoList infos = ImageCategorizedView::imageInfos(indexes); + + if (needGroupResolving(type, infos)) + { + return resolveGrouping(infos); + } + + return infos; +} + void DigikamImageView::setFaceMode(bool on) { d->faceMode = on; @@ -389,8 +447,12 @@ void DigikamImageView::rename() { - bool grouping = needGroupResolving(ApplicationSettings::Rename); - QList urls = selectedUrls(grouping); + ImageInfoList infos = selectedImageInfos(); + if (needGroupResolving(ApplicationSettings::Rename, infos)) + { + infos = resolveGrouping(infos); + } + QList urls = infos.toImageUrlList(); bool loop = false; NewNamesList newNamesList; @@ -409,7 +471,7 @@ if (!loop) { - QUrl nextUrl = nextInOrder(selectedImageInfos(grouping).last(), 1).fileUrl(); + QUrl nextUrl = nextInOrder(infos.last(),1).fileUrl(); setCurrentUrl(nextUrl); loop = true; } diff --git a/core/app/items/imagecategorizedview.h b/core/app/items/imagecategorizedview.h --- a/core/app/items/imagecategorizedview.h +++ b/core/app/items/imagecategorizedview.h @@ -27,7 +27,6 @@ // Local includes -#include "applicationsettings.h" #include "imageinfo.h" #include "itemviewcategorized.h" #include "thumbnailsize.h" @@ -78,23 +77,10 @@ ImageInfo currentInfo() const; QUrl currentUrl() const; - ImageInfo imageInfo(const QModelIndex& index) const; - ImageInfoList imageInfos(const QList& indexes, - bool grouping = false) const; - ImageInfoList imageInfos(const QList& indexes, - ApplicationSettings::OperationType type) const; - - ImageInfoList selectedImageInfos(bool grouping = false) const; - ImageInfoList selectedImageInfos(ApplicationSettings::OperationType type) const; - ImageInfoList selectedImageInfosCurrentFirst(bool grouping = false) const; - QList selectedUrls(bool grouping = false) const; - QList selectedUrls(ApplicationSettings::OperationType type) const; - - ImageInfoList allImageInfos(bool grouping = false) const; - QList allUrls(bool grouping = false) const; - - bool needGroupResolving(ApplicationSettings::OperationType type, - bool all = false) const; + ImageInfoList allImageInfos() const; + QList allUrls() const; + ImageInfoList selectedImageInfos() const; + ImageInfoList selectedImageInfosCurrentFirst() const; /** Selects the index as current and scrolls to it. */ @@ -218,13 +204,8 @@ virtual void showContextMenuOnInfo(QContextMenuEvent* event, const ImageInfo& info); virtual void showContextMenuOnIndex(QContextMenuEvent* event, const QModelIndex& index); - // Adds group members when appropriate - ImageInfoList resolveGrouping(const QModelIndexList& indexes) const; - ImageInfoList resolveGrouping(const ImageInfoList& infos) const; - bool needGroupResolving(ApplicationSettings::OperationType type, - const QList& indexes) const; - bool needGroupResolving(ApplicationSettings::OperationType type, - const ImageInfoList& infos) const; + ImageInfo imageInfo(const QModelIndex& index) const; + ImageInfoList imageInfos(const QList& indexes) const; private Q_SLOTS: diff --git a/core/app/items/imagecategorizedview.cpp b/core/app/items/imagecategorizedview.cpp --- a/core/app/items/imagecategorizedview.cpp +++ b/core/app/items/imagecategorizedview.cpp @@ -303,32 +303,27 @@ return d->filterModel->imageInfo(index); } -ImageInfoList ImageCategorizedView::imageInfos(const QList& indexes, - ApplicationSettings::OperationType type) const +ImageInfoList ImageCategorizedView::imageInfos(const QList& indexes) const { - return imageInfos(indexes, needGroupResolving(type, indexes)); + return d->filterModel->imageInfos(indexes); } -ImageInfoList ImageCategorizedView::imageInfos(const QList& indexes, bool grouping) const +ImageInfoList ImageCategorizedView::allImageInfos() const { - if (grouping) { - return resolveGrouping(indexes); - } - return d->filterModel->imageInfos(indexes); + return d->filterModel->imageInfosSorted(); } -ImageInfoList ImageCategorizedView::selectedImageInfos(bool grouping) const +QList ImageCategorizedView::allUrls() const { - return imageInfos(selectedIndexes(), grouping); + return allImageInfos().toImageUrlList(); } -ImageInfoList ImageCategorizedView::selectedImageInfos( - ApplicationSettings::OperationType type) const +ImageInfoList ImageCategorizedView::selectedImageInfos() const { - return selectedImageInfos(needGroupResolving(type)); + return imageInfos(selectedIndexes()); } -ImageInfoList ImageCategorizedView::selectedImageInfosCurrentFirst(bool grouping) const +ImageInfoList ImageCategorizedView::selectedImageInfosCurrentFirst() const { QModelIndexList indexes = selectedIndexes(); const QModelIndex current = currentIndex(); @@ -344,61 +339,9 @@ } } - if (grouping) { - return resolveGrouping(indexes); - } return imageInfos(indexes); } -ImageInfoList ImageCategorizedView::allImageInfos(bool grouping) const -{ - if (grouping) { - return resolveGrouping(d->filterModel->imageInfosSorted()); - } - return d->filterModel->imageInfosSorted(); -} - -QList ImageCategorizedView::allUrls(bool grouping) const -{ - ImageInfoList infos = allImageInfos(grouping); - QList urls; - - foreach(const ImageInfo& info, infos) - { - urls << info.fileUrl(); - } - - return urls; -} - -bool ImageCategorizedView::needGroupResolving(ApplicationSettings::OperationType type, bool all) const -{ - if (all) - { - return needGroupResolving(type, allImageInfos()); - } - - return needGroupResolving(type, selectedIndexes()); -} - -QList ImageCategorizedView::selectedUrls(bool grouping) const -{ - ImageInfoList infos = selectedImageInfos(grouping); - QList urls; - - foreach(const ImageInfo& info, infos) - { - urls << info.fileUrl(); - } - - return urls; -} - -QList ImageCategorizedView::selectedUrls(ApplicationSettings::OperationType type) const -{ - return selectedUrls(needGroupResolving(type)); -} - void ImageCategorizedView::toIndex(const QUrl& url) { ItemViewCategorized::toIndex(d->filterModel->indexForPath(url.toLocalFile())); @@ -765,61 +708,6 @@ // implemented in subclass } -ImageInfoList ImageCategorizedView::resolveGrouping(const QModelIndexList& indexes) const -{ - return resolveGrouping(imageInfos(indexes)); -} - -ImageInfoList ImageCategorizedView::resolveGrouping(const ImageInfoList& infos) const -{ - ImageInfoList outInfos; - - foreach(const ImageInfo& info, infos) - { - outInfos << info; - - if (info.hasGroupedImages() && !imageFilterModel()->isGroupOpen(info.id())) - { - outInfos << info.groupedImages(); - } - } - - return outInfos; -} - -bool ImageCategorizedView::needGroupResolving(ApplicationSettings::OperationType type, - const QList& indexes) const -{ - return needGroupResolving(type, imageInfos(indexes)); -} - -bool ImageCategorizedView::needGroupResolving(ApplicationSettings::OperationType type, - const ImageInfoList& infos) const -{ - ApplicationSettings::ApplyToEntireGroup applyAll = - ApplicationSettings::instance()->getGroupingOperateOnAll(type); - - if (applyAll == ApplicationSettings::No) - { - return false; - } - else if (applyAll == ApplicationSettings::Yes) - { - return true; - } - - foreach(const ImageInfo& info, infos) - { - if (info.hasGroupedImages() && !imageFilterModel()->isGroupOpen(info.id())) - { - // Ask whether should be performed on all and return info if no - return ApplicationSettings::instance()->askGroupingOperateOnAll(type); - } - } - - return false; -} - void ImageCategorizedView::paintEvent(QPaintEvent* e) { // We want the thumbnails to be loaded in order. diff --git a/core/app/utils/groupingviewimplementation.h b/core/app/utils/groupingviewimplementation.h new file mode 100644 --- /dev/null +++ b/core/app/utils/groupingviewimplementation.h @@ -0,0 +1,55 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2017-11-02 + * Description : Implementation of grouping specific functions for views + * + * Copyright (C) 2017 by Simon Frei + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * ============================================================ */ + +#ifndef VIEWGROUPINGIMPLEMENTATION_H +#define VIEWGROUPINGIMPLEMENTATION_H + +// Local includes + +#include "applicationsettings.h" +#include "digikam_export.h" + +namespace Digikam +{ + +class ImageInfo; +class ImageInfoList; + +class DIGIKAM_EXPORT GroupingViewImplementation +{ +public: + + virtual ~GroupingViewImplementation() {} + + // must be implemented by parent view + virtual bool hasHiddenGroupedImages(const ImageInfo&) const {return false;} + + bool needGroupResolving(ApplicationSettings::OperationType type, + const ImageInfoList& infos) const; + ImageInfoList resolveGrouping(const ImageInfoList& infos) const; + ImageInfoList getHiddenGroupedInfos(const ImageInfoList& infos) const; +}; + +} // namespace Digikam + +#endif /* VIEWGROUPINGIMPLEMENTATION_H */ diff --git a/core/app/utils/groupingviewimplementation.cpp b/core/app/utils/groupingviewimplementation.cpp new file mode 100644 --- /dev/null +++ b/core/app/utils/groupingviewimplementation.cpp @@ -0,0 +1,94 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2017-11-02 + * Description : Implementation of grouping specific functions for views + * + * Copyright (C) 2017 by Simon Frei + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * ============================================================ */ + +#include "groupingviewimplementation.h" + +// Local includes + +#include "imageinfolist.h" + +// Qt includes + +#include + +namespace Digikam +{ + +bool GroupingViewImplementation::needGroupResolving(ApplicationSettings::OperationType type, const ImageInfoList& infos) const +{ + ApplicationSettings::ApplyToEntireGroup applyAll = + ApplicationSettings::instance()->getGroupingOperateOnAll(type); + + if (applyAll == ApplicationSettings::No) + { + return false; + } + + foreach(const ImageInfo& info, infos) + { + if (hasHiddenGroupedImages(info)) + { + if (applyAll == ApplicationSettings::Yes) + { + return true; + } + return ApplicationSettings::instance()->askGroupingOperateOnAll(type); + } + } + + return false; +} + +ImageInfoList GroupingViewImplementation::resolveGrouping(const ImageInfoList& infos) const +{ + ImageInfoList outInfos; + + foreach(const ImageInfo& info, infos) + { + outInfos << info; + + if (hasHiddenGroupedImages(info)) + { + outInfos << info.groupedImages(); + } + } + + return outInfos; +} + +ImageInfoList GroupingViewImplementation::getHiddenGroupedInfos(const ImageInfoList& infos) const +{ + ImageInfoList outInfos; + + foreach(const ImageInfo& info, infos) + { + if (hasHiddenGroupedImages(info)) + { + outInfos << info.groupedImages(); + } + } + + return outInfos; +} + +} // namespace Digikam diff --git a/core/app/views/digikamview.h b/core/app/views/digikamview.h --- a/core/app/views/digikamview.h +++ b/core/app/views/digikamview.h @@ -119,17 +119,12 @@ ImageInfoList allInfo(const ApplicationSettings::OperationType type) const; /** - * Query whether the operation to be performed on currently selected items - * (all=false, default) or all items in the currently active view (all=true) - * should be performed on all grouped items or just the first. - * - * @brief needGroupResolving - * @param type Type of operation to be performed. - * @param all Whether to apply to all items in the current view or just selected - * @return Whether to perform operation on all grouped items or just the first + * Query whether the operation to be performed on currently selected or all + * all items in the currently active view should be performed on all + * grouped items or just the first. */ - bool needGroupResolving(const ApplicationSettings::OperationType type, - const bool all = false) const; + bool allNeedGroupResolving(const ApplicationSettings::OperationType type) const; + bool selectedNeedGroupResolving(const ApplicationSettings::OperationType type) const; double zoomMin() const; double zoomMax() const; diff --git a/core/app/views/digikamview.cpp b/core/app/views/digikamview.cpp --- a/core/app/views/digikamview.cpp +++ b/core/app/views/digikamview.cpp @@ -803,31 +803,17 @@ { /// @todo This functions seems not to be used anywhere right now - switch (viewMode()) - { - case StackedView::TableViewMode: - return d->tableView->allUrls(grouping); - - default: - return d->iconView->allUrls(grouping); - } + return allInfo(grouping).toImageUrlList(); } QList DigikamView::selectedUrls(bool grouping) const { - switch (viewMode()) - { - case StackedView::TableViewMode: - return d->tableView->selectedUrls(grouping); - - default: - return d->iconView->selectedUrls(grouping); - } + return selectedInfoList(grouping).toImageUrlList(); } QList DigikamView::selectedUrls(const ApplicationSettings::OperationType type) const { - return selectedUrls(needGroupResolving(type)); + return selectedInfoList(type).toImageUrlList(); } void DigikamView::showSideBars() @@ -1794,12 +1780,12 @@ void DigikamView::slotLightTable() { - bool grouping = needGroupResolving(ApplicationSettings::LightTable); + bool grouping = selectedNeedGroupResolving(ApplicationSettings::LightTable); const ImageInfoList selectedList = selectedInfoList(false, grouping); if (selectedList.isEmpty()) { - grouping = needGroupResolving(ApplicationSettings::LightTable, true); + grouping = allNeedGroupResolving(ApplicationSettings::LightTable); } const ImageInfoList allInfoList = allInfo(grouping); @@ -1810,7 +1796,7 @@ void DigikamView::slotQueueMgr() { - bool grouping = needGroupResolving(ApplicationSettings::BQM); + bool grouping = selectedNeedGroupResolving(ApplicationSettings::BQM); ImageInfoList imageInfoList = selectedInfoList(false, grouping); ImageInfo singleInfo = currentInfo(); @@ -1821,7 +1807,7 @@ if (singleInfo.isNull()) { - grouping = needGroupResolving(ApplicationSettings::BQM, true); + grouping = allNeedGroupResolving(ApplicationSettings::BQM); const ImageInfoList allItems = allInfo(grouping); if (!allItems.isEmpty()) @@ -2444,15 +2430,15 @@ ImageInfoList DigikamView::selectedInfoList(const ApplicationSettings::OperationType type, const bool currentFirst) const { - return selectedInfoList(currentFirst, needGroupResolving(type)); + return selectedInfoList(currentFirst, selectedNeedGroupResolving(type)); } ImageInfoList DigikamView::allInfo(const bool grouping) const { switch (viewMode()) { case StackedView::TableViewMode: - return d->tableView->allInfo(grouping); + return d->tableView->allImageInfos(grouping); case StackedView::MapWidgetMode: case StackedView::PreviewImageMode: @@ -2468,23 +2454,38 @@ ImageInfoList DigikamView::allInfo(const ApplicationSettings::OperationType type) const { - return allInfo(needGroupResolving(type, true)); + return allInfo(allNeedGroupResolving(type)); } -bool DigikamView::needGroupResolving(const ApplicationSettings::OperationType type, - const bool all) const +bool DigikamView::allNeedGroupResolving(const ApplicationSettings::OperationType type) const { switch (viewMode()) { case StackedView::TableViewMode: - return d->tableView->needGroupResolving(type, all); + return d->tableView->allNeedGroupResolving(type); case StackedView::MapWidgetMode: case StackedView::PreviewImageMode: case StackedView::MediaPlayerMode: case StackedView::IconViewMode: // all of these modes use the same selection model and data as the IconViewMode - return d->iconView->needGroupResolving(type, all); + return d->iconView->allNeedGroupResolving(type); + default: + return false; + } +} +bool DigikamView::selectedNeedGroupResolving(const ApplicationSettings::OperationType type) const +{ + switch (viewMode()) + { + case StackedView::TableViewMode: + return d->tableView->selectedNeedGroupResolving(type); + case StackedView::MapWidgetMode: + case StackedView::PreviewImageMode: + case StackedView::MediaPlayerMode: + case StackedView::IconViewMode: + // all of these modes use the same selection model and data as the IconViewMode + return d->iconView->selectedNeedGroupResolving(type); default: return false; } diff --git a/core/app/views/tableview/tableview.h b/core/app/views/tableview/tableview.h --- a/core/app/views/tableview/tableview.h +++ b/core/app/views/tableview/tableview.h @@ -67,8 +67,6 @@ ThumbnailSize getThumbnailSize() const; ImageInfo currentInfo() const; Album* currentAlbum() const; - ImageInfoList allInfo(bool grouping = false) const; - QList allUrls(bool grouping = false) const; int numberOfSelectedItems() const; ImageInfo nextInfo() const; ImageInfo previousInfo() const; @@ -78,15 +76,11 @@ void clearSelection(); void invertSelection(); - QModelIndexList selectedIndexesCurrentFirst() const; - ImageInfoList selectedImageInfos(bool grouping = false) const; - ImageInfoList selectedImageInfos(ApplicationSettings::OperationType type) const; - ImageInfoList selectedImageInfosCurrentFirst(bool grouping = false) const; - QList selectedImageIdsCurrentFirst(bool grouping = false) const; - QList selectedUrls(bool grouping = false) const; - - bool needGroupResolving(ApplicationSettings::OperationType type, - bool all = false) const; + ImageInfoList allImageInfos(bool grouping = false) const; + ImageInfoList selectedImageInfos(bool grouping = false) const; + ImageInfoList selectedImageInfosCurrentFirst(bool grouping = false) const; + bool allNeedGroupResolving(const ApplicationSettings::OperationType type) const; + bool selectedNeedGroupResolving(const ApplicationSettings::OperationType type) const; protected: @@ -96,10 +90,6 @@ virtual bool eventFilter(QObject* watched, QEvent* event); QList getExtraGroupingActions(); - // Adds group members when appropriate - ImageInfoList resolveGrouping(const QList& indexes) const; - ImageInfoList resolveGrouping(const ImageInfoList& infos) const; - public Q_SLOTS: void slotGoToRow(const int rowNumber, const bool relativeMove); diff --git a/core/app/views/tableview/tableview.cpp b/core/app/views/tableview/tableview.cpp --- a/core/app/views/tableview/tableview.cpp +++ b/core/app/views/tableview/tableview.cpp @@ -39,6 +39,7 @@ #include "advancedrenamedialog.h" #include "advancedrenameprocessdialog.h" +#include "applicationsettings.h" #include "contextmenuhelper.h" #include "digikam_debug.h" #include "fileactionmngr.h" @@ -183,7 +184,7 @@ } else { - d->imageViewUtilities->openInfos(info, allInfo(), currentAlbum()); + d->imageViewUtilities->openInfos(info, allImageInfos(), currentAlbum()); } } else @@ -264,16 +265,26 @@ return s->tableViewModel->imageInfo(s->tableViewSelectionModel->currentIndex()); } -ImageInfoList TableView::allInfo(bool grouping) const +ImageInfoList TableView::allImageInfos(bool grouping) const { if (grouping) { - return resolveGrouping(s->tableViewModel->allImageInfo()); + return s->treeView->resolveGrouping(s->tableViewModel->allImageInfo()); } return s->tableViewModel->allImageInfo(); } +bool TableView::allNeedGroupResolving(const ApplicationSettings::OperationType type) const +{ + return s->treeView->needGroupResolving(type, allImageInfos()); +} + +bool TableView::selectedNeedGroupResolving(const ApplicationSettings::OperationType type) const +{ + return s->treeView->needGroupResolving(type, selectedImageInfos()); +} + void TableView::slotDeleteSelected(const ImageViewUtilities::DeleteMode deleteMode) { const ImageInfoList infoList = selectedImageInfos(true); @@ -345,19 +356,6 @@ s->tableViewModel->setGroupingMode(newGroupingMode); } -QList TableView::allUrls(bool grouping) const -{ - const ImageInfoList infos = allInfo(grouping); - QList resultList; - - foreach(const ImageInfo& info, infos) - { - resultList << info.fileUrl(); - } - - return resultList; -} - int TableView::numberOfSelectedItems() const { return s->tableViewSelectionModel->selectedRows().count(); @@ -569,18 +567,14 @@ ImageInfoList TableView::selectedImageInfos(bool grouping) const { + ImageInfoList infos = s->tableViewModel->imageInfos(s->tableViewSelectionModel->selectedRows()); if (grouping) { - return resolveGrouping(s->tableViewSelectionModel->selectedRows()); + return s->treeView->resolveGrouping(infos); } - return s->tableViewModel->imageInfos(s->tableViewSelectionModel->selectedRows()); -} - -ImageInfoList TableView::selectedImageInfos(ApplicationSettings::OperationType type) const -{ - return selectedImageInfos(needGroupResolving(type)); + return infos; } -QModelIndexList TableView::selectedIndexesCurrentFirst() const +ImageInfoList TableView::selectedImageInfosCurrentFirst(bool grouping) const { QModelIndexList indexes = s->tableViewSelectionModel->selectedRows(); const QModelIndex current = s->tableViewModel->toCol0(s->tableViewSelectionModel->currentIndex()); @@ -596,100 +590,22 @@ } } - return indexes; -} - -ImageInfoList TableView::selectedImageInfosCurrentFirst(bool grouping) const -{ if (grouping) { - return resolveGrouping(selectedIndexesCurrentFirst()); - } - return s->tableViewModel->imageInfos(selectedIndexesCurrentFirst()); -} - -QList TableView::selectedImageIdsCurrentFirst(bool grouping) const -{ - return selectedImageInfosCurrentFirst(grouping).toImageIdList(); -} - -QList TableView::selectedUrls(bool grouping) const -{ - return selectedImageInfos(grouping).toImageUrlList(); -} - -ImageInfoList TableView::resolveGrouping(const QList& indexes) const -{ - return resolveGrouping(s->tableViewModel->imageInfos(indexes)); -} - -ImageInfoList TableView::resolveGrouping(const ImageInfoList& infos) const -{ - ImageInfoList out; - - foreach(const ImageInfo& info, infos) - { - QModelIndex index = s->tableViewModel->indexFromImageId(info.id(), 0); - - out << info; - - if (info.hasGroupedImages() - && (s->tableViewModel->groupingMode() == s->tableViewModel->GroupingMode::GroupingHideGrouped - || (s->tableViewModel->groupingMode() == s->tableViewModel->GroupingMode::GroupingShowSubItems - && !s->treeView->isExpanded(index)))) - { - out << info.groupedImages(); - } + return s->treeView->resolveGrouping(s->tableViewModel->imageInfos(indexes)); } - - return out; + return s->tableViewModel->imageInfos(indexes); } -bool TableView::needGroupResolving(ApplicationSettings::OperationType type, bool all) const +void TableView::rename() { - ApplicationSettings::ApplyToEntireGroup applyAll = - ApplicationSettings::instance()->getGroupingOperateOnAll(type); - - if (applyAll == ApplicationSettings::No) + ImageInfoList infos = selectedImageInfos(); + if (s->treeView->needGroupResolving(ApplicationSettings::Rename, infos)) { - return false; - } - else if (applyAll == ApplicationSettings::Yes) - { - return true; + infos = s->treeView->resolveGrouping(infos); } - ImageInfoList infos; + QList urls = infos.toImageUrlList(); - if (all) - { - infos = s->tableViewModel->allImageInfo(); - } - else - { - infos = s->tableViewModel->imageInfos(s->tableViewSelectionModel->selectedRows()); - } - - foreach(const ImageInfo& info, infos) - { - QModelIndex index = s->tableViewModel->indexFromImageId(info.id(), 0); - - if (info.hasGroupedImages() - && (s->tableViewModel->groupingMode() == s->tableViewModel->GroupingMode::GroupingHideGrouped - || (s->tableViewModel->groupingMode() == s->tableViewModel->GroupingMode::GroupingShowSubItems - && !s->treeView->isExpanded(index)))) - { - // Ask whether should be performed on all and return info if no - return ApplicationSettings::instance()->askGroupingOperateOnAll(type); - } - } - - return false; -} - -void TableView::rename() -{ - bool grouping = needGroupResolving(ApplicationSettings::Rename); - QList urls = selectedUrls(grouping); bool loop = false; NewNamesList newNamesList; diff --git a/core/app/views/tableview/tableview_treeview.h b/core/app/views/tableview/tableview_treeview.h --- a/core/app/views/tableview/tableview_treeview.h +++ b/core/app/views/tableview/tableview_treeview.h @@ -38,6 +38,7 @@ #include "tableview_columnfactory.h" #include "tableview_shared.h" #include "thumbnailloadthread.h" +#include "groupingviewimplementation.h" class QMenu; class QContextMenuEvent; @@ -49,7 +50,7 @@ /// of DragDropModelImplementation's functions in the TableViewModel or /// in the sort model. Subclassing DragDropModelImplementation would not /// work there, because we want to re-use ImageDragDropHandler... -class TableViewTreeView : public QTreeView, public DragDropViewImplementation +class TableViewTreeView : public QTreeView, public DragDropViewImplementation, public GroupingViewImplementation { Q_OBJECT @@ -71,6 +72,8 @@ virtual QPixmap pixmapForDrag(const QList& indexes) const; virtual void wheelEvent(QWheelEvent* event); + virtual bool hasHiddenGroupedImages(const ImageInfo& info) const; + private: void addColumnDescriptionsToMenu(const QList& columnDescriptions, QMenu* const menu); diff --git a/core/app/views/tableview/tableview_treeview.cpp b/core/app/views/tableview/tableview_treeview.cpp --- a/core/app/views/tableview/tableview_treeview.cpp +++ b/core/app/views/tableview/tableview_treeview.cpp @@ -330,6 +330,14 @@ QTreeView::wheelEvent(event); } +bool TableViewTreeView::hasHiddenGroupedImages(const ImageInfo& info) const +{ + return (info.hasGroupedImages() + && (s->tableViewModel->groupingMode() == s->tableViewModel->GroupingMode::GroupingHideGrouped + || (s->tableViewModel->groupingMode() == s->tableViewModel->GroupingMode::GroupingShowSubItems + && !s->treeView->isExpanded(s->tableViewModel->indexFromImageId(info.id(), 0))))); +} + void TableViewTreeView::slotModelGroupingModeChanged() { setRootIsDecorated(s->tableViewModel->groupingMode()==TableViewModel::GroupingShowSubItems); diff --git a/core/libs/database/utils/dbinfoiface.cpp b/core/libs/database/utils/dbinfoiface.cpp --- a/core/libs/database/utils/dbinfoiface.cpp +++ b/core/libs/database/utils/dbinfoiface.cpp @@ -256,7 +256,7 @@ } withGroupedIsSet = true; - withGrouped = DigikamApp::instance()->view()->needGroupResolving(operationType, true); + withGrouped = DigikamApp::instance()->view()->allNeedGroupResolving(operationType); return withGrouped; }