Skip to content

Commit

Permalink
mime for drag and drop, not finished
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jun 14, 2011
1 parent 2670283 commit 27db9c3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/browser/qgsbrowserbase.ui
Expand Up @@ -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">
Expand Down
37 changes: 36 additions & 1 deletion src/browser/qgsbrowsermodel.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions src/browser/qgsbrowsermodel.h
Expand Up @@ -3,6 +3,7 @@

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

#include "qgsdataitem.h"

Expand Down Expand Up @@ -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;

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

void connectItem( QgsDataItem * item );

signals:

public slots:
Expand Down

0 comments on commit 27db9c3

Please sign in to comment.