diff --git a/akonadi/descendantsproxymodel.cpp b/akonadi/descendantsproxymodel.cpp index 4132f9af5..1b98ffae9 100644 --- a/akonadi/descendantsproxymodel.cpp +++ b/akonadi/descendantsproxymodel.cpp @@ -1,79 +1,101 @@ /* Copyright (c) 2009 Stephen Kelly This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "descendantsproxymodel.h" #include "entitytreemodel.h" using namespace Akonadi; namespace Akonadi { class DescendantsProxyModelPrivate { public: DescendantsProxyModelPrivate(DescendantsProxyModel *model) : m_headerSet(EntityTreeModel::EntityTreeHeaders), q_ptr(model) { } private: int m_headerSet; Q_DECLARE_PUBLIC(DescendantsProxyModel) DescendantsProxyModel *q_ptr; }; } DescendantsProxyModel::DescendantsProxyModel(QObject *parent) : KDescendantsProxyModel(parent), d_ptr(new DescendantsProxyModelPrivate(this)) { } DescendantsProxyModel::~DescendantsProxyModel() { delete d_ptr; } QVariant DescendantsProxyModel::headerData(int section, Qt::Orientation orientation, int role) const { Q_D(const DescendantsProxyModel); int adjustedRole; adjustedRole = role + ( Akonadi::EntityTreeModel::TerminalUserRole * d->m_headerSet ); return sourceModel()->headerData(section, orientation, adjustedRole); } int DescendantsProxyModel::headerSet() const { Q_D(const DescendantsProxyModel); return d->m_headerSet; } void DescendantsProxyModel::setHeaderSet(int set) { Q_D(DescendantsProxyModel); d->m_headerSet = set; } + +bool DescendantsProxyModel::dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ) +{ + Q_ASSERT(sourceModel()); + const QModelIndex sourceParent = mapToSource(parent); + return sourceModel()->dropMimeData(data, action, row, column, sourceParent); +} + +QMimeData* DescendantsProxyModel::mimeData( const QModelIndexList & indexes ) const +{ + Q_ASSERT(sourceModel()); + QModelIndexList sourceIndexes; + foreach(const QModelIndex& index, indexes) + sourceIndexes << mapToSource(index); + return sourceModel()->mimeData(sourceIndexes); +} + +QStringList DescendantsProxyModel::mimeTypes() const +{ + Q_ASSERT(sourceModel()); + return sourceModel()->mimeTypes(); +} diff --git a/akonadi/descendantsproxymodel.h b/akonadi/descendantsproxymodel.h index 3155ed8f8..f72524b2d 100644 --- a/akonadi/descendantsproxymodel.h +++ b/akonadi/descendantsproxymodel.h @@ -1,77 +1,82 @@ /* Copyright (c) 2009 Stephen Kelly This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_DESCENDANTSPROXYMODEL_H #define AKONADI_DESCENDANTSPROXYMODEL_H #include "akonadi_export.h" #include namespace Akonadi { class DescendantsProxyModelPrivate; /** * @short A proxy model that flattens a tree-based model to a list model. * * @author Stephen Kelly * @since 4.4 */ class AKONADI_EXPORT DescendantsProxyModel : public KDescendantsProxyModel { Q_OBJECT public: /** * Creates a new descendants proxy model. * * @param parent The parent object. */ DescendantsProxyModel( QObject *parent = 0 ); /** * Destroys the descendants proxy model. */ virtual ~DescendantsProxyModel(); /** * Sets the header @p set that shall be used by the proxy model. * * \s EntityTreeModel::HeaderGroup */ void setHeaderSet( int set ); /** * Returns the header set used by the proxy model. */ int headerSet() const; + // QAbstractProxyModel does not proxy all methods... + virtual bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ); + virtual QMimeData* mimeData( const QModelIndexList & indexes ) const; + virtual QStringList mimeTypes() const; + virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; private: //@cond PRIVATE Q_DECLARE_PRIVATE(DescendantsProxyModel) DescendantsProxyModelPrivate *d_ptr; //@endcond }; } #endif diff --git a/akonadi/selectionproxymodel.cpp b/akonadi/selectionproxymodel.cpp index afefab14a..790cbdae4 100644 --- a/akonadi/selectionproxymodel.cpp +++ b/akonadi/selectionproxymodel.cpp @@ -1,79 +1,102 @@ /* Copyright (c) 2009 Stephen Kelly This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "selectionproxymodel.h" #include "entitytreemodel.h" using namespace Akonadi; namespace Akonadi { class SelectionProxyModelPrivate { public: SelectionProxyModelPrivate(SelectionProxyModel *model) : m_headerSet(EntityTreeModel::EntityTreeHeaders), q_ptr(model) { } private: int m_headerSet; Q_DECLARE_PUBLIC(SelectionProxyModel) SelectionProxyModel *q_ptr; }; } SelectionProxyModel::SelectionProxyModel(QItemSelectionModel *selectionModel, QObject *parent) : KSelectionProxyModel(selectionModel, parent), d_ptr(new SelectionProxyModelPrivate(this)) { } SelectionProxyModel::~SelectionProxyModel() { delete d_ptr; } QVariant SelectionProxyModel::headerData(int section, Qt::Orientation orientation, int role) const { Q_D(const SelectionProxyModel); int adjustedRole; adjustedRole = role + ( Akonadi::EntityTreeModel::TerminalUserRole * d->m_headerSet ); return sourceModel()->headerData(section, orientation, adjustedRole); } int SelectionProxyModel::headerSet() const { Q_D(const SelectionProxyModel); return d->m_headerSet; } void SelectionProxyModel::setHeaderSet(int set) { Q_D(SelectionProxyModel); d->m_headerSet = set; } + +bool SelectionProxyModel::dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ) +{ + Q_ASSERT(sourceModel()); + const QModelIndex sourceParent = mapToSource(parent); + return sourceModel()->dropMimeData(data, action, row, column, sourceParent); +} + +QMimeData* SelectionProxyModel::mimeData( const QModelIndexList & indexes ) const +{ + Q_ASSERT(sourceModel()); + QModelIndexList sourceIndexes; + foreach(const QModelIndex& index, indexes) + sourceIndexes << mapToSource(index); + return sourceModel()->mimeData(sourceIndexes); +} + +QStringList SelectionProxyModel::mimeTypes() const +{ + Q_ASSERT(sourceModel()); + return sourceModel()->mimeTypes(); +} + diff --git a/akonadi/selectionproxymodel.h b/akonadi/selectionproxymodel.h index 5db4ae7af..7c288fe35 100644 --- a/akonadi/selectionproxymodel.h +++ b/akonadi/selectionproxymodel.h @@ -1,81 +1,86 @@ /* Copyright (c) 2009 Stephen Kelly This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_SELECTIONPROXYMODEL_H #define AKONADI_SELECTIONPROXYMODEL_H #include "akonadi_export.h" #include #include namespace Akonadi { class SelectionProxyModelPrivate; /** * @short A proxy model that provides data depending on the selection of a view. * * @author Stephen Kelly * @since 4.4 */ class AKONADI_EXPORT SelectionProxyModel : public KSelectionProxyModel { Q_OBJECT public: /** * Creates a new selection proxy model. * * @param selectionModel The selection model to work on. * @param parent The parent object. */ explicit SelectionProxyModel( QItemSelectionModel *selectionModel, QObject *parent = 0 ); /** * Destroys the selection proxy model. */ virtual ~SelectionProxyModel(); /** * Sets the header @p set that shall be used by the proxy model. * * \s EntityTreeModel::HeaderGroup */ void setHeaderSet( int set ); /** * Returns the header set used by the proxy model. */ int headerSet() const; + // QAbstractProxyModel does not proxy all methods... + virtual bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ); + virtual QMimeData* mimeData( const QModelIndexList & indexes ) const; + virtual QStringList mimeTypes() const; + virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; private: //@cond PRIVATE Q_DECLARE_PRIVATE( SelectionProxyModel ) SelectionProxyModelPrivate *d_ptr; //@endcond }; } #endif