ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #00200
[Branch ~agateau/plasma-indicatordisplay/trunk] Rev 79: Reworked filter to filter out servers if they do not use the "messaging" type.
------------------------------------------------------------
revno: 79
committer: Aurelien Gateau <aurelien.gateau@xxxxxxxxxxxxx>
branch nick: plasma-indicatordisplay
timestamp: Tue 2009-09-15 14:16:56 +0200
message:
Reworked filter to filter out servers if they do not use the "messaging" type.
modified:
src/filtermodel.cpp
src/filtermodel.h
src/indicatordisplay.cpp
src/listenermodel.cpp
tests/filtermodeltest.cpp
--
lp:plasma-indicatordisplay
https://code.launchpad.net/~agateau/plasma-indicatordisplay/trunk
Your team ayatana-commits is subscribed to branch lp:plasma-indicatordisplay.
To unsubscribe from this branch go to https://code.launchpad.net/~agateau/plasma-indicatordisplay/trunk/+edit-subscription.
=== modified file 'src/filtermodel.cpp'
--- src/filtermodel.cpp 2009-07-30 20:31:12 +0000
+++ src/filtermodel.cpp 2009-09-15 12:16:56 +0000
@@ -19,12 +19,10 @@
// Local
#include <listenermodel.h>
-static const FilterModel::DisplayStyle DEFAULT_DISPLAY_STYLE = FilterModel::Summary;
-
struct FilterModelPrivate
{
FilterModel* q;
- QHash<QString, FilterModel::DisplayStyle> mDisplayStyleForType;
+ QString mAcceptedServerType;
};
FilterModel::FilterModel(QObject* parent)
@@ -40,32 +38,39 @@
delete d;
}
-void FilterModel::setDisplayStyle(const QString& type, DisplayStyle style)
+void FilterModel::setAcceptedServerType(const QString& type)
{
- d->mDisplayStyleForType.insert(type, style);
+ d->mAcceptedServerType = type;
invalidateFilter();
}
-FilterModel::DisplayStyle FilterModel::displayStyle(const QString& type) const
+QString FilterModel::acceptedServerType() const
{
- return d->mDisplayStyleForType.value(type, DEFAULT_DISPLAY_STYLE);
+ return d->mAcceptedServerType;
}
-bool FilterModel::filterAcceptsRow(int /*sourceRow*/, const QModelIndex& sourceParent) const
+bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
- if (!sourceParent.isValid()) {
- // Row is a server, accept it
- return true;
+ QModelIndex serverIndex;
+ if (sourceParent.isValid()) {
+ // Row is an indicator, parent is the server
+ serverIndex = sourceParent;
+ } else {
+ // Row is a server
+ serverIndex = sourceModel()->index(sourceRow, 0);
+ if (!serverIndex.isValid()) {
+ kWarning() << "Invalid index!";
+ return false;
+ }
}
- // Row is an indicator, accept it if we use detailed style for its server
- QVariant serverType = sourceParent.data(ListenerModel::ServerTypeRole);
+ QVariant serverType = serverIndex.data(ListenerModel::ServerTypeRole);
+ kDebug() << "serverType" << serverType;
if (!serverType.isValid()) {
// We don't know the server type for now, wait
return false;
}
- DisplayStyle style = displayStyle(serverType.toString());
- return style == Detailed;
+ return serverType.toString() == d->mAcceptedServerType;
}
#include "filtermodel.moc"
=== modified file 'src/filtermodel.h'
--- src/filtermodel.h 2009-07-30 14:54:42 +0000
+++ src/filtermodel.h 2009-09-15 12:16:56 +0000
@@ -25,13 +25,8 @@
FilterModel(QObject* parent=0);
~FilterModel();
- enum DisplayStyle {
- Summary,
- Detailed
- };
-
- void setDisplayStyle(const QString& type, DisplayStyle);
- DisplayStyle displayStyle(const QString& type) const;
+ void setAcceptedServerType(const QString& type);
+ QString acceptedServerType() const;
protected:
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const;
=== modified file 'src/indicatordisplay.cpp'
--- src/indicatordisplay.cpp 2009-09-15 08:52:51 +0000
+++ src/indicatordisplay.cpp 2009-09-15 12:16:56 +0000
@@ -102,7 +102,7 @@
void IndicatorDisplay::initFilterModel()
{
mFilterModel = new FilterModel(this);
- mFilterModel->setDisplayStyle("messaging", FilterModel::Detailed);
+ mFilterModel->setAcceptedServerType("messaging");
mFilterModel->setSourceModel(mSourceModel);
}
=== modified file 'src/listenermodel.cpp'
--- src/listenermodel.cpp 2009-09-15 08:52:13 +0000
+++ src/listenermodel.cpp 2009-09-15 12:16:56 +0000
@@ -182,7 +182,12 @@
kError() << "No item for server" << server;
return;
}
+ // HACK: emit layoutAboutToBeChanged() and layoutChanged() because
+ // otherwise FilterModel won't tell the view it should show the index
+ // children.
+ emit layoutAboutToBeChanged();
item->setData(type, ServerTypeRole);
+ emit layoutChanged();
}
void ListenerModel::slotServerRemoved(QIndicate::Listener::Server* server)
=== modified file 'tests/filtermodeltest.cpp'
--- tests/filtermodeltest.cpp 2009-09-14 16:23:19 +0000
+++ tests/filtermodeltest.cpp 2009-09-15 12:16:56 +0000
@@ -66,15 +66,17 @@
indicator.show();
QTest::qWait(500);
- // Get indexes
+ // No index by default
QModelIndex serverIndex = mFilterModel->index(0, 0);
+ QVERIFY(!serverIndex.isValid());
+
+ // Set server type
+ mFilterModel->setAcceptedServerType(SERVER_TYPE);
+
+ // We should see the server and its indicator now
+ serverIndex = mFilterModel->index(0, 0);
QVERIFY(serverIndex.isValid());
- // No indicator by default
- QVERIFY(!mFilterModel->hasChildren(serverIndex));
-
- // Switch to detailed view, we should see the indicator now
- mFilterModel->setDisplayStyle(SERVER_TYPE, FilterModel::Detailed);
QVERIFY(mFilterModel->hasChildren(serverIndex));
QModelIndex indicatorIndex = mFilterModel->index(0, 0, serverIndex);