X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=application%2Fstationlistproxymodel.cpp;h=4adc370262c58ccbe2a1f55f0f801b5d5b42571f;hb=88e9978682c323edd0572dc63224c7cc85e85eec;hp=77bc05714fcf64e376f471732d48556c8daa1e3d;hpb=68098d7197170772ac09b9eb6ba426eaa0f6c560;p=quandoparte diff --git a/application/stationlistproxymodel.cpp b/application/stationlistproxymodel.cpp index 77bc057..4adc370 100644 --- a/application/stationlistproxymodel.cpp +++ b/application/stationlistproxymodel.cpp @@ -1,3 +1,24 @@ +/* + +Copyright (C) 2011 Luciano Montanaro + +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. + +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; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. + +*/ + #include "stationlistproxymodel.h" #include "stationlistmodel.h" @@ -11,8 +32,15 @@ Q_DECLARE_METATYPE(QGeoCoordinate) StationListProxyModel::StationListProxyModel(QObject *parent) : QSortFilterProxyModel(parent), m_here(44.5, 9.0), + m_sortingMode(NoSorting), m_filterRecentOnly(false) { + QHash roles; + roles[StationListModel::PositionRole] = "position"; + setRoleNames(roles); + + setFilterCaseSensitivity(Qt::CaseInsensitive); + setSortCaseSensitivity(Qt::CaseInsensitive); } bool StationListProxyModel::lessThan(const QModelIndex &left, @@ -59,3 +87,47 @@ void StationListProxyModel::setRecentOnlyFilter(bool activation) { m_filterRecentOnly = activation; } + +QString StationListProxyModel::searchPattern() const +{ + return m_searchPattern; +} + +void StationListProxyModel::setSearchPattern(const QString &pattern) +{ + m_searchPattern = pattern; + setFilterFixedString(m_searchPattern); + qDebug() << "set Search pattern to" << pattern; +} + +StationListProxyModel::SortingMode StationListProxyModel::sortingMode() +{ + return m_sortingMode; +} + +void StationListProxyModel::setSortingMode(SortingMode mode) +{ + if (mode != m_sortingMode) { + qDebug() << "setSorting Mode" << mode << m_sortingMode << "called"; + m_sortingMode = mode; + setRecentOnlyFilter(false); + + switch (mode) { + case StationListProxyModel::AlphaSorting: + setSortRole(Qt::DisplayRole); + break; + case StationListProxyModel::DistanceSorting: + setSortRole(StationListModel::PositionRole); + break; + case StationListProxyModel::RecentUsageSorting: + setRecentOnlyFilter(true); + break; + case StationListProxyModel::NoSorting: + default: + break; + } + invalidate(); + sort(0); + emit sortingModeChanged(mode); + } +}