Skip to content
Permalink
Browse files
[FEATURE] Add project loading support from browser
  • Loading branch information
NathanW2 committed Dec 11, 2015
1 parent 19dcd21 commit ffd7c9436fb2888b8e5ada52968d231f49173876
Showing with 87 additions and 2 deletions.
  1. +17 −0 python/core/qgsdataitem.sip
  2. +25 −0 src/app/qgsbrowserdockwidget.cpp
  3. +12 −1 src/core/qgsbrowsermodel.cpp
  4. +18 −0 src/core/qgsdataitem.cpp
  5. +15 −1 src/core/qgsdataitem.h
@@ -47,6 +47,8 @@ class QgsDataItem : QObject
sipType = sipType_QgsZipItem;
else if (qobject_cast<QgsDataCollectionItem*>(sipCpp))
sipType = sipType_QgsDataCollectionItem;
else if (qobject_cast<QgsProjectItem*>(sipCpp))
sipType = sipType_QgsProjectItem;
else
sipType = 0;
%End
@@ -324,6 +326,21 @@ class QgsDirectoryItem : QgsDataCollectionItem
// static QVector<QLibrary*> mLibraries;
};

/**
Data item that can be used to represent QGIS projects.
*/
class QgsProjectItem : QgsDataItem
{
%TypeHeaderCode
#include <qgsdataitem.h>
%End
public:

QgsProjectItem( QgsDataItem* parent, const QString& name, const QString& path );
~QgsProjectItem();

};

/**
Data item that can be used to report problems (e.g. network error)
*/
@@ -541,6 +541,16 @@ void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex& index )
QgsDebugMsg( QString( "rowCount() = %1" ).arg( mModel->rowCount( mProxyModel->mapToSource( index ) ) ) );
QgsDataItem *item = mModel->dataItem( mProxyModel->mapToSource( index ) );

if ( item != NULL && item->type() == QgsDataItem::Project )
{
QgsProjectItem *projectItem = qobject_cast<QgsProjectItem*>( item );
if ( projectItem != NULL )
{
QApplication::setOverrideCursor( Qt::WaitCursor );
QgisApp::instance()->openFile( projectItem->path() );
QApplication::restoreOverrideCursor();
}
}
if ( item != NULL && item->type() == QgsDataItem::Layer )
{
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( item );
@@ -566,6 +576,21 @@ void QgsBrowserDockWidget::addSelectedLayers()
QModelIndexList list = mBrowserView->selectionModel()->selectedIndexes();
qSort( list );

// If any of the layer items are QGIS we just open and exit the loop
for ( int i = 0; i <= list.size(); i++ )
{
QgsDataItem *item = mModel->dataItem( mProxyModel->mapToSource( list[i] ) );
if ( item && item->type() == QgsDataItem::Project )
{
QgsProjectItem *projectItem = qobject_cast<QgsProjectItem*>( item );
if ( projectItem )
QgisApp::instance()->openFile( projectItem->path() );

QApplication::restoreOverrideCursor();
return;
}
}

// add items in reverse order so they are in correct order in the layers dock
for ( int i = list.size() - 1; i >= 0; i-- )
{
@@ -16,6 +16,7 @@
#include <QApplication>
#include <QStyle>
#include <QtConcurrentMap>
#include <QUrl>

#include "qgis.h"
#include "qgsapplication.h"
@@ -185,7 +186,7 @@ Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex & index ) const
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;

QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
if ( ptr->type() == QgsDataItem::Layer )
if ( ptr->type() == QgsDataItem::Layer || ptr->type() == QgsDataItem::Project )
{
flags |= Qt::ItemIsDragEnabled;
}
@@ -448,6 +449,16 @@ QMimeData * QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
if ( index.isValid() )
{
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
if ( ptr->type() == QgsDataItem::Project )
{
QMimeData *mimeData = new QMimeData();
QUrl url = QUrl::fromLocalFile( ptr->path() );
QList<QUrl> urls;
urls << url;
mimeData->setUrls( urls );
return mimeData;
}

if ( ptr->type() != QgsDataItem::Layer ) continue;
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
lst.append( QgsMimeDataUtils::Uri( layer ) );
@@ -813,6 +813,13 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren()
QString path = dir.absoluteFilePath( name );
QFileInfo fileInfo( path );

if ( fileInfo.suffix() == "qgs" )
{
QgsDataItem * item = new QgsProjectItem( this, name, path );
children.append( item );
continue;
}

// vsizip support was added to GDAL/OGR 1.6 but GDAL_VERSION_NUM not available here
// so we assume it's available anyway
{
@@ -1064,6 +1071,17 @@ void QgsDirectoryParamWidget::showHideColumn()
settings.setValue( "/dataitem/directoryHiddenColumns", lst );
}

QgsProjectItem::QgsProjectItem( QgsDataItem* parent, const QString &name, const QString& path )
: QgsDataItem( QgsDataItem::Project, parent, name, path )
{
mIconName = ":/images/icons/qgis-icon-16x16.png";

setState( Populated ); // no more children
}

QgsProjectItem::~QgsProjectItem()
{
}

QgsErrorItem::QgsErrorItem( QgsDataItem* parent, const QString& error, const QString& path )
: QgsDataItem( QgsDataItem::Error, parent, error, path )
@@ -84,7 +84,8 @@ class CORE_EXPORT QgsDataItem : public QObject
Directory,
Layer,
Error,
Favourites
Favourites,
Project
};

/** Create new data item. */
@@ -424,6 +425,19 @@ class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
bool mRefreshLater;
};

/**
Data item that can be used to represent QGIS projects.
*/
class CORE_EXPORT QgsProjectItem : public QgsDataItem
{
Q_OBJECT
public:

QgsProjectItem( QgsDataItem* parent, const QString& name, const QString& path );
~QgsProjectItem();

};

/**
Data item that can be used to report problems (e.g. network error)
*/

0 comments on commit ffd7c94

Please sign in to comment.