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

mailcommon

  • sources
  • kde-4.12
  • kdepim
  • mailcommon
  • filter
filtermodel.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
3  Copyright (c) 2010 Andras Mantia <andras@kdab.com>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #include "filtermodel_p.h"
21 #include "filtermanager.h"
22 #include "mailfilter.h"
23 
24 using namespace MailCommon;
25 
26 FilterModel::FilterModel( QObject *parent )
27  : QAbstractListModel( parent )
28 {
29  connect( FilterManager::instance(), SIGNAL(filtersChanged()),
30  this, SLOT(filterListUpdated()) );
31 }
32 
33 QVariant FilterModel::data( const QModelIndex &index, int role ) const
34 {
35  if ( role == Qt::DisplayRole ) {
36  return FilterManager::instance()->filters().at( index.row() )->name();
37  }
38 
39  return QVariant();
40 }
41 
42 int FilterModel::rowCount( const QModelIndex & ) const
43 {
44  return FilterManager::instance()->filters().size();
45 }
46 
47 void FilterModel::moveRow( int sourceRow, int destinationRow )
48 {
49  if ( sourceRow == destinationRow ) {
50  return;
51  }
52 
53  if ( sourceRow < 0 || sourceRow >= rowCount() ) {
54  return;
55  }
56 
57  if ( destinationRow < 0 || destinationRow >= rowCount() ) {
58  return;
59  }
60 
61  QList<MailFilter*> filters;
62 
63  foreach ( MailFilter *filter, FilterManager::instance()->filters() ) {
64  filters.append( new MailFilter( *filter ) ); // deep copy
65  }
66 
67  filters.move( sourceRow, destinationRow );
68  FilterManager::instance()->setFilters( filters );
69 
70  reset();
71 }
72 
73 bool FilterModel::insertRows( int row, int count, const QModelIndex &parent )
74 {
75  beginInsertRows( parent, row, row + count - 1 );
76  for ( int i = 0; i < count; ++i ) {
77  MailFilter *filter = new MailFilter();
78  FilterManager::instance()->appendFilters( QList<MailFilter*> () << filter );
79  }
80  endInsertRows();
81 
82  return true;
83 }
84 
85 bool FilterModel::removeRows( int row, int count, const QModelIndex &parent )
86 {
87  const QList<MailFilter*> filters = FilterManager::instance()->filters();
88 
89  beginRemoveRows( parent, row, row + count - 1 );
90  for ( int i = 0; i < count; ++i ) {
91  MailFilter *filter = filters.at( row );
92  FilterManager::instance()->removeFilter( filter );
93  delete filter;
94  }
95  endRemoveRows();
96 
97  return true;
98 }
99 
100 void FilterModel::filterListUpdated()
101 {
102  // Since the FilterManager doesn't tell use which filter has been
103  // updated, we emit dataChanged() for all of them
104  emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ) );
105 }
106 
107 #include "filtermodel_p.moc"
MailCommon::FilterManager::setFilters
void setFilters(const QList< MailCommon::MailFilter * > &filters)
Replace the list of filters of the filter manager with the given list of filters. ...
Definition: filtermanager.cpp:269
MailCommon::FilterModel::moveRow
void moveRow(int sourceRow, int destinationRow)
Definition: filtermodel.cpp:47
mailfilter.h
QAbstractListModel
QObject
filtermodel_p.h
MailCommon::FilterManager::appendFilters
void appendFilters(const QList< MailCommon::MailFilter * > &filters, bool replaceIfNameExists=false)
Manage filters interface.
Definition: filtermanager.cpp:282
MailCommon::FilterModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: filtermodel.cpp:33
MailCommon::FilterManager::instance
static FilterManager * instance()
Returns the global filter manager object.
Definition: filtermanager.cpp:101
MailCommon::FilterModel::insertRows
virtual bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
Definition: filtermodel.cpp:73
MailCommon::FilterModel::FilterModel
FilterModel(QObject *parent=0)
Definition: filtermodel.cpp:26
MailCommon::FilterModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: filtermodel.cpp:42
MailCommon::FilterManager::filters
QList< MailCommon::MailFilter * > filters() const
Returns the filter list of the manager.
Definition: filtermanager.cpp:277
MailCommon::FilterModel::removeRows
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Definition: filtermodel.cpp:85
filtermanager.h
MailCommon::FilterManager::removeFilter
void removeFilter(MailCommon::MailFilter *filter)
Removes the given filter from the list.
Definition: filtermanager.cpp:303
MailCommon::MailFilter
Definition: mailfilter.h:42
QList
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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