diff --git a/CMakeLists.txt b/CMakeLists.txt index 99caf6bc..23069ad5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,88 +1,89 @@ project(zanshin) cmake_minimum_required(VERSION 3.2) find_package(ECM REQUIRED CONFIG) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH}) include(GenerateExportHeader) include(KDEInstallDirs) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(FeatureSummary) include(ECMInstallIcons) include(ECMMarkAsTest) include(ECMPoQmTools) +set(REQUIRED_QT_VERSION 5.10.0) find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Core Gui Widgets Test) find_package(Boost REQUIRED) find_package(Threads REQUIRED) macro(assert_min_ver version) set(error_msg "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_VERSION} not supported") if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "${version}") message(FATAL_ERROR "${msg}") endif() endmacro() if(APPLE) if((NOT "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "6.0.0.0") AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "6.0.0.6000058") # Apple Clang 6.0.0.6000057 is known to fail on some of our code using std::mem_fn # but have no issues with boost::mem_fn message("problematic Apple Clang version ${CMAKE_CXX_COMPILER_VERSION}, using boost::mem_fn") add_definitions(-DZANSHIN_USE_BOOST_MEM_FN) endif() endif() if(UNIX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") set(CMAKE_CXX_STANDARD 14) # Enable C++14, with cmake >= 3.1 set(CMAKE_CXX_EXTENSIONS OFF) # Don't enable gcc-specific extensions endif() kde_enable_exceptions() if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") endif() option(ZANSHIN_BUILD_COVERAGE "Build Zanshin with gcov support" OFF) if(ZANSHIN_BUILD_COVERAGE AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") endif() option(ZANSHIN_BUILD_ASAN "Build Zanshin with asan support" OFF) if(ZANSHIN_BUILD_ASAN) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") link_libraries("asan") endif() add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS -DQT_NO_URL_CAST_FROM_STRING -DQT_STRICT_ITERATORS ) include_directories ( ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${Boost_INCLUDE_DIR} 3rdparty/kdepim/ 3rdparty/kdepim/libkdepim/ ) find_package(KF5 REQUIRED COMPONENTS AkonadiCalendar KontactInterface Runner WindowSystem I18n ) find_package(KF5Akonadi "5.1" CONFIG REQUIRED) add_subdirectory(3rdparty) add_subdirectory(src) if(BUILD_TESTING) add_subdirectory(tests) endif() diff --git a/src/widgets/quickselectdialog.cpp b/src/widgets/quickselectdialog.cpp index 625da602..7949c38a 100644 --- a/src/widgets/quickselectdialog.cpp +++ b/src/widgets/quickselectdialog.cpp @@ -1,129 +1,130 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens Copyright 2015 Franck Arrecot 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 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "quickselectdialog.h" #include #include #include #include #include +#include #include #include #include -#include using namespace Widgets; QuickSelectDialog::QuickSelectDialog(QWidget *parent) : QDialog(parent), m_model(nullptr), - m_filterProxyModel(new KRecursiveFilterProxyModel(this)), + m_filterProxyModel(new QSortFilterProxyModel(this)), m_label(new QLabel(this)), m_tree(new QTreeView(this)) { setWindowTitle(i18n("Quick Select Dialog")); m_label->setText(i18n("You can start typing to filter the list of available pages")); m_filterProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + m_filterProxyModel->setRecursiveFilteringEnabled(true); m_tree->setModel(m_filterProxyModel); m_tree->setObjectName(QStringLiteral("pagesView")); m_tree->header()->hide(); m_tree->expandAll(); m_tree->setFocus(); m_tree->setSelectionMode(QAbstractItemView::SingleSelection); m_tree->setSortingEnabled(false); m_tree->installEventFilter(this); auto buttonBox = new QDialogButtonBox(this); buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); auto mainLayout = new QVBoxLayout(this); mainLayout->addWidget(m_label); mainLayout->addWidget(m_tree); mainLayout->addWidget(buttonBox); connect(buttonBox, &QDialogButtonBox::accepted, this, &QuickSelectDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &QuickSelectDialog::reject); } int QuickSelectDialog::exec() { return QDialog::exec(); } QPersistentModelIndex QuickSelectDialog::selectedIndex() const { QModelIndex selected = m_tree->currentIndex(); return m_filterProxyModel->mapToSource(selected); } void QuickSelectDialog::applyFilterChanged(const QString &textFilter) { if (textFilter.isEmpty()) m_label->setText(i18n("You can start typing to filter the list of available pages")); else m_label->setText(i18n("Path: %1", textFilter)); m_filterProxyModel->setFilterFixedString(textFilter); m_tree->expandAll(); } bool QuickSelectDialog::eventFilter(QObject *, QEvent *ev) { if (ev->type() == QEvent::KeyPress) { auto event = static_cast(ev); auto filter = m_filterProxyModel->filterRegExp().pattern(); switch (event->key()) { case Qt::Key_Backspace: filter.chop(1); break; case Qt::Key_Delete: filter = QString(); break; default: if (event->text().contains(QRegExp("^(\\w| )+$"))) { filter += event->text(); } break; } applyFilterChanged(filter); } return false; } void QuickSelectDialog::setModel(QAbstractItemModel *model) { if (model == m_model) return; m_model = model; m_filterProxyModel->setSourceModel(m_model); m_tree->expandAll(); } diff --git a/src/widgets/quickselectdialog.h b/src/widgets/quickselectdialog.h index 84b5a00a..9da0b140 100644 --- a/src/widgets/quickselectdialog.h +++ b/src/widgets/quickselectdialog.h @@ -1,70 +1,70 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens Copyright 2015 Franck Arrecot 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 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef WIDGETS_QUICKSELECTDIALOG_H #define WIDGETS_QUICKSELECTDIALOG_H #include #include #include #include "presentation/metatypes.h" #include "widgets/quickselectdialoginterface.h" class QAbstractItemModel; class QLabel; class QTreeView; -class KRecursiveFilterProxyModel; +class QSortFilterProxyModel; namespace Widgets { class QuickSelectDialog : public QDialog, public QuickSelectDialogInterface { Q_OBJECT public: explicit QuickSelectDialog(QWidget *parent = nullptr); int exec() override; QPersistentModelIndex selectedIndex() const override; void setModel(QAbstractItemModel *model) override; private slots: void applyFilterChanged(const QString &textFilter); bool eventFilter(QObject *object, QEvent *ev) override; private: QString m_filter; QAbstractItemModel *m_model; - KRecursiveFilterProxyModel *m_filterProxyModel; + QSortFilterProxyModel *m_filterProxyModel; QLabel *m_label; QTreeView *m_tree; }; } #endif // WIDGETS_QUICKSELECTDIALOG_H