mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
[FEATURE] Add project loading support from browser
This commit is contained in:
parent
19dcd21b6d
commit
ffd7c9436f
@ -47,6 +47,8 @@ class QgsDataItem : QObject
|
|||||||
sipType = sipType_QgsZipItem;
|
sipType = sipType_QgsZipItem;
|
||||||
else if (qobject_cast<QgsDataCollectionItem*>(sipCpp))
|
else if (qobject_cast<QgsDataCollectionItem*>(sipCpp))
|
||||||
sipType = sipType_QgsDataCollectionItem;
|
sipType = sipType_QgsDataCollectionItem;
|
||||||
|
else if (qobject_cast<QgsProjectItem*>(sipCpp))
|
||||||
|
sipType = sipType_QgsProjectItem;
|
||||||
else
|
else
|
||||||
sipType = 0;
|
sipType = 0;
|
||||||
%End
|
%End
|
||||||
@ -324,6 +326,21 @@ class QgsDirectoryItem : QgsDataCollectionItem
|
|||||||
// static QVector<QLibrary*> mLibraries;
|
// 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)
|
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 ) ) ) );
|
QgsDebugMsg( QString( "rowCount() = %1" ).arg( mModel->rowCount( mProxyModel->mapToSource( index ) ) ) );
|
||||||
QgsDataItem *item = mModel->dataItem( 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 )
|
if ( item != NULL && item->type() == QgsDataItem::Layer )
|
||||||
{
|
{
|
||||||
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( item );
|
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( item );
|
||||||
@ -566,6 +576,21 @@ void QgsBrowserDockWidget::addSelectedLayers()
|
|||||||
QModelIndexList list = mBrowserView->selectionModel()->selectedIndexes();
|
QModelIndexList list = mBrowserView->selectionModel()->selectedIndexes();
|
||||||
qSort( list );
|
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
|
// add items in reverse order so they are in correct order in the layers dock
|
||||||
for ( int i = list.size() - 1; i >= 0; i-- )
|
for ( int i = list.size() - 1; i >= 0; i-- )
|
||||||
{
|
{
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QtConcurrentMap>
|
#include <QtConcurrentMap>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
#include "qgis.h"
|
#include "qgis.h"
|
||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
@ -185,7 +186,7 @@ Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex & index ) const
|
|||||||
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
|
|
||||||
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
|
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
|
||||||
if ( ptr->type() == QgsDataItem::Layer )
|
if ( ptr->type() == QgsDataItem::Layer || ptr->type() == QgsDataItem::Project )
|
||||||
{
|
{
|
||||||
flags |= Qt::ItemIsDragEnabled;
|
flags |= Qt::ItemIsDragEnabled;
|
||||||
}
|
}
|
||||||
@ -448,6 +449,16 @@ QMimeData * QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
|
|||||||
if ( index.isValid() )
|
if ( index.isValid() )
|
||||||
{
|
{
|
||||||
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
|
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;
|
if ( ptr->type() != QgsDataItem::Layer ) continue;
|
||||||
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
|
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
|
||||||
lst.append( QgsMimeDataUtils::Uri( layer ) );
|
lst.append( QgsMimeDataUtils::Uri( layer ) );
|
||||||
|
@ -813,6 +813,13 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren()
|
|||||||
QString path = dir.absoluteFilePath( name );
|
QString path = dir.absoluteFilePath( name );
|
||||||
QFileInfo fileInfo( path );
|
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
|
// vsizip support was added to GDAL/OGR 1.6 but GDAL_VERSION_NUM not available here
|
||||||
// so we assume it's available anyway
|
// so we assume it's available anyway
|
||||||
{
|
{
|
||||||
@ -1064,6 +1071,17 @@ void QgsDirectoryParamWidget::showHideColumn()
|
|||||||
settings.setValue( "/dataitem/directoryHiddenColumns", lst );
|
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 )
|
QgsErrorItem::QgsErrorItem( QgsDataItem* parent, const QString& error, const QString& path )
|
||||||
: QgsDataItem( QgsDataItem::Error, parent, error, path )
|
: QgsDataItem( QgsDataItem::Error, parent, error, path )
|
||||||
|
@ -84,7 +84,8 @@ class CORE_EXPORT QgsDataItem : public QObject
|
|||||||
Directory,
|
Directory,
|
||||||
Layer,
|
Layer,
|
||||||
Error,
|
Error,
|
||||||
Favourites
|
Favourites,
|
||||||
|
Project
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Create new data item. */
|
/** Create new data item. */
|
||||||
@ -424,6 +425,19 @@ class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
|
|||||||
bool mRefreshLater;
|
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)
|
Data item that can be used to report problems (e.g. network error)
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user