~ubuntu-branches/ubuntu/hardy/qgis/hardy

« back to all changes in this revision

Viewing changes to src/qgisapp.h

  • Committer: Bazaar Package Importer
  • Author(s): William Grant
  • Date: 2007-05-06 13:42:32 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070506134232-pyli6t388w5asd8x
Tags: 0.8.0-3ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules, debian/qgis.install, debian/qgis.dirs debian/qgis.desktop:
    Add and install .desktop.
* debian/qgis.desktop: Remove Applications category; it's not real.
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                          qgisapp.h  -  description
3
 
                             -------------------
4
 
    begin                : Sat Jun 22 2002
5
 
    copyright            : (C) 2002 by Gary E.Sherman
6
 
    email                : sherman at mrcc.com
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
11
 
 *   This program is free software; you can redistribute it and/or modify  *
12
 
 *   it under the terms of the GNU General Public License as published by  *
13
 
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 
 *   (at your option) any later version.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
17
 
/*  $Id: qgisapp.h,v 1.136.2.3 2005/09/09 22:08:07 mcoletti Exp $ */
18
 
 
19
 
#ifndef QGISAPP_H
20
 
#define QGISAPP_H
21
 
 
22
 
class QCanvas;
23
 
class QRect;
24
 
class QCanvasView;
25
 
class QStringList;
26
 
class QScrollView;
27
 
class QgsPoint;
28
 
class QgsLegend;
29
 
class QgsLegendView;
30
 
class QVBox;
31
 
class QCursor;
32
 
class QLabel;
33
 
class QListView;
34
 
class QListViewItem;
35
 
class QProgressBar;
36
 
class QFileInfo;
37
 
class QgsMapLayer;
38
 
class QSettings;
39
 
class QSocket;
40
 
class QgsProviderRegistry;
41
 
class QgsHelpViewer;
42
 
class QgsMapCanvas;
43
 
class QgsMapLayerRegistry;
44
 
class QgsRasterLayer;
45
 
class QCheckBox;
46
 
class QEvent;
47
 
class QgsComposer;
48
 
class QPushButton;
49
 
#ifdef WIN32
50
 
#include "qgisappbase.h"
51
 
#else
52
 
#include "qgisappbase.uic.h"
53
 
#endif
54
 
#include "qgisiface.h"
55
 
#include "splashscreen.h"
56
 
#include "qgsconfig.h"
57
 
#include "qgsvectordataprovider.h"
58
 
 
59
 
#include <map>
60
 
 
61
 
static SplashScreen * gSplashScreen ;
62
 
 
63
 
 
64
 
/*! \class QgisApp
65
 
 * \brief Main window for the Qgis application
66
 
 */
67
 
class QgisApp : public QgisAppBase
68
 
{
69
 
    Q_OBJECT;
70
 
 
71
 
public:
72
 
 
73
 
    //! Constructor
74
 
    QgisApp(QWidget * parent = 0, const char *name = 0, WFlags fl = WType_TopLevel);
75
 
 
76
 
    ~QgisApp();
77
 
 
78
 
    QgisIface *getInterface();
79
 
 
80
 
    /** \brief Set the Z order of both mapcanvas and overview
81
 
     * canvas. Typically this will be called by projectio when loading a
82
 
     * stored project.
83
 
     */
84
 
    void setZOrder (std::list<QString>);
85
 
 
86
 
    void addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey);
87
 
    /** \brief overloaded vesion of the privat addLayer method that takes a list of
88
 
    * filenames instead of prompting user with a dialog.
89
 
    @param enc encoding type for the layer 
90
 
    @returns true if successfully added layer
91
 
 
92
 
    @note
93
 
 
94
 
    This should be deprecated because it's possible to have a
95
 
    heterogeneous set of files; i.e., a mix of raster and vector.
96
 
    It's much better to try to just open one file at a time.
97
 
 
98
 
    */
99
 
    bool addLayer(QStringList const & theLayerQStringList, const QString& enc);
100
 
 
101
 
    /** open a vector layer for the given file
102
 
 
103
 
    
104
 
    @returns false if unable to open a raster layer for rasterFile
105
 
 
106
 
      @note
107
 
 
108
 
      This is essentially a simplified version of the above
109
 
    */
110
 
    bool addLayer(QFileInfo const & vectorFile);
111
 
 
112
 
 
113
 
    /** overloaded vesion of the private addRasterLayer()
114
 
 
115
 
    Method that takes a list of filenames instead of prompting
116
 
    user with a dialog.
117
 
 
118
 
    @returns true if successfully added layer(s)
119
 
 
120
 
    @note
121
 
 
122
 
    This should be deprecated because it's possible to have a
123
 
    heterogeneous set of files; i.e., a mix of raster and vector.
124
 
    It's much better to try to just open one file at a time.
125
 
 
126
 
    */
127
 
    bool addRasterLayer(QStringList const & theLayerQStringList, bool guiWarning=true);
128
 
 
129
 
 
130
 
    /** open a raster layer for the given file
131
 
 
132
 
       @returns false if unable to open a raster layer for rasterFile
133
 
 
134
 
       @note
135
 
 
136
 
       This is essentially a simplified version of the above
137
 
    */
138
 
    bool addRasterLayer(QFileInfo const & rasterFile, bool guiWarning=true);
139
 
 
140
 
    /** Add a 'pre-made' map layer to the project */
141
 
    void addMapLayer(QgsMapLayer *theMapLayer);
142
 
 
143
 
    /** Set the extents of the map canvas */
144
 
    void setExtent(QgsRect theRect);
145
 
 
146
 
    //! Remove all layers from the map and legend - reimplements same method from qgisappbase
147
 
    void removeAllLayers();
148
 
 
149
 
    /** Open a raster or vector file; ignore other files.
150
 
    Used to process a commandline argument or OpenDocument AppleEvent.
151
 
    @returns true if the file is successfully opened
152
 
    */
153
 
    bool openLayer(const QString & fileName);
154
 
 
155
 
    /** Open the specified project file; prompt to save previous project if necessary.
156
 
    Used to process a commandline argument or OpenDocument AppleEvent.
157
 
    */
158
 
    void openProject(const QString & fileName);
159
 
 
160
 
    /** opens a qgis project file
161
 
    @returns false if unable to open the project
162
 
 
163
 
    */
164
 
    bool addProject(QString projectFile);
165
 
 
166
 
    //!Overloaded version of the private function with same name that takes the imagename as a parameter
167
 
    void saveMapAsImage(QString, QPixmap *);
168
 
    QgsMapCanvas * getMapCanvas() { return mMapCanvas; };
169
 
 
170
 
    /** return the layer registry
171
 
 
172
 
       @note
173
 
 
174
 
       Returns QgsMapLayerRegistry::instance(); i.e., it's a Singleton
175
 
    */
176
 
    QgsMapLayerRegistry * getLayerRegistry();
177
 
 
178
 
    //! Set theme (icons)
179
 
    void setTheme(QString themeName="default");
180
 
    //! Setup the toolbar popup menus for a given theme
181
 
    void setupToolbarPopups(QString themeName);
182
 
 
183
 
private:
184
 
 
185
 
    //! Add a vector layer to the map
186
 
    void addLayer();
187
 
    //! Add a raster layer to the map (will prompt user for filename using dlg
188
 
    void addRasterLayer();
189
 
    //! Add a raster layer to the map (passed in as a ptr). It waont force a refresh unless you explicitly
190
 
    //use the force redraw flag.
191
 
    //
192
 
    bool addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRedrawFlag=false);
193
 
    //@todo We should move these next two into vector layer class
194
 
    /** This helper checks to see whether the filename appears to be a valid vector file name */
195
 
    bool isValidVectorFileName (QString theFileNameQString);
196
 
    /** Overloaded version of the above function provided for convenience that takes a qstring pointer */
197
 
    bool isValidVectorFileName (QString * theFileNameQString);
198
 
#ifdef HAVE_POSTGRESQL
199
 
    //! Add a databaselayer to the map
200
 
    void addDatabaseLayer();
201
 
#endif
202
 
 
203
 
    //! Exit Qgis
204
 
    void fileExit();
205
 
    
206
 
    //! add this file to the recently opened/saved projects list
207
 
    //  pass settings by reference since creating more than one
208
 
    //! instance simultaneously results in data loss.
209
 
    void saveRecentProjectPath(QString projectPath, QSettings & settings);
210
 
    //! Update file menu with the current list of recently accessed projects
211
 
    void updateRecentProjectPaths();
212
 
    //! Set map tool to Zoom out
213
 
    void zoomOut();
214
 
    //! Set map tool to Zoom in
215
 
    void zoomIn();
216
 
    //! Zoom to full extent
217
 
    void zoomFull();
218
 
    //! Zoom to the previous extent
219
 
    void zoomPrevious();
220
 
    //! Zoom to selected features
221
 
    void zoomToSelected();
222
 
    //! Set map tool to pan
223
 
    void pan();
224
 
    //! Identify feature(s) on the currently selected layer
225
 
    void identify();
226
 
    //! Measure distance
227
 
    void measure();
228
 
    //! show the attribute table for the currently selected layer
229
 
    void attributeTable();
230
 
    /**Deletes the selected attributes for the currently selected vector layer*/
231
 
    void deleteSelected();
232
 
    //! Read Well Known Binary stream from PostGIS
233
 
    //void readWKB(const char *, QStringList tables);
234
 
    //! Draw a point on the map canvas
235
 
    void drawPoint(double x, double y);
236
 
    //! draw layers
237
 
    void drawLayers();
238
 
    //! test function
239
 
    void testButton();
240
 
    //! About QGis
241
 
    void about();
242
 
    //! activates the capture point tool
243
 
    void capturePoint();
244
 
    //! activates the capture line tool
245
 
    void captureLine();
246
 
    //! activates the capture polygon tool
247
 
    void capturePolygon();
248
 
    //! activates the selection tool
249
 
    void select();
250
 
    //! check to see if file is dirty and if so, prompt the user th save it
251
 
    int saveDirty();
252
 
 
253
 
 
254
 
    
255
 
private slots:
256
 
 
257
 
    //! reimplements widget keyPress event so we can check if cancel was pressed
258
 
    void keyPressEvent ( QKeyEvent * e );
259
 
 
260
 
   /** for when a menu bar item is activated
261
 
       Used to dynamically update pop-up menu items
262
 
   */
263
 
    /* virtual */ void menubar_highlighted( int i );
264
 
 
265
 
 
266
 
    /** toggles whether the current selected layer is in overview or not */
267
 
    void inOverview(bool);
268
 
    //! Slot to show the map coordinate position of the mouse cursor
269
 
    void showMouseCoordinate(QgsPoint &);
270
 
    //copy the click coord to clipboard and let the user know its there
271
 
    void showCapturePointCoordinate(QgsPoint &);
272
 
    //! Slot to show current map scale;
273
 
    void showScale(QString theScale);
274
 
    //! Show layer properties for the selected layer
275
 
    void layerProperties(QListViewItem *);
276
 
    //! Show layer properties for selected layer (called by right-click menu)
277
 
    void layerProperties();
278
 
    //! Show the right-click menu for the legend
279
 
    void rightClickLegendMenu(QListViewItem *, const QPoint &, int);
280
 
    //! Disable/enable toolbar buttons as appropriate for selected layer
281
 
    void currentLayerChanged(QListViewItem *);
282
 
    //! Remove a layer from the map and legend
283
 
    void removeLayer();
284
 
    //! zoom to extent of layer
285
 
    void zoomToLayerExtent();
286
 
    //! load any plugins used in the last qgis session
287
 
    void restoreSessionPlugins(QString thePluginDirString);
288
 
    //! test plugin functionality
289
 
    void testPluginFunctions();
290
 
    //! test maplayer plugins
291
 
    void testMapLayerPlugins();
292
 
    //! plugin manager
293
 
    void actionPluginManager_activated();
294
 
    //! plugin loader
295
 
    void loadPlugin(QString name, QString description, QString mFullPath);
296
 
    //! Add a plugin menu to the main Plugins menu
297
 
    int addPluginMenu(QString menuText, QPopupMenu *menu);
298
 
 
299
 
    QPopupMenu* getPluginMenu(QString menuName);
300
 
 
301
 
    void removePluginMenuItem(QString name, int menuId);
302
 
 
303
 
    //! Add an icon to the plugin toolbar
304
 
    int addPluginToolBarIcon (QAction * qAction);
305
 
    //! Remove an icon from the plugin toolbar
306
 
    void removePluginToolBarIcon(QAction *qAction);
307
 
    //! Save window state
308
 
    void saveWindowState();
309
 
    //! Restore the window and toolbar state
310
 
    void restoreWindowState();
311
 
    //! Save project
312
 
    void fileSave();
313
 
    //! Save project as
314
 
    void fileSaveAs();
315
 
    //! Open the project file corresponding to the
316
 
    //! path at the given index in mRecentProjectPaths
317
 
    void openProject(int pathIndex);
318
 
    //! Save the map view as an image - user is prompted for image name using a dialog
319
 
    void saveMapAsImage();
320
 
    //! Open a project
321
 
    void fileOpen();
322
 
    //! Create a new project
323
 
    void fileNew();
324
 
    //! As above but allows forcing without prompt
325
 
    void fileNew(bool thePromptToSaveFlag);
326
 
    //! Create a new empty vector layer
327
 
    void newVectorLayer();
328
 
    //! Print the current map view frame
329
 
    void filePrint();
330
 
    //! Add all loaded layers into the overview - overides qgisappbase method
331
 
    void addAllToOverview();
332
 
    //! Remove all loaded layers from the overview - overides qgisappbase method
333
 
    void removeAllFromOverview();
334
 
    //reimplements method from base (gui) class
335
 
    void hideAllLayers();
336
 
    //reimplements method from base (gui) class
337
 
    void showAllLayers();
338
 
    //! Export current view as a mapserver map file
339
 
    void exportMapServer();
340
 
    //! Return pointer to the active layer
341
 
    QgsMapLayer *activeLayer();
342
 
    //! Return data source of the active layer
343
 
    QString activeLayerSource();
344
 
    //! Open the help contents in a browser
345
 
    void helpContents();
346
 
    //! Open the QGIS homepage in users browser
347
 
    void helpQgisHomePage();
348
 
    //! Open the QGIS Sourceforge page in users browser
349
 
    void helpQgisSourceForge();
350
 
    //! Open a url in the users configured browser
351
 
    void openURL(QString url, bool useQgisDocDirectory=true);
352
 
    //! Check qgis version against the qgis version server
353
 
    void checkQgisVersion();
354
 
    //!Invoke the custom projection dialog
355
 
    void actionCustomProjection_activated(); 
356
 
    //! options dialog slot
357
 
    void options();
358
 
    //! Whats-this help slot
359
 
    void whatsThis();
360
 
    //! Get the Menu map (key is name, value is menu id)
361
 
    std::map<QString, int> menuMapByName();
362
 
    //! Get the Menu map (key is menu id, value is name)
363
 
    std::map<int, QString> menuMapById();
364
 
    //! Populate the menu maps
365
 
    void populateMenuMaps();
366
 
    void socketConnected();
367
 
    void socketConnectionClosed();
368
 
    void socketReadyRead();
369
 
    void socketError(int e);
370
 
    //! Set project properties, including map untis
371
 
    void projectProperties();
372
 
    //! Open project properties dialog and show the projections tab
373
 
    void projectPropertiesProjections();
374
 
    /*  void urlData(); */
375
 
    /** Used to (re)set the zordering of the overview map*/
376
 
    void setOverviewZOrder(QgsLegend * );
377
 
    //! Kills the splash screen
378
 
    void killSplashScreen();
379
 
    //! Show the spatial bookmarks dialog
380
 
    void actionShowBookmarks_activated();
381
 
    //! Create a new spatial bookmark
382
 
    void actionNewBookmark_activated();
383
 
 
384
 
public slots:
385
 
    void showProgress(int theProgress, int theTotalSteps);
386
 
    void showExtents(QgsRect theExtents);
387
 
    void showStatusMessage(QString theMessage);
388
 
    void setLayerOverviewStatus(QString theLayerId, bool theVisibilityFlag);
389
 
    void drawExtentRectangle(QPainter *);
390
 
    void updateMouseCoordinatePrecision();
391
 
    void projectionsEnabled(bool theFlag);
392
 
//    void debugHook();
393
 
    void stopZoom();
394
 
 
395
 
signals:
396
 
    /** emitted when a key is pressed and we want non widget sublasses to be able
397
 
        to pick up on this (e.g. maplayer) */
398
 
    void keyPressed (QKeyEvent *e);
399
 
 
400
 
    /** emitted when a project file is successfully read
401
 
 
402
 
      @note
403
 
 
404
 
      This is useful for plug-ins that store properties with project files.  A
405
 
      plug-in can connect to this signal.  When it is emitted, the plug-in
406
 
      knows to then check the project properties for any relevant state.
407
 
 
408
 
    */
409
 
    void projectRead();
410
 
 
411
 
    /** emitted when starting an entirely new project
412
 
 
413
 
      @note
414
 
 
415
 
       This is similar to projectRead(); plug-ins might want to be notified
416
 
       that they're in a new project.  Yes, projectRead() could have been
417
 
       overloaded to be used in the case of new projects instead.  However,
418
 
       it's probably more semantically correct to have an entirely separate
419
 
       signal for when this happens.
420
 
 
421
 
    */
422
 
    void newProject();
423
 
 
424
 
    /** emitted when a new bookmark is added 
425
 
     */
426
 
    void bookmarkAdded();
427
 
private:
428
 
 
429
 
    /// QgisApp aren't copyable
430
 
    QgisApp( QgisApp const & );
431
 
 
432
 
    /// QgisApp aren't copyable
433
 
    QgisApp & operator=( QgisApp const & );
434
 
    
435
 
    //! A central registry that keeps track of all loaded layers.
436
 
    // prefer QgsMapLayerRegistry::instance() to emphasize Singleton
437
 
    ///QgsMapLayerRegistry * mMapLayerRegistry;
438
 
    //! Widget that will live on the statusbar to display scale
439
 
    QLabel * mScaleLabel;
440
 
    //! Widget that will live in the statusbar to display coords
441
 
    QLabel * mCoordsLabel;
442
 
    //! Widget that will live in the statusbar to show progress of operations
443
 
    QProgressBar * mProgressBar;
444
 
    //! Widget used to suppress rendering
445
 
    QCheckBox * mRenderSuppresionCBox;
446
 
    //! Widget in status bar used to show status of on the fly projection
447
 
    QToolButton * mOnTheFlyProjectionStatusButton;
448
 
    //! Popup menu
449
 
    QPopupMenu * mPopupMenu;
450
 
    //! Top level plugin menu
451
 
    QPopupMenu *mPluginMenu;
452
 
    //! Popup menu for the map overview tools
453
 
    QPopupMenu *toolPopupOverviews;
454
 
    //! Popup menu for the display tools
455
 
    QPopupMenu *toolPopupDisplay;
456
 
    //! Popup menu for the capture tools
457
 
    QPopupMenu *toolPopupCapture;
458
 
    //! Legend list view control
459
 
    //doesnt see to be used...(TS)
460
 
    //QgsLegendView *mLegendView;
461
 
    //! Map canvas
462
 
    QgsMapCanvas *mMapCanvas;
463
 
    //! Map layer registry
464
 
    // use instance() now QgsMapLayerRegistry *mLayerRegistry;
465
 
    //! Overview canvas where the map overview is shown
466
 
    QgsMapCanvas * mOverviewCanvas;
467
 
    //! Table of contents (legend) for the map
468
 
    QgsLegend *mMapLegend;
469
 
    QCursor *mMapCursor;
470
 
    //! scale factor
471
 
    double mScaleFactor;
472
 
    //! Current map window extent in real-world coordinates
473
 
    QRect *mMapWindow;
474
 
    //! Current map tool
475
 
    int mMapTool;
476
 
    //! The previously selected non zoom map tool.
477
 
    int mPreviousNonZoomMapTool;
478
 
    //QCursor *mCursorZoomIn; //doesnt seem to be used anymore (TS)
479
 
    QString mStartupPath;
480
 
    //! full path name of the current map file (if it has been saved or loaded)
481
 
    QString mFullPathName;
482
 
    QgisIface *mQgisInterface;
483
 
    QSocket *mSocket;
484
 
    QString mVersionMessage;
485
 
    friend class QgisIface;
486
 
    QgsProviderRegistry *mProviderRegistry;
487
 
    //! application directory
488
 
    QString mAppDir;
489
 
    //! help viewer
490
 
    QgsHelpViewer *mHelpViewer;
491
 
 
492
 
    //! Flag to indicate if the splash screen is shown on startup
493
 
    bool myHideSplashFlag;
494
 
    //! Flag to indicate that newly added layers are not shown on
495
 
    //  the map
496
 
    bool mAddedLayersHidden;
497
 
    //! menu map (key is name, value is menu id)
498
 
    std::map<QString, int>mMenuMapByName;
499
 
    //! menu map (key is menu id, value is name)
500
 
    std::map<int, QString>mMenuMapById;
501
 
    //! list of recently opened/saved project files
502
 
    QStringList mRecentProjectPaths;
503
 
 
504
 
    //! Map composer
505
 
    QgsComposer *mComposer;
506
 
 
507
 
    //! How to determine the number of decimal places used to
508
 
    //! display the mouse position
509
 
    bool mMousePrecisionAutomatic;
510
 
    //! The number of decimal places to use if not automatic
511
 
    unsigned int mMousePrecisionDecimalPlaces;
512
 
    //! Flag to indicate how the project properties dialog was summoned
513
 
    bool mShowProjectionTab;
514
 
 
515
 
    /** String containing supporting vector file formats 
516
 
 
517
 
       Suitable for a QFileDialog file filter.  Build in ctor.
518
 
    */
519
 
    QString mVectorFileFilter;
520
 
 
521
 
    /** String containing supporting raster file formats 
522
 
 
523
 
       Suitable for a QFileDialog file filter.  Build in ctor.
524
 
    */
525
 
    QString mRasterFileFilter;
526
 
};
527
 
 
528
 
#endif