Skip to content
Permalink
Browse files

mime for drag and drop, not finished

  • Loading branch information
blazek committed Jun 14, 2011
1 parent 2670283 commit 27db9c3ca240d9ab89884c034a0276321160da93
Showing with 47 additions and 1 deletion.
  1. +6 −0 src/browser/qgsbrowserbase.ui
  2. +36 −1 src/browser/qgsbrowsermodel.cpp
  3. +5 −0 src/browser/qgsbrowsermodel.h
@@ -45,6 +45,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
</widget>
<widget class="QTabWidget" name="tabWidget">
<property name="enabled">
@@ -80,7 +80,14 @@ Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex & index ) const
if ( !index.isValid() )
return 0;

return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;

QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
if ( ptr->type() != QgsDataItem::Layer )
{
flags |= Qt::ItemIsDragEnabled;
}
return flags;
}

QVariant QgsBrowserModel::data( const QModelIndex & index, int role ) const
@@ -313,3 +320,31 @@ void QgsBrowserModel::connectItem( QgsDataItem* item )
connect( item, SIGNAL( endRemoveItems() ),
this, SLOT( endRemoveItems() ) );
}

QStringList QgsBrowserModel::mimeTypes() const
{
QStringList types;
types << "text/uri-list";
return types;
}

QMimeData * QgsBrowserModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;

QDataStream stream(&encodedData, QIODevice::WriteOnly);

foreach (const QModelIndex &index, indexes) {
if (index.isValid()) {
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
if ( ptr->type() != QgsDataItem::Layer ) continue;
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
QString text = layer->uri();
stream << text;
}
}

mimeData->setData("text/uri-list", encodedData);
return mimeData;
}
@@ -3,6 +3,7 @@

#include <QAbstractItemModel>
#include <QIcon>
#include <QMimeData>

#include "qgsdataitem.h"

@@ -41,6 +42,9 @@ class QgsBrowserModel : public QAbstractItemModel
/** Returns the parent of the model item with the given index. If the item has no parent, an invalid QModelIndex is returned. */
virtual QModelIndex parent( const QModelIndex & index ) const;

virtual QStringList mimeTypes() const;

QMimeData * mimeData(const QModelIndexList &indexes) const;

bool hasChildren( const QModelIndex & parent = QModelIndex() ) const;

@@ -50,6 +54,7 @@ class QgsBrowserModel : public QAbstractItemModel
void refresh( const QModelIndex& index = QModelIndex() );

void connectItem( QgsDataItem * item );

signals:

public slots:

0 comments on commit 27db9c3

Please sign in to comment.
You can’t perform that action at this time.