• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

parley

  • sources
  • kde-4.14
  • kdeedu
  • parley
  • src
  • collection
vocabularyfilter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
4 
5  ***************************************************************************/
6 
7 /***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "vocabularyfilter.h"
17 
18 #include "vocabularymodel.h"
19 
20 
21 VocabularyFilter::VocabularyFilter(QObject *parent)
22  : QSortFilterProxyModel(parent), m_model(0)
23 {
24  // do not use capitalization for searches
25  setSortCaseSensitivity(Qt::CaseInsensitive);
26  setFilterCaseSensitivity(Qt::CaseInsensitive);
27  // sort locale aware: at least puts umlauts and accents in the right position.
28  // Not sure about languages that are more different.
29  // Also depends on the current locale.
30  setSortLocaleAware(true);
31 
32  // eventually accept only one language if so desired...
33  setFilterKeyColumn(-1);
34 }
35 
36 QModelIndex VocabularyFilter::appendEntry(KEduVocExpression *expression)
37 {
38  if (!m_model) {
39  return QModelIndex();
40  }
41  return mapFromSource(m_model->appendEntry(expression));
42 }
43 
44 void VocabularyFilter::setSourceModel(VocabularyModel * model)
45 {
46  QSortFilterProxyModel::setSourceModel(model);
47  m_model = model;
48 }
49 
50 void VocabularyFilter::setSearchString(const QString & expression)
51 {
52  m_filterString = expression;
53  invalidateFilter();
54 }
55 
56 bool VocabularyFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
57 {
58  if (m_filterString.isEmpty()) {
59  return true;
60  }
61 
62  int columns = m_model->columnCount(QModelIndex());
63  for (int i = 0; i < columns; i += VocabularyModel::EntryColumnsMAX) {
64  QModelIndex index = sourceModel()->index(sourceRow, i, sourceParent);
65  if (sourceModel()->data(index).toString().contains(m_filterString, Qt::CaseInsensitive)) {
66  return true;
67  }
68  }
69  return false;
70 }
71 
72 KEduVocLesson * VocabularyFilter::lesson()
73 {
74  if (m_model) {
75  return m_model->lesson();
76  }
77  return 0;
78 }
79 
80 #include "vocabularyfilter.moc"
81 
QSortFilterProxyModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
QModelIndex
VocabularyModel::columnCount
int columnCount(const QModelIndex &) const
Definition: vocabularymodel.cpp:108
QSortFilterProxyModel::setFilterCaseSensitivity
void setFilterCaseSensitivity(Qt::CaseSensitivity cs)
QAbstractItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
VocabularyFilter::filterAcceptsRow
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
Definition: vocabularyfilter.cpp:56
QSortFilterProxyModel::setSourceModel
virtual void setSourceModel(QAbstractItemModel *sourceModel)
VocabularyFilter::lesson
KEduVocLesson * lesson()
Definition: vocabularyfilter.cpp:72
VocabularyFilter::setSourceModel
void setSourceModel(VocabularyModel *model)
Definition: vocabularyfilter.cpp:44
VocabularyFilter::appendEntry
QModelIndex appendEntry(KEduVocExpression *expression=0)
Definition: vocabularyfilter.cpp:36
VocabularyFilter::VocabularyFilter
VocabularyFilter(QObject *parent=0)
Definition: vocabularyfilter.cpp:21
QObject
QString::isEmpty
bool isEmpty() const
QSortFilterProxyModel::invalidateFilter
void invalidateFilter()
QString
VocabularyModel
Definition: vocabularymodel.h:29
QSortFilterProxyModel
QAbstractProxyModel::sourceModel
QAbstractItemModel * sourceModel() const
QSortFilterProxyModel::setSortCaseSensitivity
void setSortCaseSensitivity(Qt::CaseSensitivity cs)
QSortFilterProxyModel::mapFromSource
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
VocabularyFilter::setSearchString
void setSearchString(const QString &expression)
Definition: vocabularyfilter.cpp:50
QSortFilterProxyModel::setSortLocaleAware
void setSortLocaleAware(bool on)
VocabularyModel::appendEntry
QModelIndex appendEntry(KEduVocExpression *expression=0)
Definition: vocabularymodel.cpp:320
VocabularyModel::EntryColumnsMAX
Definition: vocabularymodel.h:44
vocabularyfilter.h
QSortFilterProxyModel::setFilterKeyColumn
void setFilterKeyColumn(int column)
VocabularyModel::lesson
KEduVocLesson * lesson()
Definition: vocabularymodel.cpp:90
QSortFilterProxyModel::data
virtual QVariant data(const QModelIndex &index, int role) const
vocabularymodel.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:56 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal