Skip to content
Permalink
Browse files

Add class QgsSourceSelectProvider and tests

This is the first step for QEP 101
  • Loading branch information
elpaso committed Sep 1, 2017
1 parent d915242 commit cd1c9b1e280785310021c8ecd38fcabeb3ed2a2a
@@ -405,3 +405,4 @@
%Include symbology/qgsarrowsymbollayer.sip
%Include composer/qgscomposerutils.sip
%Include qgsuserprofile.sip

@@ -297,3 +297,5 @@
%Include locator/qgslocatorfilter.sip
%Include locator/qgslocatorwidget.sip
%Include qgsadvanceddigitizingcanvasitem.sip
%Include qgssourceselectprovider.sip

@@ -0,0 +1,59 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgssourceselectprovider.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsSourceSelectProvider
{
%Docstring
.. seealso:: QgsDataSourceManagerDialog

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgssourceselectprovider.h"
%End
public:
virtual ~QgsSourceSelectProvider();

virtual QString providerKey() const = 0;
%Docstring
Provider key
:rtype: str
%End

virtual QString text() const = 0;
%Docstring
Text for the menu item entry
:rtype: str
%End

virtual QIcon icon() const = 0 /Factory/;
%Docstring
Caller takes responsibility of deleting created.
:rtype: QIcon
%End

virtual QgsAbstractDataSourceWidget *createDataSourceWidget( ) = 0 /Factory/;
%Docstring
Caller takes responsibility of deleting created.
:rtype: QgsAbstractDataSourceWidget
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgssourceselectprovider.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -349,6 +349,7 @@ SET(QGIS_GUI_SRCS
qgsfiledownloader.cpp
qgsdatasourcemanagerdialog.cpp
qgsabstractdatasourcewidget.cpp
qgssourceselectprovider.cpp
)

SET(QGIS_GUI_MOC_HDRS
@@ -711,6 +712,7 @@ SET(QGIS_GUI_HDRS
qgsfiledownloader.h
qgsdatasourcemanagerdialog.h
qgsabstractdatasourcewidget.h
qgssourceselectprovider.h

ogr/qgsogrhelperfunctions.h
ogr/qgsnewogrconnection.h
@@ -0,0 +1,20 @@
/***************************************************************************
qgssourceselectprovider.cpp - QgsSourceSelectProvider
---------------------
begin : 1.9.2017
copyright : (C) 2017 by Alessandro Pasotti
email : apasotti at boundlessgeo dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgssourceselectprovider.h"


// no implementation currently

@@ -0,0 +1,53 @@
/***************************************************************************
qgssourceselectprovider.h - QgsSourceSelectProvider
---------------------
begin : 1.9.2017
copyright : (C) 2017 by Alessandro Pasotti
email : apasotti at boundlessgeo dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSSOURCESELECTPROVIDER_H
#define QGSSOURCESELECTPROVIDER_H


#include "qgis_gui.h"
#include "qgis.h"
#include "qgsabstractdatasourcewidget.h"

class QString;

/** \ingroup gui
* This is the interface for those who want to add entries to the \see QgsDataSourceManagerDialog
*
* \since QGIS 3.0
*/
class GUI_EXPORT QgsSourceSelectProvider
{
public:
virtual ~QgsSourceSelectProvider() = default;

//! Provider key
virtual QString providerKey() const = 0;

//! Text for the menu item entry
virtual QString text() const = 0;

//! Creates a new instance of an QIcon for the menu item entry
//! Caller takes responsibility of deleting created.
virtual QIcon icon() const = 0 SIP_FACTORY;

//! Create a new instance of QgsAbstractDataSourceWidget (or null).
//! Caller takes responsibility of deleting created.
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( ) = 0 SIP_FACTORY;

};


#endif // QGSSOURCESELECTPROVIDER_H
@@ -176,6 +176,7 @@ ADD_PYTHON_TEST(PyQgsDBManagerGpkg test_db_manager_gpkg.py)
ADD_PYTHON_TEST(PyQgsFileDownloader test_qgsfiledownloader.py)
ADD_PYTHON_TEST(PyQgsSettings test_qgssettings.py)
ADD_PYTHON_TEST(PyQgsZipUtils test_qgsziputils.py)
ADD_PYTHON_TEST(PyQgsSourceSelectProvider test_qgssourceselectprovider.py)

IF (NOT WIN32)
ADD_PYTHON_TEST(PyQgsLogger test_qgslogger.py)
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
"""
Test the QgsSourceSelectProvider class
Run with: ctest -V -R PyQgsSourceSelectProvider
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""

import os
import tempfile
from qgis.gui import (QgsSourceSelectProvider, QgsAbstractDataSourceWidget)
from qgis.testing import start_app, unittest
from qgis.PyQt.QtGui import QIcon

__author__ = 'Alessandro Pasotti'
__date__ = '01/09/2017'
__copyright__ = 'Copyright 2017, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'


start_app()


class ConcreteDataSourceWidget(QgsAbstractDataSourceWidget):
pass


class ConcreteSourceSelectProvider(QgsSourceSelectProvider):

def providerKey(self):
return "MyTestProviderKey"

def text(self):
return "MyTestProviderText"

def icon(self):
return QIcon()

def createDataSourceWidget(self):
return ConcreteDataSourceWidget()


class TestQgsSourceSelectProvider(unittest.TestCase):

def setUp(self):
pass

def tearDown(self):
pass

def testConcreteClass(self):

provider = ConcreteSourceSelectProvider()
self.assertTrue(isinstance(provider, ConcreteSourceSelectProvider))
widget = provider.createDataSourceWidget()
self.assertTrue(isinstance(widget, ConcreteDataSourceWidget))
self.assertEqual(provider.providerKey(), "MyTestProviderKey")
self.assertEqual(provider.text(), "MyTestProviderText")
self.assertTrue(isinstance(provider.icon(), QIcon))


if __name__ == '__main__':
unittest.main()

0 comments on commit cd1c9b1

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