diff --git a/keduvocdocument/CMakeLists.txt b/keduvocdocument/CMakeLists.txt index d285288..1177bbc 100644 --- a/keduvocdocument/CMakeLists.txt +++ b/keduvocdocument/CMakeLists.txt @@ -1,144 +1,146 @@ if (BUILD_TESTING) add_subdirectory(autotests) add_subdirectory(tests) endif() ########### next target ############### include(ECMSetupVersion) ecm_setup_version(5.0.0 VARIABLE_PREFIX KDEEDU VERSION_HEADER "${CMAKE_BINARY_DIR}/keduvocdocument/keduvocdocument_version.h" PACKAGE_VERSION_FILE "${CMAKE_BINARY_DIR}/KEduVocDocumentVersion.cmake") include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) set(keduvocdocument_LIB_SRCS keduvocdocument.cpp keduvocidentifier.cpp keduvocexpression.cpp keduvoctranslation.cpp keduvoccontainer.cpp keduvoclesson.cpp keduvocleitnerbox.cpp keduvoctext.cpp keduvocarticle.cpp keduvocconjugation.cpp keduvocpersonalpronoun.cpp keduvocdeclension.cpp keduvocwordtype.cpp keduvockvtmlcompability.cpp keduvockvtml2writer.cpp keduvoccsvwriter.cpp keduvoccontainermodel.cpp keduvoclessonmodel.cpp keduvocreadonlycontainermodel.cpp keduvocvocabularymodel.cpp keduvocwordclassmodel.cpp keduvoccontainermimedata.cpp keduvocvocabularymimedata.cpp + keduvocvocabularyfilter.cpp readerwriters/dummyreader.cpp readerwriters/failedreader.cpp readerwriters/keduvockvtmlreader.cpp readerwriters/keduvockvtml2reader.cpp readerwriters/keduvoccsvreader.cpp readerwriters/keduvocpaukerreader.cpp readerwriters/keduvocvokabelnreader.cpp readerwriters/keduvocwqlreader.cpp readerwriters/keduvocxdxfreader.cpp readerwriters/readermanager.cpp sharedkvtmlfiles.cpp ) include(ECMGenerateHeaders) ecm_generate_headers( KdeEdu_HEADERS HEADER_NAMES KEduVocDocument KEduVocIdentifier KEduVocExpression KEduVocText KEduVocArticle KEduVocConjugation KEduVocLesson KEduVocLeitnerBox KEduVocContainer KEduVocWordFlags KEduVocMultipleChoice KEduVocTranslation KEduVocWordtype KEduVocPersonalPronoun SharedKVTMLFiles KEduVocDeclension KEduVocKVTML2Writer KEduVocContainerModel KEduVocLessonModel KEduVocReadOnlyContainerModel KEduVocVocabularyModel KEduVocWordClassModel KEduVocContainerMimeData KEduVocVocabularyMimeData + KEduVocVocabularyFilter REQUIRED_HEADERS KdeEdu_HEADERS ) add_library(KEduVocDocument SHARED ${keduvocdocument_LIB_SRCS}) generate_export_header(KEduVocDocument BASE_NAME KEduVocDocument) # vHanda: Add library alias? target_link_libraries(KEduVocDocument PUBLIC Qt5::Xml Qt5::Gui Qt5::Core PRIVATE KF5::I18n KF5::KIOCore KF5::Archive ) # vHanda: Add Export Name? set_target_properties(KEduVocDocument PROPERTIES VERSION ${KDEEDU_VERSION_STRING} SOVERSION ${KDEEDU_SOVERSION} ) target_include_directories(KEduVocDocument INTERFACE "$") #Library for non-api unittests add_library(keduvocdocument_static STATIC ${keduvocdocument_LIB_SRCS}) set_target_properties(keduvocdocument_static PROPERTIES COMPILE_FLAGS -DKEDUVOCDOCUMENT_STATIC_DEFINE) target_link_libraries(keduvocdocument_static PUBLIC KF5::KIOCore Qt5::Xml Qt5::Core Qt5::Gui PRIVATE KF5::I18n KF5::Archive ) # if we want to set our own version instead of following kde generic #set(LIB_KEDUVOCDOCUMENT_VERSION "5.0.0") #set(LIB_KEDUVOCDOCUMENT_SOVERSION "5") #set_target_properties(keduvocdocument # PROPERTIES VERSION ${LIB_KEDUVOCDOCUMENT_VERSION} # SOVERSION ${LIB_KEDUVOCDOCUMENT_SOVERSION} #) install(TARGETS KEduVocDocument EXPORT LibKEduVocDocumentTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### install(FILES ${CMAKE_CURRENT_BINARY_DIR}/keduvocdocument_export.h ${KdeEdu_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/libkeduvocdocument COMPONENT Devel ) diff --git a/keduvocdocument/keduvocvocabularyfilter.cpp b/keduvocdocument/keduvocvocabularyfilter.cpp new file mode 100644 index 0000000..17450da --- /dev/null +++ b/keduvocdocument/keduvocvocabularyfilter.cpp @@ -0,0 +1,99 @@ +/*************************************************************************** + + Copyright 2007-2008 Frederik Gladhorn + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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) any later version. * + * * + ***************************************************************************/ + +#include "keduvocvocabularyfilter.h" +#include + +class KEduVocVocabularyFilter::Private +{ +public: + Private(); + virtual void setSourceModel(QAbstractItemModel *model) { + Q_UNUSED(model) + } + + KEduVocVocabularyModel * m_model; + QString m_filterString; +}; + +KEduVocVocabularyFilter::Private::Private() { + m_model = 0; + m_filterString = ""; +} + +KEduVocVocabularyFilter::KEduVocVocabularyFilter(QObject *parent) + : QSortFilterProxyModel(parent), + d( new Private ) +{ + // do not use capitalization for searches + setSortCaseSensitivity(Qt::CaseInsensitive); + setFilterCaseSensitivity(Qt::CaseInsensitive); + // sort locale aware: at least puts umlauts and accents in the right position. + // Not sure about languages that are more different. + // Also depends on the current locale. + setSortLocaleAware(true); + + // eventually accept only one language if so desired... + setFilterKeyColumn(-1); +} + +KEduVocVocabularyFilter::~KEduVocVocabularyFilter() +{ + delete d; +} + +QModelIndex KEduVocVocabularyFilter::appendEntry(KEduVocExpression *expression) +{ + if (!d->m_model) { + return QModelIndex(); + } + return mapFromSource(d->m_model->appendEntry(expression)); +} + +void KEduVocVocabularyFilter::setSourceModel(KEduVocVocabularyModel * model) +{ + d->setSourceModel(model); + d->m_model = model; +} + +void KEduVocVocabularyFilter::setSearchString(const QString & expression) +{ + d->m_filterString = expression; + invalidateFilter(); +} + +bool KEduVocVocabularyFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + if (d->m_filterString.isEmpty()) { + return true; + } + + int columns = d->m_model->columnCount(QModelIndex()); + for (int i = 0; i < columns; i += KEduVocVocabularyModel::EntryColumnsMAX) { + QModelIndex index = sourceModel()->index(sourceRow, i, sourceParent); + if (sourceModel()->data(index).toString().contains(d->m_filterString, Qt::CaseInsensitive)) { + return true; + } + } + return false; +} + +KEduVocLesson * KEduVocVocabularyFilter::lesson() +{ + if (d->m_model) { + return d->m_model->lesson(); + } + return 0; +} diff --git a/keduvocdocument/keduvocvocabularyfilter.h b/keduvocdocument/keduvocvocabularyfilter.h new file mode 100644 index 0000000..376bb65 --- /dev/null +++ b/keduvocdocument/keduvocvocabularyfilter.h @@ -0,0 +1,51 @@ +/*************************************************************************** + + Copyright 2007-2008 Frederik Gladhorn + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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) any later version. * + * * + ***************************************************************************/ + +#ifndef KEDUVOCVOCABULARYFILTER_H +#define KEDUVOCVOCABULARYFILTER_H + +#include "keduvocdocument_export.h" +#include + +class KEduVocLesson; +class KEduVocExpression; + +class KEduVocVocabularyModel; + +class KEDUVOCDOCUMENT_EXPORT KEduVocVocabularyFilter : public QSortFilterProxyModel +{ + Q_OBJECT +public: + KEduVocVocabularyFilter(QObject *parent = 0); + ~KEduVocVocabularyFilter(); + + void setSourceModel(KEduVocVocabularyModel* model); + + QModelIndex appendEntry(KEduVocExpression *expression = 0); + KEduVocLesson * lesson(); + +public slots: + void setSearchString(const QString& expression); + +protected: + virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + +private: + class Private; + Private * const d; +}; + + +#endif