diff --git a/plugins/dockers/shapecollection/CollectionItemModel.cpp b/plugins/dockers/shapecollection/CollectionItemModel.cpp index 31315913d2b..cb96cbb2104 100644 --- a/plugins/dockers/shapecollection/CollectionItemModel.cpp +++ b/plugins/dockers/shapecollection/CollectionItemModel.cpp @@ -1,129 +1,133 @@ /* This file is part of the KDE project * Copyright (C) 2008 Peter Simonsson * * 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 "CollectionItemModel.h" #include #include #include #include CollectionItemModel::CollectionItemModel(QObject* parent) : QAbstractListModel(parent) { - setSupportedDragActions(Qt::CopyAction); +} + +Qt::DropActions CollectionItemModel::supportedDragActions() const +{ + return Qt::CopyAction; } QVariant CollectionItemModel::data(const QModelIndex& index, int role) const { if (!index.isValid() || index.row() > m_shapeTemplateList.count ()) return QVariant(); switch(role) { case Qt::ToolTipRole: return m_shapeTemplateList[index.row()].toolTip; case Qt::DecorationRole: return m_shapeTemplateList[index.row()].icon; case Qt::UserRole: return m_shapeTemplateList[index.row()].id; case Qt::DisplayRole: return m_shapeTemplateList[index.row()].name; default: return QVariant(); } return QVariant(); } int CollectionItemModel::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent); return m_shapeTemplateList.count(); } void CollectionItemModel::setShapeTemplateList(const QList& newlist) { beginResetModel(); m_shapeTemplateList = newlist; endResetModel(); } QMimeData* CollectionItemModel::mimeData(const QModelIndexList& indexes) const { if(indexes.isEmpty()) return 0; QModelIndex index = indexes.first(); if(!index.isValid()) return 0; if(m_shapeTemplateList.isEmpty()) return 0; QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << m_shapeTemplateList[index.row()].id; const KoProperties *props = m_shapeTemplateList[index.row()].properties; if(props) dataStream << props->store("shapes"); else dataStream << QString(); QMimeData* mimeData = new QMimeData; mimeData->setData(SHAPETEMPLATE_MIMETYPE, itemData); return mimeData; } QStringList CollectionItemModel::mimeTypes() const { QStringList mimetypes; mimetypes << SHAPETEMPLATE_MIMETYPE; return mimetypes; } Qt::ItemFlags CollectionItemModel::flags(const QModelIndex& index) const { if(index.isValid()) return QAbstractListModel::flags(index) | Qt::ItemIsDragEnabled; return QAbstractListModel::flags(index); } const KoProperties* CollectionItemModel::properties(const QModelIndex& index) const { if (!index.isValid() || index.row() > m_shapeTemplateList.count()) return 0; return m_shapeTemplateList[index.row()].properties; } QDebug operator<<(QDebug dbg, const KoCollectionItem &i) { return dbg << "CollectionItem[" << i.id << ',' << i.name << "]"; } diff --git a/plugins/dockers/shapecollection/CollectionItemModel.h b/plugins/dockers/shapecollection/CollectionItemModel.h index 6f64d0298e6..b8edfc4eaf4 100644 --- a/plugins/dockers/shapecollection/CollectionItemModel.h +++ b/plugins/dockers/shapecollection/CollectionItemModel.h @@ -1,75 +1,76 @@ /* This file is part of the KDE project * Copyright (C) 2008 Peter Simonsson * * 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 KIVIOSHAPETEMPLATEMODEL_H #define KIVIOSHAPETEMPLATEMODEL_H #include #include #include #include #include class KoProperties; /** * Struct containing the information stored in CollectionItemModel item */ struct KoCollectionItem { KoCollectionItem() { properties = 0; }; QString id; QString name; QString toolTip; QIcon icon; const KoProperties* properties; }; class CollectionItemModel : public QAbstractListModel { Q_OBJECT public: explicit CollectionItemModel(QObject *parent = 0); + virtual Qt::DropActions supportedDragActions() const; virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual QMimeData* mimeData(const QModelIndexList& indexes) const; virtual QStringList mimeTypes() const; virtual Qt::ItemFlags flags(const QModelIndex& index) const; /** * Set the list of KoCollectionItem to be stored in the model */ void setShapeTemplateList(const QList& newlist); QList shapeTemplateList () const { return m_shapeTemplateList; } const KoProperties* properties(const QModelIndex& index) const; private: QList m_shapeTemplateList; QString m_family; }; QDebug operator<<(QDebug dbg, const KoCollectionItem &i); #endif //KIVIOSHAPETEMPLATEMODEL_H