Related Plugins and Tags

QGIS Planet

Django : Faking it with South

So we use the super awesome South to manage schema changes when we change our django models. Basically South works in the background to make sure that your database is always in a consistent state with your models. Recently I have been adding South to a project and deploying these updates to my server. One [...]

Django : Faking it with South

So we use the super awesome South to manage schema changes when we change our django models. Basically South works in the background to make sure that your database is always in a consistent state with your models. Recently I have been adding South to a project and deploying these updates to my server. One of the tricky things I found is letting South know when your database is already in a consistent state and that it should mark its migration history as being up to date. Today I had a few moments to properly figure out how to do this. You can substitute RTFM for 'figure out' as you prefer. The trick is to do a fake migration like this:

python manage.py migrate someapp 0001 --fake

With 0001 being the migration state that you want to tell South that you are now at. This is documented here. One other noteworthy tip is that in the course of our updates, we are switching from Django 1.2.1 to 1.3.x and South gave me some pretty confusing error messages like this:

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "/home/web/sac/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/web/sac/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/web/sac/python/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
  self.execute(*args, **options.__dict__)
File "/home/web/sac/python/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
  output = self.handle(*args, **options)
File "/home/web/sac/python/lib/python2.7/site-packages/south/management/commands/schemamigration.py", line 83, in handle
  if migrations.app_label() not in getattr(last_migration.migration_class(), "complete_apps", []):
File "/home/web/sac/python/lib/python2.7/site-packages/south/migration/base.py", line 307, in migration_class
  return self.migration().Migration
AttributeError: 'module' object has no attribute 'Migration'

I didn't really find any useful help on google, but eventually resolved the issue by removing the .pyc files from the app/migrations/ folder and then everything just worked like magic.

Django development with Eclipse and PyDev

Eclipse is a Java IDE right? Wrong! You can use it for other languages too! I have been needing to improve my debugging techniques for python and Django (more on that in the future). This post outlines how you can set up Eclipse with PyDev to work on an existing Django aplication. The benifits? A [...]

Django development with Eclipse and PyDev

Eclipse is a Java IDE right? Wrong! You can use it for other languages too! I have been needing to improve my debugging techniques for python and Django (more on that in the future). This post outlines how you can set up Eclipse with PyDev to work on an existing Django aplication. The benifits? A complete IDE environment with a debugger that will let you set breakpoints anywhere in your app and interactively step through the code from that point.  You also get other nice things like refactoring support, code completion and so on. I'm still a dyed in the wool command line user since I can use my same development environment both locally and on a remote server effortlessly,  but for training courses and those who prefer to use a GUI, PyDev on Eclipse will probably make a compelling alternative. lets see how to get is set up (after the break below)...

These steps are also explained in the PyDev documentation which is quite good. First you need to doHelp->Install New Software. Then click on the 'Add...' button and fill in the details as shown below:

Add the PyDev extensions (click for larger image)

Next choose the PyDeb and PyDev Extensions item from the 'work with' list and wait a moment (PyDeb in the screenshots is a typo in my part  - it should read 'PyDev').  Then tick 'PyDev' from the software list and untick 'Contact all update sites to find required software'. Then click next and wait while the packages download. It took a few attempts to work for me on our slow internet connection. After you are done, click finish to close the installer and restart Eclipse as prompted.

Choose the PyDev source and select PyDev from the list (click for larger image).

I'm going to assume that you have an existing Django web site you want to work with, but note that the PyDev will also happily create a new Django project from scratch for you. I'm also assuming you prefer to work with python virtual environments since you are not a crazy nutter right? Right, good so here are the steps I followed for an existing project:

  •  create a new django project in your Eclipse project workspace named the same as your existing project
  • remove the project director and replace it with a symlink to your real project
  • setup Eclipse to be aware of our virtualenv
  • set breakpoints, run the development server and generally have fun with Django within an IDE

So first up open Eclipse and use a workspace (I took the default one as shown below):

|Open a workspace (click for larger image)|

Next, create a new Django project: File -> New -> Project.... and then choose PyDev Django Project from the dialog that appears.

Create a new django project (click for larger image)

Click next and then you should give the project the same name as the existing Django project that you want to bring into Eclipse (in my case greatcircle). Also choose 'don't configure PYTHONPATH' from the options in the dialog that appears:

Configure your project (click for larger version)

Use the hyperlink on the above dialog to configure your python interpreter. On the screen that appears we get to tell PyDev where our virtualenvironment is. Click New...then fill the interpreter details in like this:

Point pydev to your virtual environment (click for larger version)

When you click OK, a dialog like this will appear, and you should enable the system python ('/usr/lib/python2.7' in my case) too.

Configured python interpreter dialog (click for larger view)

Clicking OK will take  you back to the Eclipse preferences window and should look something like this:

Final view of Eclipse preferences (click for larger view)

Now click OK and it will start doing some magic stuff, eventually bringing you back to the 'PyDev Django Project' dialog. Be sure to change the interpreter option to 'GreatCircle VirtualEnvironment' (or similar based on your previous choices). Click next and you will be prompted for your database connection details. You can completely ignore this since we will be grafting in the settings from our existing 'greatcircles' project below. So clicking Finish will end this part of the process.

At this point you should completely close Eclipse and carefully run the following commands (substituting details for your own project of course):

cd ~/workspace/greatcircle/
rm -rf greatcircle
ln -s /home/web/greatcircle/greatcircle greatcircle

Basically, the commands just substitute the PyDev generated stub project with a symbolic link to the real project. Now we can open up Eclipse again and open our project. You may need to press F5 to refresh the project view before you see all your real project files. Good so now we have our project all set up in Eclipse it should look something like this:

Our django project loaded in Eclipse (click for larger image)

The last part of this article covers debugging. The process is really simple.  First open a source file (for example views.py) and then double click in a margin where you would like to place a break point.

Setting a breakpoint in your project (click for larger image)

Next you can run the django development server  by right clicking on the project and from the context menu choosing Debug As -> PyDeb: Django.

Launching the debugger (click for larger image)

PyDev will prompt you to switch to the debug perspective. Now you can go ahead and open the site in your browser. When you hit the url that triggers the breakpoint, PyDev will stop, highlight the line and you can use the normal debugging tools for there on. You can view the state of any variable while django is running and so on.

Debugging your Django application interactively - woohoo! (Click for larger image)

From my limited usage, it doesn't quite have the power of my traditional pdb command line debugging environment. For example being able to change variables at runtime and so on. It does however offer the convenience of not needing to insert extra code into your sources to trigger breakpoints.

Eclipse feels big and unwieldy to me after using my svelte command line environment for this kind of thing, but it does have some compelling features and makes a great platform for training people who are command line averse. I'm going to revisit PyDev again in a future article to see how well it works as a platform for writing and debugging QGIS plugins.

A nice QGIS tutorial by Lex Berman

Lex Berman from Harvard just dropped me a nice email with a link to an interactive QGIS tutorial he has created. The tutorial is one of the nicest I have seen – each section is detailed with text, screenshots and howto videos.  I thought I would make a quick post about it here so the [...]

A nice QGIS tutorial by Lex Berman

Lex Berman from Harvard just dropped me a nice email with a link to aninteractive QGIS tutorial he has created. The tutorial is one of the nicest I have seen - each section is detailed with text, screenshots and howto videos.  I thought I would make a quick post about it here so the rest of the world can enjoy it too!

Lex's cool online tutorial (click to visit the site)

Compiling QGIS with Eclipts CDT on Ubuntu

Everything I’m about to tell you you should probably forget – in my brief experience with it, Eclipse makes for an inferior alternative to Qt Creator if you are looking for a GUI to do development on QGIS with. That said, there are those for whom Eclipse is their weapon of choice. My primary motivation [...]

Compiling QGIS with Eclipse CDT on Ubuntu

Everything I'm about to tell you you should probably forget - in my brief experience with it, Eclipse makes for an inferior alternative to Qt Creator if you are looking for a GUI to do development on QGIS with. That said, there are those for whom Eclipse is their weapon of choice. My primary motivation for testing eclipse was that I wanted to use the Eclipse refactoring tools which in days of yore when I did a lot of Java programming proved to be the IDE's saving grace. I wanted the refactoring tools because for QGIS 2.0 we are planning an API cleanup and I was hoping that it would make the process easier. Ok so let's dive in (read on after the break for details)

First we install Eclipse-CDT - the C++ environment for Eclipse. Under Ubuntu you should simply be able to do:

sudo apt-get install eclipse-cdt

If you live in South Africa, go make a cup of tea since Eclipse and all its dependencies is a bit of a beast to download...

Ok so next I am assuming you already have a checkout of Quantum-GIS cloned from our github repository, and all the build requirements as outlined in the INSTALL file at the top of the source tree.

CMake includes a project generator for eclipse-cdt so making a project is quite easy. There is one thing you need to be aware of though - the cmake build directory should be a sibling and not a child of the Quantum-GIS checkout directory. This small nuance I missed the first time and the consequence of having the build directory under the Quantum-GIS tree is that you won't see any source files in the Eclipse project.

|- Quantum-GIS
|- Quantum-GIS-build-eclipse

So your source tree and your build dir are in the same level in the file system hierarchy as illustrated in the above masterfully drawn ascii art. Now you need to tell cmake to create the build files like this (from within the Quantum-GIS-build-eclipse directory):

cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE\_BUILD\_TYPE=Debug
../Quantum-GIS

It will whirrr and clunk for a little and then you should have a nicely prepared build directory. Next you need to fire up Eclipse (again go have a cup of tea, it takes ages to start on my system). Now you need to import the project we just made. Do File -> import and then complete the process as shown in my screenshots below (click for larger images) :

Importing your cmake project

Importing your project step 2

In my last screenshot above, the 'Finish' button is disabled because I had already imported the project once, but it should be enabled for you at this point. Now that your project is imported, is should look something like this:

Our project loaded into Eclipse

You can go ahead and build QGIS now by pressing Ctrl-B. Once again it built somewhat slowly for me - probably it uses only a single core to do the donkey work by default. Now comes the moment of truth - can we use the refactor too? I highlighted a variable as shown below and then got the error shown beneath that.

Invoking the refactor tool in Eclipse

Refactoring was a non-starter

It was a bit of a disappointment because I was really hoping I could use the Eclipse refactoring goodness on QGIS for 2.0. Perhaps if someone out there can see something I may have missed in order for it to work, you would be so kind as to let me know in the comment section below? Hopefully for those who are most comfortable in Eclipse, the above will act as a primer to get you working with the QGIS code base under your preferred IDE. Look out for another couple of  Eclipse article from me in the near future as I have been testing it under PyDev for QGIS plugin and Django development. Now where did I leave my VIM.....?

Work mantras – an off FOSSGIS topic post

Running a small business is a challenge. I came into this as a FOSS geek with a grandiose plan of spreading the FOSS GIS goodness far and wide and somehow earning a living from it. I don’t have an MBA or any significant business skills so I have been learning everything from first principles as [...]

Work mantras - an off FOSSGIS topic post

Running a small business is a challenge. I came into this as a FOSS geek with a grandiose plan of spreading the FOSS GIS goodness far and wide and somehow earning a living from it. I don't have an MBA or any significant business skills so I have been learning everything from first principles as I go along. Using `Scrum`_ project management has been a huge step forward for us and has been instrumental on us creating a much more effective work process within the office. The next biggest challenge we have faced on our journey is how to motivate and get the best out of our staff. Having staff is a double edged sword in a small business - they can boost your productivity and earning power, but they also cost a lot of money and time (training and supervision). One of the things we do with our staff is have a bonus system whereby a percentage of their salary is dependent on performance. This theoretically motivates them to work harder to achieve their maximum earning power.

There are two problems with this bonus system though:

  1. It assumes staff are motivated by money
  2. It assumes you have a decent and efficient way to calibrate whether your staff members have earned their bonus or not

I am going to use Rudi as an example for this discussion (with his permission). Rudi is a young, extremely intelligent geek with deep interest in computers, technology, gaming, and writing web comics, among other things. Sounds perfect right? It is in many respects, except that you will notice that 'a never ending love of money and material goods' is missing from the list. Which means that item 1. above runs into problems. To address this, we have asked Rudi to see the allocation of bonuses as a point of prestige. Rudi grasps this concept well since he is a gamer and uses sites like stack exchange where prestige is currency de rigeur.

Item two on our problem list has also been a challenge with us. It is a problem in a number of ways. If we decide on the bonus allocation in a manner which is opaque to Rudi, he has no understanding of what is required to earn the bonus and thus it becomes 'black magic' to him and he will lose interest in the system. Another issue is that even if the criteria are shared with Rudi, he may feel we are unfair in our appraisal of the criteria. For example, we might say to Rudi that we are holding his bonus back this week because there were too many bugs in the code he committed. Rudi may feel this is unfair as the bugs may be side effects of other work or something he had no control over. To address the issue of calibration, we decided to turn the problem on its head.

How did we do this? The first thing we did was to collaboratively define the bonus criteria with Rudi. That means that each criterion was discussed and agreed apon as being a reasonable expectation. We tried to structure the criteria to include both 'hard' measurable items ("your code must be documented") and 'soft woolly' items ("you must bring more into the office than you took out"). We also tried to structure the criteria as a progression through his daily work flow - from arriving at work in the morning to working through the problems of the day, to leaving in the afternoon with a sense of 'I feel good about the work I did'. The final piece to the puzzle, and the most important is that we made the process self-monitoring.

By self-monitoring, I mean that we assigned Rudi the responsibility of noting when he doesn't meet his own criteria. To do this, we created a laminated wall chart that looks like this:

Rudi's daily mantra (click for larger view)

Whenever Rudi realises he hasn't achieved one of his mantra's, he will place an X in the day column next to that item. This moves all the responsibility of monitoring onto Rudi himself, and we only need to intervene if we feel that he has missed and opportunity to chastise himself - 'don't you think you should put an X in that column for forgetting to `talk to the duck`_ to help you solve your problem?'.

With our mantra sheets, allocating bonuses is now doable in a fair and efficient way, and there is a very visual reminder whenever we go off the rails. I am going to be making my own mantra sheet so that I can try to improve my own focus on my work.  Having staff in the office is great in many ways - it's good to have someone to interact with and share ideas, bounce problems around with and have some office banter with. But its also challenging to keep them motivated and focused so we are constantly looking for ways to make things run more smoothly. Do you have things that work well and help you bring out the best in your staff? Let us know in the comments below, we would love to hear your ideas!

My favourite VIM tip

I’ve been a VIM user for many years and over that time I have tweaked my vimrc a little (not too much mind you). I have one modification that I use probably hundreds of times a day. " Added by Tim to map alt-left/right to flip through buffers nmap <A-Left> :bp<CR> nmap <A-Right> :bn<CR> Adding [...]

My favourite VIM tip

I've been a VIM user for many years and over that time I have tweaked my vimrc a little (not too much mind you). I have one modification that I use probably hundreds of times a day.

" Added by Tim to map alt-left/right to flip through buffers
nmap <A-Left> :bp<CR>
nmap <A-Right> :bn<CR>

Adding the above to your ~/.vimrc file will let you quickly hop between buffers - pressing alt-right arrow will take you to the next buffer and pressing alt-left arrow will take you to the previous buffer.

More on QGIS Desktop web fusion

So my previous article about fusing QGIS Desktop with web technologies generated quite a bit of interest, including some people interested to start hacking on it (always a good sign). In this article I want to show the next level of functionality we can obtain by means of a simple example. There won’t be any [...]

More on QGIS Desktop web fusion

So my previous article about fusing QGIS Desktop with web technologies generated quite a bit of interest, including some people interested to start hacking on it (always a good sign). In this article I want to show the next level of functionality we can obtain by means of a simple example. There won't be any flashy graphics here but hopefully it will give you inspiration for other things we can do.

Here is the executive summary and a quick video to demonstrate it:

  • I replaced Metadata tab in the QGIS Raster Layer Properties with a QWebView widget
  • I created asimple web page that accepts a C++ QgsRasterLayer object and then does stuff with it
  • I implemented a Q_PROPERTY on QgsMapLayer (the base class for all map layers) that exposed the metadata property as a read-only property.
  • I created a customised BluePrint CSS template (using a narrower format than the traditional 960 grid) and deployed it in QGIS resources
  • I added a simple button  to the form and used a bit of jquery and javascript to call a slot on the QgsRasterLayer and retrieve its min and max scale properties, then update the page

More details after the break below...

The video demonstrates how the page gets rendered (I havent bothered too much with css etc yet beyond using blueprint for layout), and then the min/max scale is queried from the QgsRasterLayer object. I then change these properties on the general tab, then come back to the metadata tab and when clicking the button, you can see the javascript is hooked into a 'live' copy of my QgsRasterLayer object.

[advanced_iframe securitykey="da39a3ee5e6b4b0d3255bfef95601890afd80709" src="http://www.youtube.com/embed/8xBXUPrvwLQ" height="315" width="560"]

You can browse the changesI pushed to my fork of QGIS today so see how I implemented all of this. It was a few minutes work (if you disregard the formatting tweaking I did to the metadata to make it more blueprint friendly). If anyone would like to start pitching in, it would be really nice to have some designers start tweaking the content we deliver in these QWebViews to make them look gob-smackingly beautiful! Next on  my todo list is to make the providers return their metadata as json and then we can properly separate the content from the mark up (and use the metadata in other interesting contexts too).

Centering table cell contents with xhtml2pdf

If you’ve tried centering table cell contents in xhtml2pdf, you’ve probably noticed that it doesn’t work.  The typical symptoms seem to be that cell contents are right against (or even over) the upper border of the cell. For reasons unknown, xhtml2pdf ignores “vertical-align” instructions, so you can’t use that.  To solve the problem, I did [...]

Centering table cell contents with xhtml2pdf

If you've tried centering table cell contents in xhtml2pdf, you've probably noticed that it doesn't work.  The typical symptoms seem to be that cell contents are right against (or even over) the upper border of the cell.

For reasons unknown, xhtml2pdf ignores "vertical-align" instructions, so you can't use that.  To solve the problem, I did this:

table th, td {
  padding-top: 3px;
  padding-bottom: 2px;
  line-height: 50%;
}

You may want to add some more to this for the sake of appearance, but that's the gist of it.

Fusing web technologies with QGIS

The Python bindings for QGIS introduced just before version 1.0 was released proved to be a huge boon to the development of QGIS as a popular, free alternative to proprietary vendor’s offerings. More than 100 plugins grace our plugin repository, and the ability to use Python scripting has really lowered the barrier to entry for [...]

Fusing web technologies with QGIS

The Python bindings for QGIS introduced just before version 1.0 was released proved to be a huge boon to the development of QGIS as a popular, free alternative to proprietary vendor's offerings. More than 100 plugins grace our plugin repository, and the ability to use Python scripting has really lowered the barrier to entry for many who would find building similar tools in C++ (the 'native' language of QGIS) too intimidating. Lately I have been pondering the future of QGIS 2.0. In particular my feeling is that we pretty much have the standard functionality of a desktop GIS application covered and it is time to step out of 'emulate' mode into 'innovate' mode. Not that QGIS 1.x entirely lacks innovation, but I believe there is a lot more that can be done.

At the recent developer meeting in Zurich, I had some enjoyable conversations with Andreas Neumann and others. Andreas showed off some examples of the awesome D3 javascript svg visualisation toolkit. I had seen the kit before in its former guise as protovis, but I hadn't ever seen quite the extent of all the cool things you could do with it. Parallel to Andreas' presentation, I had been pondering fusing web technologies with QGIS. Now let me start out by explaining that living in a low bandwidth society has made me quite cautious about building web tools for the masses, but what I am talking about here is using web technologies on the desktop without any need for an internet connection. D3 is just one example of many hundreds of javascript libraries out there that cover a whole gamut of functionality. I would argue that the javascript universe is far richer than the Qt/C++ one and far easier to 'pick up and use'. Combined with this rich javascript resource is the fact that recent versions of Qt4 ship with QWebView, a webkit based widget that you can place onto any form. More than that, Qt4 provides entry points for calling javascript routines from C++ and passing C++ objects into the javascript context. Though I havent tested it yet, you can also use Qt4's signal and slot mechnism from within the Javascript context.

If you take a minute to think about this, you will realize that this opens up a world of possibilities: what if we use C++ for the heavy lifting and Javascript + CSS + html for our visualisation in QGIS? Not for map rendering per se, but for all the other places where you need to see charts, tables, reports, metadata and so on. And what is really nice is that we have a fixed browser platform to work against, and complete platform independent capability, without any of the overhead that Python for example introduces (like having to ship a separate interpreter with the QGIS binaries). Plus the multitude of people that can already do web programming suddenly have an easy way to start contributing to QGIS.

To demonstrate this idea I have updated my fork of QGIS to use JQuery, Flot and some html to do the rendering of the histogram in the raster layer properties dialog. You can see a little demo of this below:

[advanced_iframe securitykey="da39a3ee5e6b4b0d3255bfef95601890afd80709" src="http://www.youtube.com/embed/TVVvFzvhCUM" height="315" width="560"]

While building this I noticed a couple of nice benefits:

  • I can debug my javascript separately in a browser
  • I can update the html / javascript and simply reinstall those files while QGIS is still running and immediately see the results
  • Whatever libraries I chose to use (jquery and flot in this case) were trivial to package with QGIS and I didnt need to worry about making the user e.g. install a separate python package before they could use my code
  • The code to implement the graph was much simpler than my former Qwt based implementation and it was trivial to add the zoom capability shown in the video above
  • The rendered graph looks much nicer than the Qwt one it replaces without any effort on my part
  • It was fun to work on!

And this last point is probably the most important - the more fun it is to hack on QGIS, the more likely we will get others to contribute. Hopefully we can also start attracting web innovators like my friend Javier de la Torre from Vizzuality to see QGIS as a place where they can bring the awesome stuff they are doing on the web into the desktop environment! I have quite a few other ideas as to how we can leverage this technology further so look out for further posts on the topic.

Building a QWizard in Qt4 using designer

Building a wizard in designer is overly complex and has a few pitfalls. This is especially the case when you try to build your wizard using Qt4 Designer exclusively. The main problem comes in due to the fact that although you can happily place any widgets you like onto a QWizardPage, in the QWizard you [...]

Building a QWizard in Qt4 using designer

Building a wizard in designer is overly complex and has a few pitfalls. This is especially the case when you try to build your wizard using Qt4 Designer exclusively. The main problem comes in due to the fact that although you can happily place any widgets you like onto a QWizardPage, in the QWizard you cannot actually access them at run time. So that makes it useful for adding static content like labels or text but pretty challenging for everything else. A while ago I implemented a welcome wizard for QGIS but never actually applied it trunk. Today I had occasion to dust off the cobwebs and I thought I would write this up to explain how I did it since you won't find much help on Google on the matter.

Ok, so first up, I created a new QWizard implementation (qgswelcomewizardbase.ui) using designer like this.

Our wizard in designer

So thats fine for page one, but on page two I want some dynamic content - in this case a checkbox. You would think I could just click next in designer and plonk it on the page here:

No programmatically accessible widgets on the QWizard pages!

Rather you need to create a separate QWizardPage widget and drop your controls on there like this:

Create a separate QWizardPage where you need programmatic access to widgets.

Next you need to create an implementation class for the page widget. I called my ui 'qgschoosetoregisterbase.ui' (catchy name I know), so my inheriting class will be QgsChooseToRegister. It looks like this (all implemented directly in the header):

#ifndef QGSCHOOSETOREGISTERPAGE_H
#define QGSCHOOSETOREGISTERPAGE_H

#include <ui_qgschoosetoregisterpagebase.h>

/** \ingroup app
 * \brief a custom page (by promotion in designer) so that we
 * can access added widgets on this page from within the QWizard context.
 * @author Tim Sutton
 * */

class QgsChooseToRegisterPage : public QWizardPage, public Ui::QgsChooseToRegisterPageBase
{
  Q_OBJECT;

  public:
    QgsChooseToRegisterPage(){
      setupUi( this );
      setTitle( tr( "Would you like to register on our user's map?" ) );
    };
    ~QgsChooseToRegisterPage(){};
};

#endif

As you can see, it doesn't do much. If you wanted to, you could also user registerField() calls in this function to make any widgets globally accessible from the wizard. Next comes the real trick, and that is to promote the empty page widget in designer for our QWizard  to our new class. To do this, right click on the page object in the object inspector and promote it to the QgsChoosToRegister class. You probably won't have that latter listed already, in which case you should add it to the list of promotable classes by right clicking on the page widget in the object inspector and choosing 'promote to...'. Then fill in the form to look like the screenshot below and click the add button to make it part of the list of promoted classes.  Then you can close and do the aforementioned step as illustrated in the two screenshots below.

Creating a promotable class in designer

Promoting the QWizardPage to our custom class

There is one last piece of the puzzle - how you actually access the control (in our case the checkbox above). The code below is from our implementation class for the QWizard and illustrates how to do this.

int QgsWelcomeWizard::nextId() const
{
  switch ( currentId() )
  {
    case StartPage:
        return ChooseToRegisterPage;
    case ChooseToRegisterPage:
      if ( mChooseToRegisterPage->mCbxRegister->isChecked() )
      {
        mRegisterPage->webView->setUrl( QUrl( "http://users.qgis.org/community-map/create_user_form.html" ) );
        return RegisterPage;
      }
      else
      {
        return ThanksPage;
      }
    case RegisterPage:
        return ThanksPage;
    default:
      return -1;
  }
}

To access the checkbox I simply called

setPage( ChooseToRegisterPage, mChooseToRegisterPage ),

in the init function of the page and then used the

mChooseToRegisterPage->mCbxRegister->isChecked()

To see if the checkbox was checked.

Hopefully this will prove helpful to others out there who run into the same issues. The process described above is still a lot faster than hand coding your wizard, though I thing the Qt4 folks could make like a lot easier still by providing some glue to access the content of the wizard pages.

Back to Top

Sustaining Members