SortModel->SortFilterModel
svn path=/trunk/KDE/kdebase/runtime/; revision=1190655
This commit is contained in:
parent
1b1ea1a1b3
commit
0394675156
@ -45,7 +45,7 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
|
||||
|
||||
qmlRegisterType<Plasma::DataSource>(uri, 0, 1, "DataSource");
|
||||
qmlRegisterType<Plasma::DataModel>(uri, 0, 1, "DataModel");
|
||||
qmlRegisterType<Plasma::SortModel>(uri, 0, 1, "SortModel");
|
||||
qmlRegisterType<Plasma::SortFilterModel>(uri, 0, 1, "SortFilterModel");
|
||||
|
||||
qmlRegisterInterface<Plasma::Service>("Service");
|
||||
qRegisterMetaType<Plasma::Service*>("Service");
|
||||
|
@ -25,18 +25,18 @@
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
SortModel::SortModel(QObject* parent)
|
||||
SortFilterModel::SortFilterModel(QObject* parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
setObjectName("SortModel");
|
||||
setObjectName("SortFilterModel");
|
||||
setDynamicSortFilter(true);
|
||||
}
|
||||
|
||||
SortModel::~SortModel()
|
||||
SortFilterModel::~SortFilterModel()
|
||||
{
|
||||
}
|
||||
|
||||
void SortModel::syncRoleNames()
|
||||
void SortFilterModel::syncRoleNames()
|
||||
{
|
||||
m_roleIds.clear();
|
||||
|
||||
@ -49,7 +49,7 @@ void SortModel::syncRoleNames()
|
||||
setSortRole(m_sortRole);
|
||||
}
|
||||
|
||||
int SortModel::roleNameToId(const QString &name)
|
||||
int SortFilterModel::roleNameToId(const QString &name)
|
||||
{
|
||||
if (!m_roleIds.contains(name)) {
|
||||
return -1;
|
||||
@ -57,7 +57,7 @@ int SortModel::roleNameToId(const QString &name)
|
||||
return m_roleIds.value(name);
|
||||
}
|
||||
|
||||
void SortModel::setModel(QObject *source)
|
||||
void SortFilterModel::setModel(QObject *source)
|
||||
{
|
||||
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(source);
|
||||
if (!model) {
|
||||
@ -72,40 +72,40 @@ void SortModel::setModel(QObject *source)
|
||||
|
||||
|
||||
|
||||
void SortModel::setFilterRegExp(const QString &exp)
|
||||
void SortFilterModel::setFilterRegExp(const QString &exp)
|
||||
{
|
||||
QSortFilterProxyModel::setFilterRegExp(QRegExp(exp));
|
||||
}
|
||||
|
||||
QString SortModel::filterRegExp() const
|
||||
QString SortFilterModel::filterRegExp() const
|
||||
{
|
||||
return QSortFilterProxyModel::filterRegExp().pattern();
|
||||
}
|
||||
|
||||
void SortModel::setFilterRole(const QString &role)
|
||||
void SortFilterModel::setFilterRole(const QString &role)
|
||||
{
|
||||
QSortFilterProxyModel::setFilterRole(roleNameToId(role));
|
||||
m_filterRole = role;
|
||||
}
|
||||
|
||||
QString SortModel::filterRole() const
|
||||
QString SortFilterModel::filterRole() const
|
||||
{
|
||||
return m_filterRole;
|
||||
}
|
||||
|
||||
void SortModel::setSortRole(const QString &role)
|
||||
void SortFilterModel::setSortRole(const QString &role)
|
||||
{
|
||||
QSortFilterProxyModel::setSortRole(roleNameToId(role));
|
||||
m_sortRole = role;
|
||||
sort(0, sortOrder());
|
||||
}
|
||||
|
||||
QString SortModel::sortRole() const
|
||||
QString SortFilterModel::sortRole() const
|
||||
{
|
||||
return m_sortRole;
|
||||
}
|
||||
|
||||
void SortModel::setSortOrder(const Qt::SortOrder order)
|
||||
void SortFilterModel::setSortOrder(const Qt::SortOrder order)
|
||||
{
|
||||
sort(0, order);
|
||||
}
|
||||
@ -113,11 +113,11 @@ void SortModel::setSortOrder(const Qt::SortOrder order)
|
||||
|
||||
|
||||
|
||||
DataModel::DataModel(SortModel* parent)
|
||||
DataModel::DataModel(QObject* parent)
|
||||
: QAbstractItemModel(parent),
|
||||
// m_sortModel(parent),
|
||||
m_dataSource(0)
|
||||
{
|
||||
setObjectName("DataModel");
|
||||
}
|
||||
|
||||
DataModel::~DataModel()
|
||||
@ -285,4 +285,5 @@ int DataModel::roleNameToId(const QString &name)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "datamodel.moc"
|
||||
|
@ -34,7 +34,7 @@ class DataSource;
|
||||
class DataModel;
|
||||
|
||||
|
||||
class SortModel : public QSortFilterProxyModel
|
||||
class SortFilterModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QObject *sourceModel READ sourceModel WRITE setModel)
|
||||
@ -47,8 +47,8 @@ class SortModel : public QSortFilterProxyModel
|
||||
friend class DataModel;
|
||||
|
||||
public:
|
||||
SortModel(QObject* parent=0);
|
||||
~SortModel();
|
||||
SortFilterModel(QObject* parent=0);
|
||||
~SortFilterModel();
|
||||
|
||||
//FIXME: find a way to make QML understnd QAbstractItemModel
|
||||
void setModel(QObject *source);
|
||||
@ -83,7 +83,7 @@ class DataModel : public QAbstractItemModel
|
||||
Q_PROPERTY(QString key READ key WRITE setKey)
|
||||
|
||||
public:
|
||||
DataModel(SortModel* parent=0);
|
||||
DataModel(QObject* parent=0);
|
||||
~DataModel();
|
||||
|
||||
void setDataSource(QObject *source);
|
||||
|
Loading…
Reference in New Issue
Block a user