|
|
(Není zobrazeno 28 mezilehlých verzí od stejného uživatele.) |
Řádek 1: |
Řádek 1: |
| {{Upravit}} | | {{freegiswiki|QGIS / Tvorba zásuvného modulu}} |
| | |
| Stránka obsahuje poznámky pro tvorbu vlastního [http://cs.wikipedia.org/wiki/Plugin zásuvného modulu] pro aplikaci [[QGIS]]. Navržený modul má na vstupu dvě vektorové vrstvy - bodovou a polygonovou. Na výstupu vytvoří novou vektorovou vrstvu obsahující pouze body ležící uvnitř polygonů (viz [[Programování s knihovnou OGR#Prostorové predikáty|příklad pro knihovnu OGR]]). Uvedený text čerpá především z [http://download.osgeo.org/qgis/doc/manual/qgis-1.5.0_coding-compilation_guide_en.pdf QGIS Coding and Compilation Guide]. Zdrojové texty najdete [http://geo.fsv.cvut.cz/~landa/vyuka/2010/qgis/sampleplugin/ zde].
| |
| | |
| __TOC__
| |
| == Minimální kód ==
| |
| | |
| Projekt obsahuje tři soubory:
| |
| | |
| ; Soubor projektu sampleplugin.pro
| |
| | |
| <source lang="cpp">
| |
| # cesta k adresari se zdrojovymi texty QGISu
| |
| QGIS_DIR = /opt/src/qgis_trunk
| |
| TEMPLATE = lib
| |
| CONFIG = qt
| |
| QT += xml
| |
| unix:LIBS += -L/$$QGIS_DIR/lib \
| |
| -lqgis_core \
| |
| -lqgis_gui
| |
| INCLUDEPATH += $$QGIS_DIR/src/ui \
| |
| $$QGIS_DIR/src/plugins \
| |
| $$QGIS_DIR/src/gui \
| |
| $$QGIS_DIR/src/raster \
| |
| $$QGIS_DIR/src/core \
| |
| $$QGIS_DIR
| |
| SOURCES = qgssampleplugin.cpp
| |
| HEADERS = qgssampleplugin.h
| |
| DEST = sampleplugin.so
| |
| DEFINES += GUI_EXPORT= \
| |
| CORE_EXPORT=
| |
| </source>
| |
| | |
| ; Hlavičkový soubor pluginu qgssampleplugin.h
| |
| | |
| <source lang="cpp">
| |
| #ifndef QGSSAMPLEPLUGIN_H
| |
| #define QGSSAMPLEPLUGIN_H
| |
| | |
| #include "qgisplugin.h"
| |
| | |
| /* Testovaci plugin pro QGIS - prostorove predikaty */
| |
| class QgsSamplePlugin: public QgisPlugin
| |
| {
| |
| public:
| |
| QgsSamplePlugin(QgisInterface *);
| |
| ~QgsSamplePlugin();
| |
| | |
| void initGui();
| |
| void unload();
| |
| | |
| private:
| |
| QgisInterface *mIface;
| |
| };
| |
| | |
| #endif // QGSSAMPLEPLUGIN_H
| |
| </source>
| |
| | |
| ; C++ soubor qgssampleplugin.cpp
| |
| | |
| <source lang="cpp">
| |
| #include "qgssampleplugin.h"
| |
| | |
| #ifdef WIN32
| |
| #define QGISEXTERN extern "C" __declspec( dllexport )
| |
| #else
| |
| #define QGISEXTERN extern "C"
| |
| #endif
| |
| | |
| QgsSamplePlugin::QgsSamplePlugin(QgisInterface* iface): mIface(iface)
| |
| {
| |
| }
| |
| | |
| QgsSamplePlugin::~QgsSamplePlugin()
| |
| {
| |
| }
| |
| | |
| // Zobrazit elementy GUI nastrojove listy a menu pluginu
| |
| void QgsSamplePlugin::initGui()
| |
| {
| |
| }
| |
| | |
| // Odstranit alokovane GUI elementy
| |
| void QgsSamplePlugin::unload()
| |
| {
| |
| }
| |
| | |
| // generator pluginu
| |
| QGISEXTERN QgisPlugin* classFactory(QgisInterface* iface)
| |
| {
| |
| return new QgsSamplePlugin(iface);
| |
| }
| |
| | |
| QGISEXTERN QString name()
| |
| {
| |
| return "Within";
| |
| }
| |
| | |
| QGISEXTERN QString description()
| |
| {
| |
| return "Prostorovy predikat within";
| |
| }
| |
| | |
| QGISEXTERN QString version()
| |
| {
| |
| return "0.00001";
| |
| }
| |
| | |
| // Typ pluginu (UI nebo MapLayer plugin)
| |
| QGISEXTERN int type()
| |
| {
| |
| return QgisPlugin::UI;
| |
| }
| |
| | |
| // Odstranit plugin
| |
| QGISEXTERN void unload(QgisPlugin* theQgsSamplePluginPointer)
| |
| {
| |
| delete theQgsSamplePluginPointer;
| |
| }
| |
| </source>
| |
| | |
| == Ikonka, tlačítko a menu pluginu ==
| |
| | |
| Modifikujeme [http://doc.qgis.org/head/classQgisInterface.html QgisInterface], přidáme [http://doc.trolltech.com/4.7/qaction.html QAction] se slotem <tt>calculate()</tt>. Třída <tt>SamplePlugin</tt> bude odvozena z třídy [http://doc.trolltech.com/latest/qobject.html QObject].
| |
| | |
| ; Hlavička
| |
| | |
| <source lang="cpp">
| |
| ...
| |
| #include "qgisplugin.h"
| |
| #include <QObject>
| |
| | |
| class QAction;
| |
| | |
| /* Testovaci plugin pro QGIS - prostorove predikaty */
| |
| class QgsSamplePlugin: public QObject, public QgisPlugin
| |
| {
| |
| Q_OBJECT // nutne pro pouziti mechanismu signalu a slotu
| |
| ...
| |
| | |
| private:
| |
| QgisInterface *mIface;
| |
| QAction *mAction;
| |
| | |
| private slots:
| |
| void calculate();
| |
| };
| |
| | |
| #endif // QGSSAMPLEPLUGIN_H
| |
| </source>
| |
| | |
| ; C++ soubor
| |
| | |
| <source lang="cpp">
| |
| #include "qgssampleplugin.h"
| |
| #include "qgisinterface.h"
| |
| #include <QAction>
| |
| | |
| ...
| |
| | |
| QgsSamplePlugin::QgsSamplePlugin(QgisInterface* iface): mIface(iface), mAction(0)
| |
| {
| |
| }
| |
| | |
| ...
| |
| | |
| // Zobrazit elementy GUI nastrojove listy a menu pluginu
| |
| void QgsSamplePlugin::initGui()
| |
| {
| |
| mAction = new QAction(tr("&Within"), this);
| |
| connect(mAction, SIGNAL(activated()), this, SLOT(calculate()));
| |
| mIface->addToolBarIcon(mAction);
| |
| mIface->addPluginToMenu(tr("&Prostorovy predikat"), mAction);
| |
| }
| |
| | |
| // Odstranit alokovane GUI elementy
| |
| void QgsSamplePlugin::unload()
| |
| {
| |
| mIface->removeToolBarIcon(mAction);
| |
| mIface->removePluginMenu(tr("&Prostorovy predikat"), mAction);
| |
| delete mAction;
| |
| }
| |
| | |
| void QgsSamplePlugin::calculate()
| |
| {
| |
|
| |
| }
| |
| | |
| ...
| |
| </source>
| |
| | |
| == Odkazy ==
| |
| | |
| * [http://download.osgeo.org/qgis/doc/manual/qgis-1.5.0_coding-compilation_guide_en.pdf QGIS Coding and Compilation Guide]
| |
| * [http://doc.qgis.org/head/ QGIS API]
| |
| | |
| {{GFOSS}}
| |
| {{Programování}}
| |
| {{C++}}
| |