[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/work/~ervin/zanshin
From: Mario Bensi <nef () ipsquad ! net>
Date: 2008-12-31 23:04:55
Message-ID: 1230764695.870786.16549.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 903966 by bensi:
add drag and drop and test for todotreemodel
M +21 -0 tests/todotreemodeltest.cpp
M +18 -1 todoflatmodel.cpp
M +1 -0 todoflatmodel.h
M +38 -0 todotreemodel.cpp
M +2 -0 todotreemodel.h
--- branches/work/~ervin/zanshin/tests/todotreemodeltest.cpp #903965:903966
@@ -40,6 +40,7 @@
void testSingleModification();
void testReparentModification();
void testSingleRemoved();
+ void testDragAndDrop();
private:
TodoFlatModel m_flatModel;
@@ -238,4 +239,24 @@
QCOMPARE(signal.at(1).toInt(), 2);
}
+void TodoTreeModelTest::testDragAndDrop()
+{
+ Akonadi::Item item = \
m_flatModel.itemForIndex(m_flatSortedModel.mapToSource(m_flatSortedModel.index(5, \
0))); + QModelIndex index = m_model.indexForItem(item, \
TodoFlatModel::ParentRemoteId); +
+ QCOMPARE(m_model.data(index).toString(), QString("fake-01"));
+ QModelIndex parent = index.parent();
+ QModelIndex parentIndex = m_model.mapToSource(index);
+
+ QModelIndexList indexes;
+ indexes << index;
+ QMimeData *mimeData = m_model.mimeData(indexes);
+ QVERIFY(m_model.dropMimeData(mimeData, Qt::MoveAction, 0, 0, QModelIndex()));
+
+ index = m_model.indexForItem(item, TodoFlatModel::ParentRemoteId);
+ QCOMPARE(m_model.data(index).toString(), QString(""));
+
+ indexes.clear();
+}
+
#include "todotreemodeltest.moc"
--- branches/work/~ervin/zanshin/todoflatmodel.cpp #903965:903966
@@ -33,6 +33,8 @@
#include <KLocale>
#include <KDebug>
+#include <qmimedata.h>
+
typedef boost::shared_ptr<KCal::Incidence> IncidencePtr;
class TodoFlatModelImpl : public Akonadi::ItemModel
@@ -363,6 +365,21 @@
return false;
}
+QMimeData *TodoFlatModel::mimeData(const QModelIndexList &indexes) const
+{
+ QString ids;
+ foreach (const QModelIndex &index, indexes) {
+ if (!ids.isEmpty())
+ ids += ", ";
+ Akonadi::Item item = itemForIndex(index);
+ QModelIndex id = indexForItem(item, TodoFlatModel::RemoteId);
+ ids += data(id).toString();
+ }
+ QMimeData *mimeData = new QMimeData();
+ mimeData->setText(ids);
+ return mimeData;
+}
+
void TodoFlatModel::onSourceInsertRows(const QModelIndex&/*sourceIndex*/, int begin, \
int end) {
for (int i = begin; i <= end; i++) {
@@ -374,7 +391,6 @@
for (int i = begin; i <= end; i++) {
Akonadi::Item item = itemForIndex(index(i, 0));
- Akonadi::Entity::Id id = item.id();
QString remoteId = m_remoteIdMap[item.id()];
QString parentRemoteId = data(index(i, \
TodoFlatModel::ParentRemoteId)).toString(); @@ -427,3 +443,4 @@
return StandardTodo;
}
+
--- branches/work/~ervin/zanshin/todoflatmodel.h #903965:903966
@@ -52,6 +52,7 @@
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) \
const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = \
Qt::EditRole); + virtual QMimeData * mimeData ( const QModelIndexList & indexes ) \
const;
Akonadi::Item itemForIndex (const QModelIndex &index) const;
QModelIndex indexForItem (const Akonadi::Item &item, const int column) const;
--- branches/work/~ervin/zanshin/todotreemodel.cpp #903965:903966
@@ -23,8 +23,13 @@
#include <akonadi/collection.h>
#include <akonadi/item.h>
+#include <qmimedata.h>
+#include <qstringlist.h>
+
#include "todoflatmodel.h"
+#include <kdebug.h>
+
TodoTreeModel::TodoTreeModel(QObject *parent)
: QAbstractProxyModel(parent)
{
@@ -83,6 +88,39 @@
return TodoFlatModel::LastColumn + 1;
}
+QMimeData * TodoTreeModel::mimeData(const QModelIndexList &indexes) const
+{
+ QModelIndexList proxyIndexes;
+ foreach (const QModelIndex &sourceIndex, indexes) {
+ QModelIndex proxyIndex = mapToSource(sourceIndex);
+ proxyIndexes << proxyIndex;
+ }
+
+ return flatModel()->mimeData(proxyIndexes);
+}
+
+bool TodoTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int \
/*row*/, int /*column*/, const QModelIndex &parent) +{
+ if (action != Qt::MoveAction)
+ return false;
+
+ QStringList list = data->text().split(", ");
+ Akonadi::Item item = itemForIndex(parent);
+ QModelIndex parentIndex = indexForItem(item, TodoFlatModel::RemoteId);
+ QString remoteId = flatModel()->data(parentIndex).toString();
+ foreach(const QString id, list) {
+ QHash<QString, Akonadi::Entity::Id>::iterator it = \
m_remoteIdReverseMap.find(id); + if (it == m_remoteIdReverseMap.end())
+ return false;
+ Akonadi::Entity::Id akoId = it.value();
+ QModelIndex proxyIndex = indexForId(akoId, TodoFlatModel::ParentRemoteId);
+ if (!setData(proxyIndex, QVariant(remoteId))) {
+ return false;
+ }
+ }
+ return true;
+}
+
QVariant TodoTreeModel::headerData(int section, Qt::Orientation orientation, int \
role) const {
return flatModel()->headerData(section, orientation, role);
--- branches/work/~ervin/zanshin/todotreemodel.h #903965:903966
@@ -46,6 +46,8 @@
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
+ virtual bool dropMimeData(const QMimeData * data, Qt::DropAction action, int \
row, int column, const QModelIndex & parent); virtual QVariant headerData(int \
section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic