QGIS Coding and Compilation Guide
Total Page:16
File Type:pdf, Size:1020Kb
Quantum GIS Coding and Compilation Guide Version 1.5 'Thethys' Preamble This document is the original Coding and Compilation Guide of the described software Quantum GIS. The software and hardware described in this document are in most cases registered trademarks and are therefore subject to the legal requirements. Quantum GIS is subject to the GNU General Public License. Find more information on the Quantum GIS Homepage http://qgis.osgeo.org. The details, data, results etc. in this document have been written and verified to the best of knowledge and responsibility of the authors and editors. Nevertheless, mistakes concerning the content are possible. Therefore, all data are not liable to any duties or guarantees. The authors, editors and publishers do not take any responsibility or liability for failures and their consequences. Your are always welcome to indicate possible mistakes. This document has been typeset with LATEX. It is available as LATEX source code via subversion and online as PDF document via http://qgis.osgeo.org/documentation/manuals.html. Translated versions of this document can be downloaded via the documentation area of the QGIS project as well. For more information about contributing to this document and about translating it, please visit: http://www.qgis.org/wiki/index.php/Community_Ressources Links in this Document This document contains internal and external links. Clicking on an internal link moves within the document, while clicking on an external link opens an internet address. In PDF form, internal links are shown in blue, while external links are shown in red and are handled by the system browser. In HTML form, the browser displays and handles both identically. Coding Compilation Guide Authors and Editors: Tim Sutton Marco Hugentobler Gary E. Sherman Tara Athan Godofredo Contreras Werner Macho Carson J.Q. Farmer Otto Dassau Jürgen E. Fischer Davis Wills Magnus Homann Martin Dobias With thanks to Tisham Dhar for preparing the initial msys (MS Windows) environment documentation, to Tom Elwertowski and William Kyngesburye for help in the MAC OSX Installation Section and to Carlos Dávila. If we have neglected to mention any contributors, please accept our apologies for this oversight. Copyright °c 2004 - 2010 Quantum GIS Development Team Internet: http://qgis.osgeo.org License of this document Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foun- dation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. A copy of the license is included in section 11 entitled "GNU Free Documentation License". QGIS 1.5 Installation and Coding Guide iii Contents Contents Title i Preamble ii Table of Contents iv 1 Writing a QGIS Plugin in C++ 1 1.1 Why C++ and what about licensing ............................. 1 1.2 Programming a QGIS C++ Plugin in four steps ...................... 1 1.3 Further information ...................................... 19 2 Creating C++ Applications 20 2.1 Creating a simple mapping widget ............................. 20 2.2 Working with QgsMapCanvas ................................ 23 3 Writing a QGIS Plugin in Python 27 3.1 Why Python and what about licensing ........................... 27 3.2 What needs to be installed to get started .......................... 27 3.3 Programming a simple PyQGIS Plugin in four steps ................... 28 3.4 Uploading the plugin to the repository ........................... 31 3.5 Further information ...................................... 32 4 Creating PyQGIS Applications 33 4.1 Designing the GUI ...................................... 33 4.2 Creating the MainWindow .................................. 34 4.3 Finishing Up ......................................... 39 4.4 Running the Application ................................... 40 5 Installation Guide 43 5.1 General Build Notes ..................................... 43 5.1.1 An overview of the dependencies required for building .............. 43 5.2 Building under windows using msys ............................ 43 5.2.1 MSYS: ......................................... 44 5.2.2 Qt4.3 ......................................... 44 5.2.3 Flex and Bison .................................... 45 5.2.4 Python stuff: (optional) ................................ 45 5.2.5 Subversion: ...................................... 46 5.2.6 CMake: ........................................ 46 5.2.7 QGIS: ......................................... 47 5.2.8 Compiling: ...................................... 47 5.2.9 Configuration ..................................... 48 5.2.10 Compilation and installation ............................. 48 QGIS 1.5 Installation and Coding Guide iv Contents 5.2.11 Run qgis.exe from the directory where it’s installed (CMAKE_INSTALL_PREFIX) 48 5.2.12 Create the installation package: (optional) ..................... 49 5.3 Building on Mac OSX using frameworks and cmake or Xcode .............. 49 5.3.1 Install Xcode ..................................... 49 5.3.2 Install Qt4 from .dmg ................................. 50 5.3.3 Install development frameworks for QGIS dependencies ............. 50 5.3.4 Install CMake for OSX ................................ 56 5.3.5 Install subversion for OSX .............................. 56 5.3.6 Check out QGIS from SVN ............................. 57 5.3.7 Configure the build .................................. 58 5.3.8 Building ........................................ 60 5.4 Building on GNU/Linux .................................... 61 5.4.1 Building QGIS with Qt4.x .............................. 61 5.4.2 Prepare apt ...................................... 62 5.4.3 Install Qt4 ....................................... 62 5.4.4 Install additional software dependencies required by QGIS ........... 63 5.4.5 GRASS Specific Steps ................................ 63 5.4.6 Setup ccache (Optional) ............................... 64 5.4.7 Prepare your development environment ...................... 64 5.4.8 Check out the QGIS Source Code ......................... 64 5.4.9 Starting the compile ................................. 65 5.4.10 Building Debian packages .............................. 66 5.4.11 Running QGIS .................................... 67 5.4.12 A practical case: Building QGIS and GRASS from source on Ubuntu with ECW and MrSID formats support ............................. 67 5.5 Creation of MSYS environment for compilation of Quantum GIS ............. 72 5.5.1 Initial setup ...................................... 72 5.5.2 Installing dependencies ............................... 73 5.5.3 Cleanup ........................................ 76 5.6 Building with MS Visual Studio ............................... 77 5.6.1 Setup Visual Studio ................................. 77 5.6.2 Download/Install Dependencies ........................... 78 5.6.3 Building QGIS with CMAKE ............................. 82 5.7 Building under Windows using MSVC Express ...................... 82 5.7.1 System preparation ................................. 83 5.7.2 Install the libraries archive .............................. 83 5.7.3 Install Visual Studio Express 2005 ......................... 84 5.7.4 Install Microsoft Platform SDK2 ........................... 84 5.7.5 Edit your vsvars ................................... 87 5.7.6 Environment Variables ................................ 88 5.7.7 Building Qt4.3.2 ................................... 89 5.7.8 Install Python ..................................... 91 QGIS 1.5 Installation and Coding Guide v Contents 5.7.9 Install SIP ....................................... 91 5.7.10 Install PyQt4 ..................................... 91 5.7.11 Install CMake ..................................... 92 5.7.12 Install Subversion .................................. 92 5.7.13 Initial SVN Check out ................................ 92 5.7.14 Create Makefiles using cmakesetup.exe ...................... 93 5.7.15 Running and packaging ............................... 94 6 QGIS Coding Standards 95 6.1 Classes ............................................ 95 6.1.1 Names ........................................ 95 6.1.2 Members ....................................... 95 6.1.3 Accessor Functions ................................. 96 6.1.4 Functions ....................................... 96 6.2 Qt Designer .......................................... 96 6.2.1 Generated Classes .................................. 96 6.2.2 Dialogs ........................................ 97 6.3 C++ Files ........................................... 97 6.3.1 Names ........................................ 97 6.3.2 Standard Header and License ........................... 97 6.3.3 SVN Keyword ..................................... 98 6.4 Variable Names ........................................ 98 6.5 Enumerated Types ...................................... 98 6.6 Global Constants ....................................... 99 6.7 Editing ............................................. 99 6.7.1 Tabs .......................................... 99 6.7.2 Indentation ...................................... 99 6.7.3 Braces ......................................... 100 6.8 API Compatibility ....................................... 100 6.9 Coding Style ......................................... 101 6.9.1 Where-ever Possible Generalize Code ....................... 101 6.9.2 Prefer Having Constants First in Predicates .................... 101 6.9.3 Whitespace Can Be Your Friend