26 #include <KMessageBox>
28 #include <QAbstractItemModel>
30 #include <QItemSelectionModel>
32 using namespace MailCommon;
34 class FilterController::Private
38 void selectionChanged();
43 void moveDownFilter();
54 void FilterController::Private::selectionChanged()
56 const bool filterSelected = mSelectionModel->hasSelection();
58 if ( filterSelected ) {
60 mRemoveAction->setEnabled(
true );
62 const QModelIndex index = mSelectionModel->selectedRows().first();
63 mMoveUpAction->setEnabled( index.
row() != 0 );
64 mMoveDownAction->setEnabled( index.
row() != ( mModel->rowCount() - 1 ) );
66 mEditAction->setEnabled(
false );
67 mRemoveAction->setEnabled(
false );
68 mMoveUpAction->setEnabled(
false );
69 mMoveDownAction->setEnabled(
false );
73 void FilterController::Private::addFilter()
75 mModel->insertRow( mModel->rowCount() );
78 dlg.setCaption( i18n(
"Add Filter" ) );
79 dlg.
load( mModel->rowCount() - 1 );
84 mModel->removeRow( mModel->rowCount() - 1 );
88 void FilterController::Private::editFilter()
90 if ( !mSelectionModel->hasSelection() ) {
94 const QModelIndex index = mSelectionModel->selectedRows().first();
97 dlg.setCaption( i18n(
"Edit Filter" ) );
104 void FilterController::Private::removeFilter()
106 if ( !mSelectionModel->hasSelection() ) {
110 const QModelIndex index = mSelectionModel->selectedRows().first();
113 KMessageBox::questionYesNo(
115 i18n(
"Do you really want to remove filter <b>%1</b>?",
117 i18n(
"Remove Filter" ) );
119 if ( result == KMessageBox::No ) {
123 mModel->removeRow( index.
row() );
126 void FilterController::Private::moveUpFilter()
128 if ( !mSelectionModel->hasSelection() ) {
132 const QModelIndex index = mSelectionModel->selectedRows().first();
133 mModel->moveRow( index.
row(), index.
row() - 1 );
136 mSelectionModel->select( mModel->index( index.
row() - 1, 0 ),
137 QItemSelectionModel::ClearAndSelect );
140 void FilterController::Private::moveDownFilter()
142 if ( !mSelectionModel->hasSelection() ) {
146 const QModelIndex index = mSelectionModel->selectedRows().first();
147 mModel->moveRow( index.
row(), index.
row() + 1 );
150 mSelectionModel->select( mModel->index( index.
row() + 1, 0 ),
151 QItemSelectionModel::ClearAndSelect );
155 :
QObject( parent ), d( new Private )
160 d->mAddAction =
new QAction( i18n(
"Add" ),
this );
161 d->mEditAction =
new QAction( i18n(
"Edit" ),
this );
162 d->mRemoveAction =
new QAction( i18n(
"Remove" ),
this );
163 d->mMoveUpAction =
new QAction( i18n(
"Move Up" ),
this );
164 d->mMoveDownAction =
new QAction( i18n(
"Move Down" ),
this );
167 this, SLOT(selectionChanged()) );
169 connect( d->mAddAction, SIGNAL(triggered(
bool)), SLOT(addFilter()) );
170 connect( d->mEditAction, SIGNAL(triggered(
bool)), SLOT(editFilter()) );
171 connect( d->mRemoveAction, SIGNAL(triggered(
bool)), SLOT(removeFilter()) );
172 connect( d->mMoveUpAction, SIGNAL(triggered(
bool)), SLOT(moveUpFilter()) );
173 connect( d->mMoveDownAction, SIGNAL(triggered(
bool)), SLOT(moveDownFilter()) );
175 d->selectionChanged();
190 return d->mSelectionModel;
195 return d->mAddAction;
200 return d->mEditAction;
205 return d->mRemoveAction;
210 return d->mMoveUpAction;
215 return d->mMoveDownAction;
218 #include "moc_filtercontroller.cpp"
QItemSelectionModel * selectionModel() const
Returns the item selection model, which is used for adapting the state of the actions.
QAction * addAction() const
Returns the action for adding a new filter.
QAction * editAction() const
Returns the action for editing the currently selected filter.
QAction * moveDownAction() const
Returns the action for moving down the currently selected filter.
QAction * removeAction() const
Returns the action for removing the currently selected filter.
~FilterController()
Destroys the filter controller.
QAction * moveUpAction() const
Returns the action for moving up the currently selected filter.
QVariant data(int role) const
FilterController(QObject *parent=0)
Creates a new filter controller.
QAbstractItemModel * model() const
Returns the model that represents the list of filters.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)