Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow to use WMS as static provider
  • Loading branch information
PeterPetrik committed Sep 4, 2019
1 parent 4e51938 commit 635c1b5
Show file tree
Hide file tree
Showing 32 changed files with 355 additions and 131 deletions.
17 changes: 13 additions & 4 deletions CMakeLists.txt
Expand Up @@ -74,18 +74,27 @@ endif(NOT MSVC)

IF (IOS)
SET (DEFAULT_FORCE_STATIC_LIBS TRUE)
SET (DEFAULT_FORCE_STATIC_PROVIDERS TRUE)
ELSE (IOS)
SET (DEFAULT_FORCE_STATIC_LIBS FALSE)
SET (DEFAULT_FORCE_STATIC_PROVIDERS FALSE)
ENDIF (IOS)

SET (FORCE_STATIC_LIBS ${DEFAULT_FORCE_STATIC_LIBS} CACHE BOOL "Determines whether libraries should be static only")
MARK_AS_ADVANCED(FORCE_STATIC_LIBS)

IF(FORCE_STATIC_LIBS)
SET(LIBRARY_TYPE STATIC)
IF (FORCE_STATIC_LIBS)
SET (LIBRARY_TYPE STATIC)
ELSE (FORCE_STATIC_LIBS)
SET(LIBRARY_TYPE SHARED)
SET (LIBRARY_TYPE SHARED)
ENDIF (FORCE_STATIC_LIBS)

SET (FORCE_STATIC_PROVIDERS ${DEFAULT_FORCE_STATIC_PROVIDERS} CACHE BOOL "Determines whether data providers should be static only")
MARK_AS_ADVANCED(FORCE_STATIC_PROVIDERS)
IF (FORCE_STATIC_PROVIDERS)
# following variable is used in qgsconfig.h
SET (HAVE_STATIC_PROVIDERS TRUE)
ENDIF (FORCE_STATIC_PROVIDERS)

# in generated makefiles use relative paths so the project dir is moveable
# Note commented out since it cause problems but it would be nice to resolve these and enable
#
Expand Down
2 changes: 2 additions & 0 deletions cmake_templates/qgsconfig.h.in
Expand Up @@ -71,5 +71,7 @@

#cmakedefine HAVE_QT5SERIALPORT

#cmakedefine HAVE_STATIC_PROVIDERS

#endif

17 changes: 14 additions & 3 deletions python/core/auto_generated/qgsdataitem.sip.in
Expand Up @@ -122,7 +122,15 @@ Removes a child item and returns it without deleting it. Emits relevant signals
%Docstring
Returns ``True`` if this item is equal to another item (by testing item type and path).
%End
virtual QWidget *paramWidget() /Factory/;

virtual QWidget *paramWidget() /Factory,Deprecated/;
%Docstring
Returns source widget from data item for :py:class:`QgsBrowserPropertiesWidget`

Use QgsDataItemGuiProvider.createParamWidget() instead

.. deprecated:: QGIS 3.10
%End

virtual QList<QAction *> actions( QWidget *parent );
%Docstring
Expand Down Expand Up @@ -616,7 +624,7 @@ Returns the full path to the directory the item represents.

virtual QIcon icon();

virtual QWidget *paramWidget() /Factory/;
virtual QWidget *paramWidget() /Factory,Deprecated/;

virtual bool hasDragEnabled() const;
virtual QgsMimeDataUtils::Uri mimeUri() const;
Expand Down Expand Up @@ -680,9 +688,12 @@ Data item that can be used to report problems (e.g. network error)
};



class QgsDirectoryParamWidget : QTreeWidget
{
%Docstring

TODO: move to qgis_gui for QGIS 4
%End

%TypeHeaderCode
#include "qgsdataitem.h"
Expand Down
11 changes: 11 additions & 0 deletions python/gui/auto_generated/qgsdataitemguiprovider.sip.in
Expand Up @@ -144,6 +144,17 @@ Called when a user drops on an ``item``. Providers should return ``True``
if the drop was handled and do not want other providers to handle the
drop, and to prevent the default drop behavior for items.

.. versionadded:: 3.10
%End

virtual QWidget *createParamWidget( QgsDataItem *item, QgsDataItemGuiContext context ) /Factory/;
%Docstring
Creates source widget from data item for :py:class:`QgsBrowserPropertiesWidget`
By default it returns None.
Caller takes responsibility of deleting created.

The function is replacement of :py:func:`QgsDataItem.paramWidget()`

.. versionadded:: 3.10
%End
};
Expand Down
Expand Up @@ -79,6 +79,7 @@ The function is replacement of QgsProviderRegistry.createSelectionWidget() from

.. versionadded:: 3.10
%End

private:
QgsSourceSelectProviderRegistry( const QgsSourceSelectProviderRegistry &rh );
};
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Expand Up @@ -11,8 +11,8 @@ IF (WITH_GUI)
ADD_SUBDIRECTORY(auth)
ENDIF (WITH_GUI)

ADD_SUBDIRECTORY(providers)
IF (NOT IOS)
ADD_SUBDIRECTORY(providers)
ADD_SUBDIRECTORY(crssync)
ENDIF (NOT IOS)

Expand Down
12 changes: 6 additions & 6 deletions src/app/browser/qgsinbuiltdataitemproviders.cpp
Expand Up @@ -199,7 +199,7 @@ void QgsAppDirectoryItemGuiProvider::populateContextMenu( QgsDataItem *item, QMe
QAction *propertiesAction = new QAction( tr( "Properties…" ), menu );
connect( propertiesAction, &QAction::triggered, this, [ = ]
{
showProperties( directoryItem );
showProperties( directoryItem, context );
} );
menu->addAction( propertiesAction );

Expand Down Expand Up @@ -264,15 +264,15 @@ void QgsAppDirectoryItemGuiProvider::toggleFastScan( QgsDirectoryItem *item )
settings.setValue( QStringLiteral( "qgis/scanItemsFastScanUris" ), fastScanDirs );
}

void QgsAppDirectoryItemGuiProvider::showProperties( QgsDirectoryItem *item )
void QgsAppDirectoryItemGuiProvider::showProperties( QgsDirectoryItem *item, QgsDataItemGuiContext context )
{
if ( ! item )
return;

QgsBrowserPropertiesDialog *dialog = new QgsBrowserPropertiesDialog( QStringLiteral( "browser" ), QgisApp::instance() );
dialog->setAttribute( Qt::WA_DeleteOnClose );

dialog->setItem( item );
dialog->setItem( item, context );
dialog->show();
}

Expand Down Expand Up @@ -423,7 +423,7 @@ void QgsLayerItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *men
QAction *propertiesAction = new QAction( tr( "Layer Properties…" ), menu );
connect( propertiesAction, &QAction::triggered, this, [ = ]
{
showPropertiesForItem( layerItem );
showPropertiesForItem( layerItem, context );
} );
menu->addAction( propertiesAction );

Expand Down Expand Up @@ -523,14 +523,14 @@ void QgsLayerItemGuiProvider::deleteLayers( const QStringList &itemPaths, QgsDat
}
}

void QgsLayerItemGuiProvider::showPropertiesForItem( QgsLayerItem *item )
void QgsLayerItemGuiProvider::showPropertiesForItem( QgsLayerItem *item, QgsDataItemGuiContext context )
{
if ( ! item )
return;

QgsBrowserPropertiesDialog *dialog = new QgsBrowserPropertiesDialog( QStringLiteral( "browser" ), QgisApp::instance() );
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->setItem( item );
dialog->setItem( item, context );
dialog->show();
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/browser/qgsinbuiltdataitemproviders.h
Expand Up @@ -46,7 +46,7 @@ class QgsAppDirectoryItemGuiProvider : public QObject, public QgsDataItemGuiProv
void renameFavorite( QgsFavoriteItem *favorite );
void hideDirectory( QgsDirectoryItem *item );
void toggleFastScan( QgsDirectoryItem *item );
void showProperties( QgsDirectoryItem *item );
void showProperties( QgsDirectoryItem *item, QgsDataItemGuiContext context );
};


Expand Down Expand Up @@ -99,7 +99,7 @@ class QgsLayerItemGuiProvider : public QObject, public QgsDataItemGuiProvider
private:

void addLayersFromItems( const QList<QgsDataItem *> &items );
void showPropertiesForItem( QgsLayerItem *item );
void showPropertiesForItem( QgsLayerItem *item, QgsDataItemGuiContext context );
void deleteLayers( const QStringList &itemPath, QgsDataItemGuiContext context );

};
Expand Down
10 changes: 10 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -1495,6 +1495,16 @@ TARGET_LINK_LIBRARIES(qgis_core
${LIBZIP_LIBRARY}
)

IF (FORCE_STATIC_PROVIDERS)
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/providers/wms
)

TARGET_LINK_LIBRARIES(qgis_core
wmsprovider_a
)
ENDIF (FORCE_STATIC_PROVIDERS)

IF (MSVC)
#needed for linking to gdal which needs odbc
SET(TARGET_LINK_LIBRARIES qgis_core odbc32 odbccp32)
Expand Down
15 changes: 12 additions & 3 deletions src/core/qgsdataitem.h
Expand Up @@ -142,7 +142,15 @@ class CORE_EXPORT QgsDataItem : public QObject
* Returns TRUE if this item is equal to another item (by testing item type and path).
*/
virtual bool equal( const QgsDataItem *other );
virtual QWidget *paramWidget() SIP_FACTORY { return nullptr; }

/**
* Returns source widget from data item for QgsBrowserPropertiesWidget
*
* Use QgsDataItemGuiProvider::createParamWidget() instead
*
* \deprecated QGIS 3.10
*/
Q_DECL_DEPRECATED virtual QWidget *paramWidget() SIP_FACTORY SIP_DEPRECATED { return nullptr; }

/**
* Returns the list of actions available for this item. This is usually used for the popup menu on right-clicking
Expand Down Expand Up @@ -625,7 +633,7 @@ class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem

bool equal( const QgsDataItem *other ) override;
QIcon icon() override;
QWidget *paramWidget() override SIP_FACTORY;
Q_DECL_DEPRECATED QWidget *paramWidget() override SIP_FACTORY SIP_DEPRECATED;
bool hasDragEnabled() const override { return true; }
QgsMimeDataUtils::Uri mimeUri() const override;

Expand Down Expand Up @@ -682,12 +690,13 @@ class CORE_EXPORT QgsErrorItem : public QgsDataItem

};


// ---------

/**
* \ingroup core
* \class QgsDirectoryParamWidget
*
* TODO: move to qgis_gui for QGIS 4
*/
class CORE_EXPORT QgsDirectoryParamWidget : public QTreeWidget
{
Expand Down
15 changes: 12 additions & 3 deletions src/core/qgsproviderregistry.cpp
Expand Up @@ -35,6 +35,9 @@
#include "providers/gdal/qgsgdalprovider.h"
#include "providers/ogr/qgsogrprovider.h"
#include "providers/meshmemory/qgsmeshmemorydataprovider.h"
#ifdef HAVE_STATIC_PROVIDERS
#include "qgswmsprovider.h"
#endif

static QgsProviderRegistry *sInstance = nullptr;

Expand Down Expand Up @@ -97,17 +100,23 @@ QgsProviderRegistry::QgsProviderRegistry( const QString &pluginPath )

void QgsProviderRegistry::init()
{
typedef QgsProviderMetadata *factory_function( );

// add static providers
Q_NOWARN_DEPRECATED_PUSH
mProviders[ QgsMemoryProvider::providerKey() ] = new QgsProviderMetadata( QgsMemoryProvider::providerKey(), QgsMemoryProvider::providerDescription(), &QgsMemoryProvider::createProvider );
mProviders[ QgsMeshMemoryDataProvider::providerKey() ] = new QgsProviderMetadata( QgsMeshMemoryDataProvider::providerKey(), QgsMeshMemoryDataProvider::providerDescription(), &QgsMeshMemoryDataProvider::createProvider );
Q_NOWARN_DEPRECATED_POP
mProviders[ QgsGdalProvider::providerKey() ] = new QgsGdalProviderMetadata();
mProviders[ QgsOgrProvider::providerKey() ] = new QgsOgrProviderMetadata();
#ifdef HAVE_STATIC_PROVIDERS
mProviders[ QgsWmsProvider::providerKey() ] = new QgsWmsProviderMetadata();
#endif

// add dynamic providers
#ifdef HAVE_STATIC_PROVIDERS
QgsDebugMsg( QStringLiteral( "Forced only static providers" ) );
#else
typedef QgsProviderMetadata *factory_function( );

mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );

Expand Down Expand Up @@ -177,7 +186,7 @@ void QgsProviderRegistry::init()
// add this provider to the provider map
mProviders[meta->key()] = meta;
}

#endif
QgsDebugMsg( QStringLiteral( "Loaded %1 providers (%2) " ).arg( mProviders.size() ).arg( providerList().join( ';' ) ) );

// now initialize all providers
Expand Down
9 changes: 9 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -1123,6 +1123,15 @@ TARGET_LINK_LIBRARIES(qgis_gui
${Qt5QuickWidgets_LIBRARIES}
)

IF (FORCE_STATIC_PROVIDERS)
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/providers/wms
)
TARGET_LINK_LIBRARIES(qgis_gui
wmsprovider_gui_a
)
ENDIF (FORCE_STATIC_PROVIDERS)

IF(ENABLE_MODELTEST)
TARGET_LINK_LIBRARIES(qgis_gui ${Qt5Test_LIBRARIES})
ENDIF(ENABLE_MODELTEST)
Expand Down
5 changes: 3 additions & 2 deletions src/gui/qgsbrowserdockwidget.cpp
Expand Up @@ -444,7 +444,7 @@ void QgsBrowserDockWidget::showProperties()
{
QgsBrowserPropertiesDialog *dialog = new QgsBrowserPropertiesDialog( settingsSection(), this );
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->setItem( item );
dialog->setItem( item, createContext() );
dialog->show();
}
}
Expand Down Expand Up @@ -563,7 +563,8 @@ void QgsBrowserDockWidget::setPropertiesWidget()
{
QModelIndex index = mProxyModel->mapToSource( indexes.value( 0 ) );
QgsDataItem *item = mModel->dataItem( index );
QgsBrowserPropertiesWidget *propertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, mPropertiesWidget );
QgsDataItemGuiContext context = createContext();
QgsBrowserPropertiesWidget *propertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context, mPropertiesWidget );
if ( propertiesWidget )
{
propertiesWidget->setCondensedMode( true );
Expand Down

0 comments on commit 635c1b5

Please sign in to comment.