Commit ca679b08 authored by David Jarvie's avatar David Jarvie
Browse files

Data model tweaks

parent 7f57278a
......@@ -188,8 +188,8 @@ ChangeRecorder* AkonadiDataModel::monitor()
QVariant AkonadiDataModel::data(const QModelIndex& index, int role) const
{
if (role == ResourceIdRole)
role = CollectionIdRole;
if (roleHandled(role))
role = CollectionIdRole; // use the base model for this
if (roleHandled(role) || role == ParentResourceIdRole)
{
const Collection collection = EntityTreeModel::data(index, CollectionRole).value<Collection>();
if (collection.isValid())
......
......@@ -173,6 +173,8 @@ bool ResourceDataModelBase::roleHandled(int role) const
case Qt::SizeHintRole:
case Qt::AccessibleTextRole:
case Qt::ToolTipRole:
case ItemTypeRole:
case ResourceIdRole:
case BaseColourRole:
case TimeDisplayRole:
case SortRole:
......@@ -195,7 +197,7 @@ bool ResourceDataModelBase::roleHandled(int role) const
*/
QVariant ResourceDataModelBase::resourceData(int& role, const Resource& resource, bool& handled) const
{
if (roleHandled(role)) // Ensure that resourceDataHandles() is coded correctly
if (roleHandled(role)) // Ensure that roleHandled() is coded correctly
{
handled = true;
switch (role)
......@@ -210,12 +212,16 @@ QVariant ResourceDataModelBase::resourceData(int& role, const Resource& resource
const QColor colour = resource.backgroundColour();
if (colour.isValid())
return colour;
break;
break; // use base model background colour
}
case Qt::ForegroundRole:
return resource.foregroundColour();
case Qt::ToolTipRole:
return tooltip(resource, CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
case ItemTypeRole:
return static_cast<int>(Type::Resource);
case ResourceIdRole:
return resource.id();
default:
break;
}
......@@ -231,13 +237,20 @@ QVariant ResourceDataModelBase::resourceData(int& role, const Resource& resource
QVariant ResourceDataModelBase::eventData(int role, int column, const KAEvent& event,
const Resource& resource, bool& handled) const
{
if (roleHandled(role)) // Ensure that eventDataHandles() is coded correctly
if (roleHandled(role)) // Ensure that roleHandled() is coded correctly
{
handled = true;
bool calendarColour = false;
if (role == Qt::WhatsThisRole)
return whatsThisText(column);
switch (role)
{
case Qt::WhatsThisRole:
return whatsThisText(column);
case ItemTypeRole:
return static_cast<int>(Type::Event);
default:
break;
}
if (!event.isValid())
return QVariant();
switch (role)
......
/*
* resourcedatamodelbase.h - base for models containing calendars and events
* Program: kalarm
* Copyright © 2007-2019 David Jarvie <djarvie@kde.org>
* Copyright © 2007-2020 David Jarvie <djarvie@kde.org>
*
* 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
......@@ -72,6 +72,8 @@ class ResourceDataModelBase
ColumnTitleRole, // column titles (whether displayed or not)
CommandErrorRole // last command execution error for alarm (per user)
};
/** The type of a model row. */
enum class Type { Error = 0, Event, Resource };
virtual ~ResourceDataModelBase();
......
......@@ -131,15 +131,11 @@ bool ResourceFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sou
return false; // invalidly configured resource
if (!mWritableOnly && mAlarmType == CalEvent::EMPTY)
return true;
if (mWritableOnly && !resource.isWritable())
return false;
if (mAlarmType != CalEvent::EMPTY && !(resource.alarmTypes() & mAlarmType))
return false;
if (mWritableOnly && !resource.isCompatible())
return false;
if (mEnabledOnly && !resource.isEnabled(mAlarmType))
return false;
if (!mFilterText.isEmpty() && !resource.displayName().contains(mFilterText, Qt::CaseInsensitive))
if ((mWritableOnly && !resource.isWritable())
|| (mAlarmType != CalEvent::EMPTY && !(resource.alarmTypes() & mAlarmType))
|| (mWritableOnly && !resource.isCompatible())
|| (mEnabledOnly && !resource.isEnabled(mAlarmType))
|| (!mFilterText.isEmpty() && !resource.displayName().contains(mFilterText, Qt::CaseInsensitive)))
return false;
return true;
}
......@@ -486,10 +482,13 @@ void ResourceFilterCheckListModel::setEventTypeFilter(CalEvent::Type type)
{
if (type != mAlarmType)
{
disconnect(sourceModel(), &QAbstractItemModel::rowsAboutToBeInserted, this, nullptr);
disconnect(sourceModel(), &QAbstractItemModel::rowsAboutToBeRemoved, this, nullptr);
disconnect(sourceModel(), &QAbstractItemModel::rowsInserted, this, nullptr);
disconnect(sourceModel(), &QAbstractItemModel::rowsRemoved, this, nullptr);
if (sourceModel())
{
disconnect(sourceModel(), &QAbstractItemModel::rowsAboutToBeInserted, this, nullptr);
disconnect(sourceModel(), &QAbstractItemModel::rowsAboutToBeRemoved, this, nullptr);
disconnect(sourceModel(), &QAbstractItemModel::rowsInserted, this, nullptr);
disconnect(sourceModel(), &QAbstractItemModel::rowsRemoved, this, nullptr);
}
ResourceCheckListModel* newModel;
switch (type)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment