From: Tsu Jan Date: Sun, 27 Jan 2019 03:43:38 +0000 (+0330) Subject: Added missing sort-by-group action X-Git-Tag: archive/raspbian/0.14.0-3+rpi1~1^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=4b61d5bfa97493a5e80a14b435bf017d55bb7364;p=libfm-qt.git Added missing sort-by-group action This is related to https://github.com/lxqt/pcmanfm-qt/issues/886 and will be followed by a pcmanfm-qt patch, which should be applied immediately after it (otherwie, a crash will happen). Gbp-Pq: Name sort-by-group-action.patch --- diff --git a/src/foldermenu.cpp b/src/foldermenu.cpp index 1a87dd0..86675d5 100644 --- a/src/foldermenu.cpp +++ b/src/foldermenu.cpp @@ -142,13 +142,14 @@ void FolderMenu::onCustomActionTrigerred() { } } -void FolderMenu::addSortMenuItem(QString title, int id) { +void FolderMenu::addSortMenuItem(const QString &title, int id) { QAction* action = new QAction(title, this); + action->setData(QVariant(id)); sortMenu_->addAction(action); action->setCheckable(true); + action->setChecked(id == view_->model()->sortColumn()); sortActionGroup_->addAction(action); connect(action, &QAction::triggered, this, &FolderMenu::onSortActionTriggered); - sortActions_[id] = action; } void FolderMenu::createSortMenu() { @@ -158,19 +159,12 @@ void FolderMenu::createSortMenu() { sortActionGroup_ = new QActionGroup(sortMenu_); sortActionGroup_->setExclusive(true); - std::memset(sortActions_, 0, sizeof(sortActions_)); - addSortMenuItem(tr("By File Name"), FolderModel::ColumnFileName); addSortMenuItem(tr("By Modification Time"), FolderModel::ColumnFileMTime); addSortMenuItem(tr("By File Size"), FolderModel::ColumnFileSize); addSortMenuItem(tr("By File Type"), FolderModel::ColumnFileType); addSortMenuItem(tr("By File Owner"), FolderModel::ColumnFileOwner); - - int col = model->sortColumn(); - - if(col >= 0 && col < FolderModel::NumOfColumns) { - sortActions_[col]->setChecked(true);; - } + addSortMenuItem(tr("By File Group"), FolderModel::ColumnFileGroup); sortMenu_->addSeparator(); @@ -237,12 +231,16 @@ void FolderMenu::onInvertSelectionActionTriggered() { void FolderMenu::onSortActionTriggered(bool /*checked*/) { ProxyFolderModel* model = view_->model(); - if(model) { + if(model && sortActionGroup_) { QAction* action = static_cast(sender()); - for(int col = 0; col < FolderModel::NumOfColumns; ++col) { - if(action == sortActions_[col]) { - model->sort(col, model->sortOrder()); + const auto actions = sortActionGroup_->actions(); + for(auto a : actions) { + if(a == action) { + int col = a->data().toInt(); + if(col >= 0 && col < FolderModel::NumOfColumns) { + model->sort(col, model->sortOrder()); + } break; } } diff --git a/src/foldermenu.h b/src/foldermenu.h index d533c1d..eb7ec4c 100644 --- a/src/foldermenu.h +++ b/src/foldermenu.h @@ -104,7 +104,7 @@ protected Q_SLOTS: private: void createSortMenu(); - void addSortMenuItem(QString title, int id); + void addSortMenuItem(const QString &title, int id); private: FolderView* view_; @@ -118,7 +118,6 @@ private: QAction* sortAction_; QActionGroup* sortActionGroup_; QMenu* sortMenu_; - QAction* sortActions_[FolderModel::NumOfColumns]; QAction* actionAscending_; QAction* actionDescending_; QAction* showHiddenAction_;