1
/***************************************************************************
2
qgisapp.h - description
4
begin : Sat Jun 22 2002
5
copyright : (C) 2002 by Gary E.Sherman
6
email : sherman at mrcc.com
7
***************************************************************************/
9
/***************************************************************************
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. *
16
***************************************************************************/
17
/* $Id: qgisapp.h,v 1.136.2.3 2005/09/09 22:08:07 mcoletti Exp $ */
40
class QgsProviderRegistry;
43
class QgsMapLayerRegistry;
50
#include "qgisappbase.h"
52
#include "qgisappbase.uic.h"
54
#include "qgisiface.h"
55
#include "splashscreen.h"
56
#include "qgsconfig.h"
57
#include "qgsvectordataprovider.h"
61
static SplashScreen * gSplashScreen ;
65
* \brief Main window for the Qgis application
67
class QgisApp : public QgisAppBase
74
QgisApp(QWidget * parent = 0, const char *name = 0, WFlags fl = WType_TopLevel);
78
QgisIface *getInterface();
80
/** \brief Set the Z order of both mapcanvas and overview
81
* canvas. Typically this will be called by projectio when loading a
84
void setZOrder (std::list<QString>);
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
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.
99
bool addLayer(QStringList const & theLayerQStringList, const QString& enc);
101
/** open a vector layer for the given file
104
@returns false if unable to open a raster layer for rasterFile
108
This is essentially a simplified version of the above
110
bool addLayer(QFileInfo const & vectorFile);
113
/** overloaded vesion of the private addRasterLayer()
115
Method that takes a list of filenames instead of prompting
118
@returns true if successfully added layer(s)
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.
127
bool addRasterLayer(QStringList const & theLayerQStringList, bool guiWarning=true);
130
/** open a raster layer for the given file
132
@returns false if unable to open a raster layer for rasterFile
136
This is essentially a simplified version of the above
138
bool addRasterLayer(QFileInfo const & rasterFile, bool guiWarning=true);
140
/** Add a 'pre-made' map layer to the project */
141
void addMapLayer(QgsMapLayer *theMapLayer);
143
/** Set the extents of the map canvas */
144
void setExtent(QgsRect theRect);
146
//! Remove all layers from the map and legend - reimplements same method from qgisappbase
147
void removeAllLayers();
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
153
bool openLayer(const QString & fileName);
155
/** Open the specified project file; prompt to save previous project if necessary.
156
Used to process a commandline argument or OpenDocument AppleEvent.
158
void openProject(const QString & fileName);
160
/** opens a qgis project file
161
@returns false if unable to open the project
164
bool addProject(QString projectFile);
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; };
170
/** return the layer registry
174
Returns QgsMapLayerRegistry::instance(); i.e., it's a Singleton
176
QgsMapLayerRegistry * getLayerRegistry();
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);
185
//! Add a vector layer to the map
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.
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();
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
214
//! Set map tool to Zoom in
216
//! Zoom to full extent
218
//! Zoom to the previous extent
220
//! Zoom to selected features
221
void zoomToSelected();
222
//! Set map tool to pan
224
//! Identify feature(s) on the currently selected layer
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);
242
//! activates the capture point tool
244
//! activates the capture line tool
246
//! activates the capture polygon tool
247
void capturePolygon();
248
//! activates the selection tool
250
//! check to see if file is dirty and if so, prompt the user th save it
257
//! reimplements widget keyPress event so we can check if cancel was pressed
258
void keyPressEvent ( QKeyEvent * e );
260
/** for when a menu bar item is activated
261
Used to dynamically update pop-up menu items
263
/* virtual */ void menubar_highlighted( int i );
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
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();
293
void actionPluginManager_activated();
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);
299
QPopupMenu* getPluginMenu(QString menuName);
301
void removePluginMenuItem(QString name, int menuId);
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();
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();
322
//! Create a new project
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
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
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
358
//! Whats-this help slot
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();
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);
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);
400
/** emitted when a project file is successfully read
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.
411
/** emitted when starting an entirely new project
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.
424
/** emitted when a new bookmark is added
426
void bookmarkAdded();
429
/// QgisApp aren't copyable
430
QgisApp( QgisApp const & );
432
/// QgisApp aren't copyable
433
QgisApp & operator=( QgisApp const & );
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;
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;
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;
472
//! Current map window extent in real-world coordinates
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;
484
QString mVersionMessage;
485
friend class QgisIface;
486
QgsProviderRegistry *mProviderRegistry;
487
//! application directory
490
QgsHelpViewer *mHelpViewer;
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
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;
505
QgsComposer *mComposer;
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;
515
/** String containing supporting vector file formats
517
Suitable for a QFileDialog file filter. Build in ctor.
519
QString mVectorFileFilter;
521
/** String containing supporting raster file formats
523
Suitable for a QFileDialog file filter. Build in ctor.
525
QString mRasterFileFilter;