~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/gui/qgisapp.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
  qgisapp.cpp  -  description
3
 
  -------------------
4
 
 
5
 
           begin                : Sat Jun 22 2002
6
 
           copyright            : (C) 2002 by Gary E.Sherman
7
 
           email                : sherman at mrcc.com
8
 
           Romans 3:23=>Romans 6:23=>Romans 10:9,10=>Romans 12
9
 
 ***************************************************************************/
10
 
 
11
 
/***************************************************************************
12
 
 *                                                                         *
13
 
 *   This program is free software; you can redistribute it and/or modify  *
14
 
 *   it under the terms of the GNU General Public License as published by  *
15
 
 *   the Free Software Foundation; either version 2 of the License, or     *
16
 
 *   (at your option) any later version.                                   *
17
 
 *                                                                         *
18
 
 ***************************************************************************/
19
 
/* $Id: qgisapp.cpp 7019 2007-06-11 03:55:32Z timlinux $ */
20
 
 
21
 
//
22
 
// QT4 includes make sure to use the new <CamelCase> style!
23
 
//
24
 
#include <Q3ListViewItem>
25
 
#include <QAction>
26
 
#include <QApplication>
27
 
#include <QBitmap>
28
 
#include <QCheckBox>
29
 
#include <QClipboard>
30
 
#include <QColor>
31
 
#include <QCursor>
32
 
#include <QDesktopWidget>
33
 
#include <QDialog>
34
 
#include <QDir>
35
 
#include <QEvent>
36
 
#include <QFile>
37
 
#include <QFileInfo>
38
 
#include <QInputDialog>
39
 
#include <QKeyEvent>
40
 
#include <QLabel>
41
 
#include <QLibrary>
42
 
#include <QMenu>
43
 
#include <QMenuBar>
44
 
#include <QMenuItem>
45
 
#include <QMessageBox>
46
 
#include <QPainter>
47
 
#include <QPictureIO>
48
 
#include <QPixmap>
49
 
#include <QPoint>
50
 
#include <QPrinter>
51
 
#include <QProcess>
52
 
#include <QProgressBar>
53
 
#include <QSettings>
54
 
#include <QSplashScreen>
55
 
#include <QStatusBar>
56
 
#include <QStringList>
57
 
#include <QTcpSocket>
58
 
#include <QTextStream>
59
 
#include <QToolButton>
60
 
#include <QToolTip>
61
 
#include <QVBoxLayout>
62
 
#include <QWhatsThis>
63
 
#include <QtGlobal>
64
 
 
65
 
//
66
 
// Mac OS X Includes
67
 
// Must include before GEOS 3 due to unqualified use of 'Point'
68
 
//
69
 
#ifdef Q_OS_MACX
70
 
#include <ApplicationServices/ApplicationServices.h>
71
 
#endif
72
 
 
73
 
//
74
 
// QGIS Specific Includes
75
 
//
76
 
#include "../../images/themes/default/qgis.xpm"
77
 
#include "qgisapp.h"
78
 
#include "qgis.h"
79
 
#include "qgisplugin.h"
80
 
#include "qgsabout.h"
81
 
#include "qgsapplication.h"
82
 
#include "qgsbookmarkitem.h"
83
 
#include "qgsbookmarks.h"
84
 
#include "qgscomposer.h"
85
 
#include <qgscursors.h>
86
 
#include "qgscustomprojectiondialog.h"
87
 
#include "qgsencodingfiledialog.h"
88
 
#include "qgsgeomtypedialog.h"
89
 
#include "qgshelpviewer.h"
90
 
#include "qgslegend.h"
91
 
#include "qgslegendlayerfile.h"
92
 
#include "qgslegendlayer.h"
93
 
#include "qgslogger.h"
94
 
#include "qgsmapcanvas.h"
95
 
#include "qgsmaplayer.h"
96
 
#include "qgsmaplayerinterface.h"
97
 
#include "qgsmaplayerregistry.h"
98
 
#include "qgsmapoverviewcanvas.h"
99
 
#include "qgsmaprender.h"
100
 
#include "qgsmessageviewer.h"
101
 
#include "qgsoptions.h"
102
 
#include "qgspastetransformations.h"
103
 
#include "qgspluginitem.h"
104
 
#include "qgspluginmanager.h"
105
 
#include "qgspluginregistry.h"
106
 
#include "qgsproject.h"
107
 
#include "qgsprojectproperties.h"
108
 
#include "qgsproviderregistry.h"
109
 
#include "qgsrasterlayer.h"
110
 
#include "qgsrasterlayerproperties.h"
111
 
#include "qgsrect.h"
112
 
#include "qgsserversourceselect.h"
113
 
#include "qgssinglesymbolrenderer.h"
114
 
#include "qgsvectordataprovider.h"
115
 
#include "qgsvectorfilewriter.h"
116
 
#include "qgsvectorlayer.h"
117
 
 
118
 
//
119
 
// Gdal/Ogr includes
120
 
//
121
 
#include <ogrsf_frmts.h>
122
 
 
123
 
//
124
 
// Other includes
125
 
//
126
 
#include <algorithm>
127
 
#include <cmath>
128
 
#include <functional>
129
 
#include <iomanip>
130
 
#include <iostream>
131
 
#include <list>
132
 
#include <memory>
133
 
#include <vector>
134
 
 
135
 
//
136
 
// Map tools
137
 
//
138
 
#include "qgsmaptoolcapture.h"
139
 
#include "qgsmaptoolidentify.h"
140
 
#include "qgsmaptoolpan.h"
141
 
#include "qgsmaptoolselect.h"
142
 
#include "qgsmaptoolvertexedit.h"
143
 
#include "qgsmaptoolzoom.h"
144
 
#include "qgsmeasure.h"
145
 
 
146
 
//
147
 
// Conditional Includes
148
 
//
149
 
#ifdef HAVE_POSTGRESQL
150
 
#include "qgsdbsourceselect.h"
151
 
#endif
152
 
 
153
 
#ifndef WIN32
154
 
#include <dlfcn.h>
155
 
#endif
156
 
 
157
 
using namespace std;
158
 
class QTreeWidgetItem;
159
 
 
160
 
/* typedefs for plugins */
161
 
typedef QgsMapLayerInterface *create_it();
162
 
typedef QgisPlugin *create_ui(QgisApp * qgis, QgisIface * qI);
163
 
typedef QString name_t();
164
 
typedef QString description_t();
165
 
typedef int type_t();
166
 
 
167
 
// IDs for locating particular menu items
168
 
const int BEFORE_RECENT_PATHS = 123;
169
 
const int AFTER_RECENT_PATHS = 321;
170
 
 
171
 
 
172
 
/// build the vector file filter string for a QFileDialog
173
 
/*
174
 
   called in ctor for initializing mVectorFileFilter
175
 
   */
176
 
static void buildSupportedVectorFileFilter_(QString & fileFilters);
177
 
 
178
 
 
179
 
/** set the application title bar text
180
 
 
181
 
  If the current project title is null
182
 
  if the project file is null then
183
 
  set title text to just application name and version
184
 
  else
185
 
  set set title text to the the project file name
186
 
  else
187
 
  set the title text to project title
188
 
  */
189
 
static void setTitleBarText_( QWidget & qgisApp )
190
 
{
191
 
  QString caption = QgisApp::tr("Quantum GIS - ");
192
 
  caption += QString("%1 ('%2') ").arg(QGis::qgisVersion).arg(QGis::qgisReleaseName) + " ";
193
 
 
194
 
  if ( QgsProject::instance()->title().isEmpty() )
195
 
  {
196
 
    if ( QgsProject::instance()->filename().isEmpty() )
197
 
    {
198
 
      // no project title nor file name, so just leave caption with
199
 
      // application name and version
200
 
    }
201
 
    else
202
 
    {
203
 
      QFileInfo projectFileInfo( QgsProject::instance()->filename() );
204
 
      caption += projectFileInfo.baseName();
205
 
    }
206
 
  }
207
 
  else
208
 
  {
209
 
    caption += QgsProject::instance()->title();
210
 
  }
211
 
 
212
 
  qgisApp.setCaption( caption );
213
 
} // setTitleBarText_( QWidget * qgisApp )
214
 
 
215
 
 
216
 
 
217
 
 
218
 
// constructor starts here
219
 
  QgisApp::QgisApp(QSplashScreen *splash, QWidget * parent, Qt::WFlags fl)
220
 
: QMainWindow(parent,fl),
221
 
  mSplash(splash)
222
 
{
223
 
  setupUi(this);
224
 
 
225
 
  mSplash->showMessage(tr("Checking database"), Qt::AlignHCenter | Qt::AlignBottom);
226
 
  qApp->processEvents();
227
 
  // Do this early on before anyone else opens it and prevents us copying it
228
 
  createDB();    
229
 
 
230
 
  mSplash->showMessage(tr("Reading settings"), Qt::AlignHCenter | Qt::AlignBottom);
231
 
  qApp->processEvents();
232
 
  readSettings();
233
 
  mSplash->showMessage(tr("Setting up the GUI"), Qt::AlignHCenter | Qt::AlignBottom);
234
 
  qApp->processEvents();
235
 
  createActions();
236
 
  createActionGroups();
237
 
  createMenus();
238
 
  createToolBars();
239
 
  createStatusBar();
240
 
  setTheme(mThemeName);
241
 
  updateRecentProjectPaths();
242
 
  createCanvas();
243
 
  createOverview();
244
 
  createLegend();
245
 
 
246
 
  fileNew(); // prepare empty project
247
 
  qApp->processEvents();
248
 
 
249
 
  // register all GDAL and OGR plug-ins
250
 
  // Should this be here? isnt it the job of the provider? Tim
251
 
  OGRRegisterAll();
252
 
 
253
 
  QPixmap icon;
254
 
  icon = QPixmap(qgis_xpm);
255
 
  setIcon(icon);
256
 
  // store startup location
257
 
  QDir *d = new QDir();
258
 
  mStartupPath = d->absPath();
259
 
  delete d;
260
 
  QBitmap zoomincur;
261
 
  //  zoomincur = QBitmap(cursorzoomin);
262
 
  QBitmap zoomincurmask;
263
 
  //  zoomincurmask = QBitmap(cursorzoomin_mask);
264
 
  QString caption = tr("Quantum GIS - ");
265
 
  caption += QString("%1 ('%2')").arg(QGis::qgisVersion).arg(QGis::qgisReleaseName);
266
 
  setCaption(caption);
267
 
  // create the interfce
268
 
  mQgisInterface = new QgisIface(this);
269
 
 
270
 
 
271
 
  //
272
 
  // Create the plugin registry and load plugins
273
 
  //
274
 
  // Get pointer to the provider registry singleton
275
 
  QString plib = QgsApplication::pluginPath();
276
 
  // set the provider plugin path
277
 
  mProviderRegistry = QgsProviderRegistry::instance(plib);
278
 
#ifdef QGISDEBUG
279
 
  std::cout << "Plugins and providers are installed in " << plib.toLocal8Bit().data() << std::endl;
280
 
#endif
281
 
  // load any plugins that were running in the last session
282
 
  mSplash->showMessage(tr("Restoring loaded plugins"), Qt::AlignHCenter | Qt::AlignBottom);
283
 
  qApp->processEvents();
284
 
  restoreSessionPlugins(plib);
285
 
 
286
 
  /* Delete this I think - Tim - FIXME 
287
 
  //
288
 
  // Create the map layer registry. Any layers loaded will
289
 
  // register themselves here. Deleting layers shouls ONLY
290
 
  // be done by means of a removeMapLayer call to the regsitry.
291
 
  // This allows a single layer instance to be shared
292
 
  // between more than one canvas. The registry is a singleton
293
 
  // and is constructed using the static instance call.
294
 
 
295
 
  // syntactic sugar shortcut for instance handle
296
 
  //QgsMapLayerRegistry * mapLayerRegistry = QgsMapLayerRegistry::instance();
297
 
  */
298
 
 
299
 
  // Map composer
300
 
  mComposer = new QgsComposer(this);
301
 
 
302
 
  mSplash->showMessage(tr("Initializing file filters"), Qt::AlignHCenter | Qt::AlignBottom);
303
 
  qApp->processEvents();
304
 
  // now build vector file filter
305
 
  buildSupportedVectorFileFilter_( mVectorFileFilter );
306
 
 
307
 
  // now build raster file filter
308
 
  QgsRasterLayer::buildSupportedRasterFileFilter( mRasterFileFilter );
309
 
  
310
 
  // Set the background colour for toolbox and overview as they default to 
311
 
  // white instead of the window color
312
 
  QPalette myPalette = toolBox->palette();
313
 
  myPalette.setColor(QPalette::Button, myPalette.window().color());
314
 
  toolBox->setPalette(myPalette);
315
 
  //do the same for legend control
316
 
  myPalette = toolBox->palette();
317
 
  myPalette.setColor(QPalette::Button, myPalette.window().color());
318
 
  mMapLegend->setPalette(myPalette);
319
 
  //and for overview control this is done in createOverView method
320
 
  
321
 
  // Do this last in the ctor to ensure that all members are instantiated properly
322
 
  setupConnections();
323
 
  //
324
 
  // Please make sure this is the last thing the ctor does so that we can ensure teh 
325
 
  // widgets are all initialised before trying to restore their state.
326
 
  //
327
 
  mSplash->showMessage(tr("Restoring window state"), Qt::AlignHCenter | Qt::AlignBottom);
328
 
  qApp->processEvents();
329
 
  restoreWindowState();
330
 
 
331
 
  mSplash->showMessage(tr("QGIS Ready!"), Qt::AlignHCenter | Qt::AlignBottom);
332
 
  qApp->processEvents();
333
 
} // QgisApp ctor
334
 
 
335
 
 
336
 
 
337
 
QgisApp::~QgisApp()
338
 
{
339
 
  delete mMapTools.mZoomIn;
340
 
  delete mMapTools.mZoomOut;
341
 
  delete mMapTools.mPan;
342
 
  delete mMapTools.mIdentify;
343
 
  delete mMapTools.mMeasureDist;
344
 
  delete mMapTools.mMeasureArea;
345
 
  delete mMapTools.mCapturePoint;
346
 
  delete mMapTools.mCaptureLine;
347
 
  delete mMapTools.mCapturePolygon;
348
 
  delete mMapTools.mSelect;
349
 
  delete mMapTools.mVertexAdd;
350
 
  delete mMapTools.mVertexMove;
351
 
  delete mMapTools.mVertexDelete;
352
 
}
353
 
 
354
 
// restore any application settings stored in QSettings
355
 
void QgisApp::readSettings()
356
 
{
357
 
  // get the application dir
358
 
  mAppDir = QgsApplication::prefixPath();
359
 
 
360
 
  QSettings settings;
361
 
  // get the users theme preference from the settings
362
 
  mThemeName = settings.readEntry("/Themes","default");
363
 
 
364
 
 
365
 
  // Set the initial visibility flag for layers
366
 
  // This user option allows the user to turn off inital drawing of
367
 
  // layers when they are added to the map. This is useful when adding
368
 
  // many layers and the user wants to adjusty symbology, etc prior to
369
 
  // actually viewing the layer.
370
 
  mAddedLayersVisible = settings.readBoolEntry("/qgis/new_layers_visible", 1);
371
 
 
372
 
  // Add the recently accessed project file paths to the File menu
373
 
  mRecentProjectPaths = settings.readListEntry("/UI/recentProjectsList");
374
 
 
375
 
  // Set the behaviour when the map splitters are resized
376
 
  bool splitterRedraw = settings.value("/qgis/splitterRedraw", true).toBool();
377
 
  canvasLegendSplit->setOpaqueResize(splitterRedraw);
378
 
  legendOverviewSplit->setOpaqueResize(splitterRedraw);
379
 
}
380
 
 
381
 
 
382
 
//////////////////////////////////////////////////////////////////////
383
 
//            Set Up the gui toolbars, menus, statusbar etc 
384
 
//////////////////////////////////////////////////////////////////////            
385
 
 
386
 
void QgisApp::createActions()
387
 
{
388
 
  QString myIconPath = QgsApplication::themePath();
389
 
  //
390
 
  // File Menu Related Items
391
 
  //
392
 
  mActionFileNew= new QAction(QIcon(myIconPath+"/mActionFileNew.png"), tr("&New Project"), this);
393
 
  mActionFileNew->setShortcut(tr("Ctrl+N","New Project"));
394
 
  mActionFileNew->setStatusTip(tr("New Project"));
395
 
  connect(mActionFileNew, SIGNAL(triggered()), this, SLOT(fileNew()));
396
 
  //
397
 
  mActionFileOpen= new QAction(QIcon(myIconPath+"/mActionFileOpen.png"), tr("&Open Project..."), this);
398
 
  mActionFileOpen->setShortcut(tr("Ctrl+O","Open a Project"));
399
 
  mActionFileOpen->setStatusTip(tr("Open a Project"));
400
 
  connect(mActionFileOpen, SIGNAL(triggered()), this, SLOT(fileOpen()));
401
 
  //
402
 
  mActionFileSave= new QAction(QIcon(myIconPath+"/mActionFileSave.png"), tr("&Save Project"), this);
403
 
  mActionFileSave->setShortcut(tr("Ctrl+S","Save Project"));
404
 
  mActionFileSave->setStatusTip(tr("Save Project"));
405
 
  connect(mActionFileSave, SIGNAL(triggered()), this, SLOT(fileSave()));
406
 
  //
407
 
  mActionFileSaveAs= new QAction(QIcon(myIconPath+"/mActionFileSaveAs.png"), tr("Save Project &As..."), this);
408
 
  mActionFileSaveAs->setShortcut(tr("Ctrl+A","Save Project under a new name"));
409
 
  mActionFileSaveAs->setStatusTip(tr("Save Project under a new name"));
410
 
  connect(mActionFileSaveAs, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
411
 
  //
412
 
  mActionFilePrint= new QAction(QIcon(myIconPath+"/mActionFilePrint.png"), tr("&Print..."), this);
413
 
  mActionFilePrint->setShortcut(tr("Ctrl+P","Print"));
414
 
  mActionFilePrint->setStatusTip(tr("Print"));
415
 
  connect(mActionFilePrint, SIGNAL(triggered()), this, SLOT(filePrint()));
416
 
  //
417
 
  mActionSaveMapAsImage= new QAction(QIcon(myIconPath+"/mActionSaveMapAsImage.png"), tr("Save as Image..."), this);
418
 
  mActionSaveMapAsImage->setShortcut(tr("Ctrl+I","Save map as image"));
419
 
  mActionSaveMapAsImage->setStatusTip(tr("Save map as image"));
420
 
  connect(mActionSaveMapAsImage, SIGNAL(triggered()), this, SLOT(saveMapAsImage()));
421
 
  //
422
 
  mActionExportMapServer= new QAction(QIcon(myIconPath+"/mActionExportMapServer.png"), tr("Export to MapServer Map..."), this);
423
 
  mActionExportMapServer->setShortcut(tr("M","Export as MapServer .map file"));
424
 
  mActionExportMapServer->setStatusTip(tr("Export as MapServer .map file"));
425
 
  connect(mActionExportMapServer, SIGNAL(triggered()), this, SLOT(exportMapServer()));
426
 
  //
427
 
  mActionFileExit= new QAction(QIcon(myIconPath+"/mActionFileExit.png"), tr("Exit"), this);
428
 
  mActionFileExit->setShortcut(tr("Ctrl+Q","Exit QGIS"));
429
 
  mActionFileExit->setStatusTip(tr("Exit QGIS"));
430
 
  connect(mActionFileExit, SIGNAL(triggered()), this, SLOT(fileExit()));
431
 
  //
432
 
  // Layer Menu Related Items
433
 
  //
434
 
  mActionAddNonDbLayer= new QAction(QIcon(myIconPath+"/mActionAddNonDbLayer.png"), tr("Add a Vector Layer..."), this);
435
 
  mActionAddNonDbLayer->setShortcut(tr("V","Add a Vector Layer"));
436
 
  mActionAddNonDbLayer->setStatusTip(tr("Add a Vector Layer"));
437
 
  connect(mActionAddNonDbLayer, SIGNAL(triggered()), this, SLOT(addLayer()));
438
 
  //
439
 
  mActionAddRasterLayer= new QAction(QIcon(myIconPath+"/mActionAddRasterLayer.png"), tr("Add a Raster Layer..."), this);
440
 
  mActionAddRasterLayer->setShortcut(tr("R","Add a Raster Layer"));
441
 
  mActionAddRasterLayer->setStatusTip(tr("Add a Raster Layer"));
442
 
  connect(mActionAddRasterLayer, SIGNAL(triggered()), this, SLOT(addRasterLayer()));
443
 
  //
444
 
  mActionAddLayer= new QAction(QIcon(myIconPath+"/mActionAddLayer.png"), tr("Add a PostGIS Layer..."), this);
445
 
  mActionAddLayer->setShortcut(tr("D","Add a PostGIS Layer"));
446
 
  mActionAddLayer->setStatusTip(tr("Add a PostGIS Layer"));
447
 
//#ifdef HAVE_POSTGRESQL
448
 
//  std::cout << "HAVE_POSTGRESQL is defined" << std::endl; 
449
 
//  assert(0);
450
 
//#else
451
 
//  std::cout << "HAVE_POSTGRESQL not defined" << std::endl; 
452
 
//  assert(0);
453
 
//#endif
454
 
  connect(mActionAddLayer, SIGNAL(triggered()), this, SLOT(addDatabaseLayer()));
455
 
  //
456
 
  mActionNewVectorLayer= new QAction(QIcon(myIconPath+"/mActionNewVectorLayer.png"), tr("New Vector Layer..."), this);
457
 
  mActionNewVectorLayer->setShortcut(tr("N","Create a New Vector Layer"));
458
 
  mActionNewVectorLayer->setStatusTip(tr("Create a New Vector Layer"));
459
 
  connect(mActionNewVectorLayer, SIGNAL(triggered()), this, SLOT(newVectorLayer()));
460
 
  //
461
 
  mActionRemoveLayer= new QAction(QIcon(myIconPath+"/mActionRemoveLayer.png"), tr("Remove Layer"), this);
462
 
  mActionRemoveLayer->setShortcut(tr("Ctrl+D","Remove a Layer"));
463
 
  mActionRemoveLayer->setStatusTip(tr("Remove a Layer"));
464
 
  connect(mActionRemoveLayer, SIGNAL(triggered()), this, SLOT(removeLayer()));
465
 
  //
466
 
  mActionAddAllToOverview= new QAction(QIcon(myIconPath+"/mActionAddAllToOverview.png"), tr("Add All To Overview"), this);
467
 
  mActionAddAllToOverview->setShortcut(tr("+","Show all layers in the overview map"));
468
 
  mActionAddAllToOverview->setStatusTip(tr("Show all layers in the overview map"));
469
 
  connect(mActionAddAllToOverview, SIGNAL(triggered()), this, SLOT(addAllToOverview()));
470
 
  //
471
 
  mActionRemoveAllFromOverview= new QAction(QIcon(myIconPath+"/mActionRemoveAllFromOverview.png"), tr("Remove All From Overview"), this);
472
 
  mActionRemoveAllFromOverview->setShortcut(tr("-","Remove all layers from overview map"));
473
 
  mActionRemoveAllFromOverview->setStatusTip(tr("Remove all layers from overview map"));
474
 
  connect(mActionRemoveAllFromOverview, SIGNAL(triggered()), this, SLOT(removeAllFromOverview()));
475
 
  //
476
 
  mActionShowAllLayers= new QAction(QIcon(myIconPath+"/mActionShowAllLayers.png"), tr("Show All Layers"), this);
477
 
  mActionShowAllLayers->setShortcut(tr("S","Show all layers"));
478
 
  mActionShowAllLayers->setStatusTip(tr("Show all layers"));
479
 
  connect(mActionShowAllLayers, SIGNAL(triggered()), this, SLOT(showAllLayers()));
480
 
  //
481
 
  mActionHideAllLayers= new QAction(QIcon(myIconPath+"/mActionHideAllLayers.png"), tr("Hide All Layers"), this);
482
 
  mActionHideAllLayers->setShortcut(tr("H","Hide all layers"));
483
 
  mActionHideAllLayers->setStatusTip(tr("Hide all layers"));
484
 
  connect(mActionHideAllLayers, SIGNAL(triggered()), this, SLOT(hideAllLayers()));
485
 
  //
486
 
  // Settings Menu Related Items
487
 
  //
488
 
  mActionProjectProperties= new QAction(QIcon(myIconPath+"/mActionProjectProperties.png"), tr("Project Properties..."), this);
489
 
  mActionProjectProperties->setShortcut(tr("P","Set project properties"));
490
 
  mActionProjectProperties->setStatusTip(tr("Set project properties"));
491
 
  connect(mActionProjectProperties, SIGNAL(triggered()), this, SLOT(projectProperties()));
492
 
  //
493
 
  mActionOptions= new QAction(QIcon(myIconPath+"/mActionOptions.png"), tr("Options..."), this);
494
 
  // mActionOptions->setShortcut(tr("Alt+O","Change various QGIS options"));
495
 
  mActionOptions->setStatusTip(tr("Change various QGIS options"));
496
 
  connect(mActionOptions, SIGNAL(triggered()), this, SLOT(options()));
497
 
  //
498
 
  mActionCustomProjection= new QAction(QIcon(myIconPath+"/mActionCustomProjection.png"), tr("Custom Projection..."), this);
499
 
  // mActionCustomProjection->setShortcut(tr("Alt+I","Manage custom projections"));
500
 
  mActionCustomProjection->setStatusTip(tr("Manage custom projections"));
501
 
  connect(mActionCustomProjection, SIGNAL(triggered()), this, SLOT(customProjection()));
502
 
  //
503
 
  // Help Menu Related items
504
 
  //
505
 
  mActionHelpContents= new QAction(QIcon(myIconPath+"/mActionHelpContents.png"), tr("Help Contents"), this);
506
 
#ifdef Q_WS_MAC
507
 
  mActionHelpContents->setShortcut(tr("Ctrl+?","Help Documentation (Mac)"));
508
 
#else
509
 
  mActionHelpContents->setShortcut(tr("F1","Help Documentation"));
510
 
#endif
511
 
  mActionHelpContents->setStatusTip(tr("Help Documentation"));
512
 
  connect(mActionHelpContents, SIGNAL(triggered()), this, SLOT(helpContents()));
513
 
  //
514
 
  mActionQgisHomePage= new QAction(QIcon(myIconPath+"/mActionQgisHomePage.png"), tr("Qgis Home Page"), this);
515
 
#ifndef Q_WS_MAC
516
 
  mActionQgisHomePage->setShortcut(tr("Ctrl+H","QGIS Home Page"));
517
 
#endif
518
 
  mActionQgisHomePage->setStatusTip(tr("QGIS Home Page"));
519
 
  connect(mActionQgisHomePage, SIGNAL(triggered()), this, SLOT(helpQgisHomePage()));
520
 
  //
521
 
  mActionHelpAbout= new QAction(QIcon(myIconPath+"/mActionHelpAbout.png"), tr("About"), this);
522
 
  mActionHelpAbout->setStatusTip(tr("About QGIS"));
523
 
  connect(mActionHelpAbout, SIGNAL(triggered()), this, SLOT(about()));
524
 
  //
525
 
  mActionCheckQgisVersion= new QAction(QIcon(myIconPath+"/mActionCheckQgisVersion.png"), tr("Check Qgis Version"), this);
526
 
  mActionCheckQgisVersion->setStatusTip(tr("Check if your QGIS version is up to date (requires internet access)"));
527
 
  connect(mActionCheckQgisVersion, SIGNAL(triggered()), this, SLOT(checkQgisVersion()));
528
 
  // 
529
 
  // View Menu Items
530
 
  //
531
 
  mActionDraw= new QAction(QIcon(myIconPath+"/mActionDraw.png"), tr("Refresh"), this);
532
 
  mActionDraw->setShortcut(tr("Ctrl+R","Refresh Map"));
533
 
  mActionDraw->setStatusTip(tr("Refresh Map"));
534
 
  connect(mActionDraw, SIGNAL(triggered()), this, SLOT(refreshMapCanvas()));
535
 
  //
536
 
  mActionZoomIn= new QAction(QIcon(myIconPath+"/mActionZoomIn.png"), tr("Zoom In"), this);
537
 
  mActionZoomIn->setShortcut(tr("Ctrl++","Zoom In"));
538
 
  mActionZoomIn->setStatusTip(tr("Zoom In"));
539
 
  connect(mActionZoomIn, SIGNAL(triggered()), this, SLOT(zoomIn()));
540
 
  //
541
 
  mActionZoomOut= new QAction(QIcon(myIconPath+"/mActionZoomOut.png"), tr("Zoom Out"), this);
542
 
  mActionZoomOut->setShortcut(tr("Ctrl+-","Zoom Out"));
543
 
  mActionZoomOut->setStatusTip(tr("Zoom Out"));
544
 
  connect(mActionZoomOut, SIGNAL(triggered()), this, SLOT(zoomOut()));
545
 
  //
546
 
  mActionZoomFullExtent= new QAction(QIcon(myIconPath+"/mActionZoomFullExtent.png"), tr("Zoom Full"), this);
547
 
  mActionZoomFullExtent->setShortcut(tr("F","Zoom to Full Extents"));
548
 
  mActionZoomFullExtent->setStatusTip(tr("Zoom to Full Extents"));
549
 
  connect(mActionZoomFullExtent, SIGNAL(triggered()), this, SLOT(zoomFull()));
550
 
  //
551
 
  mActionZoomToSelected= new QAction(QIcon(myIconPath+"/mActionZoomToSelected.png"), tr("Zoom To Selection"), this);
552
 
  mActionZoomToSelected->setShortcut(tr("Ctrl+F","Zoom to selection"));
553
 
  mActionZoomToSelected->setStatusTip(tr("Zoom to selection"));
554
 
  connect(mActionZoomToSelected, SIGNAL(triggered()), this, SLOT(zoomToSelected()));
555
 
  //
556
 
  mActionPan= new QAction(QIcon(myIconPath+"/mActionPan.png"), tr("Pan Map"), this);
557
 
  mActionPan->setStatusTip(tr("Pan the map"));
558
 
  connect(mActionPan, SIGNAL(triggered()), this, SLOT(pan()));
559
 
  //
560
 
  mActionZoomLast= new QAction(QIcon(myIconPath+"/mActionZoomLast.png"), tr("Zoom Last"), this);
561
 
  //mActionZoomLast->setShortcut(tr("Ctrl+O","Zoom to Last Extent"));
562
 
  mActionZoomLast->setStatusTip(tr("Zoom to Last Extent"));
563
 
  connect(mActionZoomLast, SIGNAL(triggered()), this, SLOT(zoomPrevious()));
564
 
  //
565
 
  mActionZoomToLayer= new QAction(QIcon(myIconPath+"/mActionZoomToLayer.png"), tr("Zoom To Layer"), this);
566
 
  //mActionZoomToLayer->setShortcut(tr("Ctrl+O","Zoom to Layer"));
567
 
  mActionZoomToLayer->setStatusTip(tr("Zoom to Layer"));
568
 
  connect(mActionZoomToLayer, SIGNAL(triggered()), this, SLOT(zoomToLayerExtent()));
569
 
  //
570
 
  mActionIdentify= new QAction(QIcon(myIconPath+"/mActionIdentify.png"), tr("Identify Features"), this);
571
 
  mActionIdentify->setShortcut(tr("I","Click on features to identify them"));
572
 
  mActionIdentify->setStatusTip(tr("Click on features to identify them"));
573
 
  connect(mActionIdentify, SIGNAL(triggered()), this, SLOT(identify()));
574
 
  //
575
 
  mActionSelect= new QAction(QIcon(myIconPath+"/mActionSelect.png"), tr("Select Features"), this);
576
 
  mActionSelect->setStatusTip(tr("Select Features"));
577
 
  connect(mActionSelect, SIGNAL(triggered()), this, SLOT(select()));
578
 
  mActionSelect->setEnabled(false);
579
 
  //
580
 
  mActionOpenTable= new QAction(QIcon(myIconPath+"/mActionOpenTable.png"), tr("Open Table"), this);
581
 
  //mActionOpenTable->setShortcut(tr("Ctrl+O","Open Table"));
582
 
  mActionOpenTable->setStatusTip(tr("Open Table"));
583
 
  connect(mActionOpenTable, SIGNAL(triggered()), this, SLOT(attributeTable()));
584
 
  mActionOpenTable->setEnabled(false);
585
 
  //
586
 
  mActionMeasure= new QAction(QIcon(myIconPath+"/mActionMeasure.png"), tr("Measure Line "), this);
587
 
  mActionMeasure->setShortcut(tr("Ctrl+M","Measure a Line"));
588
 
  mActionMeasure->setStatusTip(tr("Measure a Line"));
589
 
  connect(mActionMeasure, SIGNAL(triggered()), this, SLOT(measure()));
590
 
  //
591
 
  mActionMeasureArea= new QAction(QIcon(myIconPath+"/mActionMeasureArea.png"), tr("Measure Area"), this);
592
 
  mActionMeasureArea->setShortcut(tr("Ctrl+J","Measure an Area"));
593
 
  mActionMeasureArea->setStatusTip(tr("Measure an Area"));
594
 
  connect(mActionMeasureArea, SIGNAL(triggered()), this, SLOT(measureArea()));
595
 
  //
596
 
  mActionShowBookmarks= new QAction(QIcon(myIconPath+"/mActionShowBookmarks.png"), tr("Show Bookmarks"), this);
597
 
  mActionShowBookmarks->setShortcut(tr("B","Show Bookmarks"));
598
 
  mActionShowBookmarks->setStatusTip(tr("Show Bookmarks"));
599
 
  connect(mActionShowBookmarks, SIGNAL(triggered()), this, SLOT(showBookmarks()));
600
 
  //
601
 
  mActionShowAllToolbars = new QAction(tr("Show most toolbars"), this);
602
 
  mActionShowAllToolbars->setShortcut(tr("T", "Show most toolbars"));
603
 
  mActionShowAllToolbars->setStatusTip(tr("Show most toolbars"));
604
 
  connect(mActionShowAllToolbars, SIGNAL(triggered()), this,
605
 
          SLOT(showAllToolbars()));
606
 
  //
607
 
  mActionHideAllToolbars = new QAction(tr("Hide most toolbars"), this);
608
 
  mActionHideAllToolbars->setShortcut(tr("Ctrl+T", "Hide most toolbars"));
609
 
  mActionHideAllToolbars->setStatusTip(tr("Hide most toolbars"));
610
 
  connect(mActionHideAllToolbars, SIGNAL(triggered()), this,
611
 
          SLOT(hideAllToolbars()));
612
 
  //
613
 
  mActionNewBookmark= new QAction(QIcon(myIconPath+"/mActionNewBookmark.png"), tr("New Bookmark..."), this);
614
 
  mActionNewBookmark->setShortcut(tr("Ctrl+B","New Bookmark"));
615
 
  mActionNewBookmark->setStatusTip(tr("New Bookmark"));
616
 
  connect(mActionNewBookmark, SIGNAL(triggered()), this, SLOT(newBookmark()));
617
 
  //
618
 
  mActionAddWmsLayer= new QAction(QIcon(myIconPath+"/mActionAddWmsLayer.png"), tr("Add WMS Layer..."), this);
619
 
  mActionAddWmsLayer->setShortcut(tr("W","Add Web Mapping Server Layer"));
620
 
  mActionAddWmsLayer->setStatusTip(tr("Add Web Mapping Server Layer"));
621
 
  connect(mActionAddWmsLayer, SIGNAL(triggered()), this, SLOT(addWmsLayer()));
622
 
  //
623
 
  mActionInOverview= new QAction(QIcon(myIconPath+"/mActionInOverview.png"), tr("In Overview"), this);
624
 
  mActionInOverview->setShortcut(tr("O","Add current layer to overview map"));
625
 
  mActionInOverview->setStatusTip(tr("Add current layer to overview map"));
626
 
  connect(mActionInOverview, SIGNAL(triggered()), this, SLOT(inOverview()));
627
 
  //
628
 
  // Plugin Menu Related Items
629
 
  //
630
 
  mActionShowPluginManager= new QAction(QIcon(myIconPath+"/mActionShowPluginManager.png"), tr("Plugin Manager..."), this);
631
 
  // mActionShowPluginManager->setShortcut(tr("Ctrl+P","Open the plugin manager"));
632
 
  mActionShowPluginManager->setStatusTip(tr("Open the plugin manager"));
633
 
  connect(mActionShowPluginManager, SIGNAL(triggered()), this, SLOT(showPluginManager()));
634
 
  //
635
 
  // Add the whats this toolbar button
636
 
  // QWhatsThis::whatsThisButton(mHelpToolBar);
637
 
  // 
638
 
  //
639
 
  // Digitising Toolbar Items
640
 
  //
641
 
 
642
 
  mActionStartEditing = new QAction(QIcon(myIconPath+"/mActionStartEditing.png"), 
643
 
                                    tr("Start editing the current layer"), this); 
644
 
  mActionStartEditing->setStatusTip(tr("Start editing the current layer")); 
645
 
  connect(mActionStartEditing, SIGNAL(triggered()), this, SLOT(startEditing()));
646
 
  //
647
 
  mActionStopEditing = new QAction(QIcon(myIconPath+"/mActionStopEditing.png"), 
648
 
                                   tr("Stop editing the current layer"), this);
649
 
  mActionStopEditing->setStatusTip(tr("Stop editing the current layer")); 
650
 
  connect(mActionStopEditing, SIGNAL(triggered()), this, SLOT(stopEditing()));
651
 
  //
652
 
  mActionCapturePoint= new QAction(QIcon(myIconPath+"/mActionCapturePoint.png"), tr("Capture Point"), this);
653
 
  mActionCapturePoint->setShortcut(tr(".","Capture Points"));
654
 
  mActionCapturePoint->setStatusTip(tr("Capture Points"));
655
 
  connect(mActionCapturePoint, SIGNAL(triggered()), this, SLOT(capturePoint()));
656
 
  mActionCapturePoint->setEnabled(false);
657
 
  //
658
 
  mActionCaptureLine= new QAction(QIcon(myIconPath+"/mActionCaptureLine.png"), tr("Capture Line"), this);
659
 
  mActionCaptureLine->setShortcut(tr("/","Capture Lines"));
660
 
  mActionCaptureLine->setStatusTip(tr("Capture Lines"));
661
 
  connect(mActionCaptureLine, SIGNAL(triggered()), this, SLOT(captureLine()));
662
 
  mActionCaptureLine->setEnabled(false);
663
 
  //
664
 
  mActionCapturePolygon= new QAction(QIcon(myIconPath+"/mActionCapturePolygon.png"), tr("Capture Polygon"), this);
665
 
  mActionCapturePolygon->setShortcut(tr("Ctrl+/","Capture Polygons"));
666
 
  mActionCapturePolygon->setStatusTip(tr("Capture Polygons"));
667
 
  connect(mActionCapturePolygon, SIGNAL(triggered()), this, SLOT(capturePolygon()));
668
 
  mActionCapturePolygon->setEnabled(false);
669
 
  //
670
 
  mActionDeleteSelected = new QAction(QIcon(myIconPath+"/mActionDeleteSelected.png"), tr("Delete Selected"), this);
671
 
  mActionDeleteSelected->setStatusTip(tr("Delete Selected"));
672
 
  connect(mActionDeleteSelected, SIGNAL(triggered()), this, SLOT(deleteSelected()));
673
 
  mActionDeleteSelected->setEnabled(false);
674
 
  //
675
 
  mActionAddVertex = new QAction(QIcon(myIconPath+"/mActionAddVertex.png"), tr("Add Vertex"), this);
676
 
  mActionAddVertex->setStatusTip(tr("Add Vertex"));
677
 
  connect(mActionAddVertex, SIGNAL(triggered()), this, SLOT(addVertex()));
678
 
  mActionAddVertex->setEnabled(false);
679
 
  //
680
 
  mActionDeleteVertex = new QAction(QIcon(myIconPath+"/mActionDeleteVertex.png"), tr("Delete Vertex"), this);
681
 
  mActionDeleteVertex->setStatusTip(tr("Delete Vertex"));
682
 
  connect(mActionDeleteVertex, SIGNAL(triggered()), this, SLOT(deleteVertex()));
683
 
  mActionDeleteVertex->setEnabled(false);
684
 
  //
685
 
  mActionMoveVertex = new QAction(QIcon(myIconPath+"/mActionMoveVertex.png"), tr("Move Vertex"), this);
686
 
  mActionMoveVertex->setStatusTip(tr("Move Vertex"));
687
 
  connect(mActionMoveVertex, SIGNAL(triggered()), this, SLOT(moveVertex()));
688
 
  mActionMoveVertex->setEnabled(false);
689
 
 
690
 
  mActionEditCut = new QAction(QIcon(myIconPath+"/mActionEditCut.png"), tr("Cut Features"), this);
691
 
  mActionEditCut->setStatusTip(tr("Cut selected features"));
692
 
  connect(mActionEditCut, SIGNAL(triggered()), this, SLOT(editCut()));
693
 
  mActionEditCut->setEnabled(false);
694
 
 
695
 
  mActionEditCopy = new QAction(QIcon(myIconPath+"/mActionEditCopy.png"), tr("Copy Features"), this);
696
 
  mActionEditCopy->setStatusTip(tr("Copy selected features"));
697
 
  connect(mActionEditCopy, SIGNAL(triggered()), this, SLOT(editCopy()));
698
 
  mActionEditCopy->setEnabled(false);
699
 
 
700
 
  mActionEditPaste = new QAction(QIcon(myIconPath+"/mActionEditPaste.png"), tr("Paste Features"), this);
701
 
  mActionEditPaste->setStatusTip(tr("Paste selected features"));
702
 
  connect(mActionEditPaste, SIGNAL(triggered()), this, SLOT(editPaste()));
703
 
  mActionEditPaste->setEnabled(false);
704
 
}
705
 
 
706
 
void QgisApp::createActionGroups()
707
 
{
708
 
  //
709
 
  // Map Tool Group
710
 
  mMapToolGroup = new QActionGroup(this);
711
 
  mActionPan->setCheckable(true);
712
 
  mMapToolGroup->addAction(mActionPan);
713
 
  mActionZoomIn->setCheckable(true);
714
 
  mMapToolGroup->addAction(mActionZoomIn);
715
 
  mActionZoomOut->setCheckable(true);
716
 
  mMapToolGroup->addAction(mActionZoomOut);
717
 
  mActionIdentify->setCheckable(true);
718
 
  mMapToolGroup->addAction(mActionIdentify);
719
 
  mActionSelect->setCheckable(true);
720
 
  mMapToolGroup->addAction(mActionSelect);
721
 
  mActionMeasure->setCheckable(true);
722
 
  mMapToolGroup->addAction(mActionMeasure);
723
 
  mActionMeasureArea->setCheckable(true);
724
 
  mMapToolGroup->addAction(mActionMeasureArea);
725
 
  mActionCaptureLine->setCheckable(true);
726
 
  mMapToolGroup->addAction(mActionCaptureLine);
727
 
  mActionCapturePoint->setCheckable(true);
728
 
  mMapToolGroup->addAction(mActionCapturePoint);
729
 
  mActionCapturePolygon->setCheckable(true);
730
 
  mMapToolGroup->addAction(mActionCapturePolygon);
731
 
  mMapToolGroup->addAction(mActionDeleteSelected);
732
 
  mActionAddVertex->setCheckable(true);
733
 
  mMapToolGroup->addAction(mActionAddVertex);
734
 
  mActionDeleteVertex->setCheckable(true);
735
 
  mMapToolGroup->addAction(mActionDeleteVertex);
736
 
  mActionMoveVertex->setCheckable(true);
737
 
  mMapToolGroup->addAction(mActionMoveVertex);
738
 
}
739
 
 
740
 
void QgisApp::createMenus()
741
 
{
742
 
  QString myIconPath = QgsApplication::themePath();
743
 
  //
744
 
  // File Menu
745
 
  mFileMenu = menuBar()->addMenu(tr("&File"));
746
 
  mFileMenu->addAction(mActionFileNew);
747
 
  mFileMenu->addAction(mActionFileOpen);
748
 
  mRecentProjectsMenu = mFileMenu->addMenu(tr("&Open Recent Projects"));
749
 
  // Connect once for the entire submenu.
750
 
  connect(mRecentProjectsMenu, SIGNAL(triggered(QAction *)),
751
 
          this, SLOT(openProject(QAction *)));
752
 
 
753
 
  mFileMenu->addSeparator();
754
 
  mFileMenu->addAction(mActionFileSave);
755
 
  mFileMenu->addAction(mActionFileSaveAs);
756
 
  mFileMenu->addAction(mActionSaveMapAsImage);
757
 
  mFileMenu->addSeparator();
758
 
  mFileMenu->addAction(mActionExportMapServer);
759
 
  mFileMenu->addAction(mActionFilePrint);
760
 
  mFileMenu->addSeparator();
761
 
  mFileMenu->addAction(mActionFileExit);
762
 
 
763
 
  //
764
 
  // View Menu
765
 
  mViewMenu = menuBar()->addMenu(tr("&View"));
766
 
  mViewMenu->addAction(mActionZoomFullExtent);
767
 
  mViewMenu->addAction(mActionZoomToSelected);
768
 
  mViewMenu->addAction(mActionZoomToLayer);
769
 
  mViewMenu->addAction(mActionZoomLast);
770
 
  mViewMenu->addAction(mActionDraw);
771
 
  mViewMenu->addSeparator();
772
 
  mViewMenu->addAction(mActionShowBookmarks);
773
 
  mViewMenu->addAction(mActionNewBookmark);
774
 
  mViewMenu->addSeparator();
775
 
  mToolbarMenu = mViewMenu->addMenu(QIcon(myIconPath+"/mActionOptions.png"),
776
 
                                    tr("&Toolbars..."));
777
 
 
778
 
  //
779
 
  // View:toolbars menu
780
 
  mToolbarMenu->addAction(mActionShowAllToolbars);
781
 
  mToolbarMenu->addAction(mActionHideAllToolbars);
782
 
 
783
 
  //
784
 
  // Layers Menu
785
 
  mLayerMenu = menuBar()->addMenu(tr("&Layer"));
786
 
  mLayerMenu->addAction(mActionAddNonDbLayer);
787
 
  mLayerMenu->addAction(mActionAddRasterLayer);
788
 
#ifdef HAVE_POSTGRESQL
789
 
  mLayerMenu->addAction(mActionAddLayer);
790
 
#endif
791
 
  mLayerMenu->addAction(mActionAddWmsLayer);
792
 
  mLayerMenu->addSeparator();
793
 
  mLayerMenu->addAction(mActionRemoveLayer);
794
 
  mLayerMenu->addAction(mActionNewVectorLayer);
795
 
  mLayerMenu->addSeparator();
796
 
  mLayerMenu->addAction(mActionInOverview);
797
 
  mLayerMenu->addAction(mActionAddAllToOverview);
798
 
  mLayerMenu->addAction(mActionRemoveAllFromOverview);
799
 
  mLayerMenu->addSeparator();
800
 
  mLayerMenu->addAction(mActionHideAllLayers);
801
 
  mLayerMenu->addAction(mActionShowAllLayers);
802
 
 
803
 
  //
804
 
  // Settings Menu
805
 
  mSettingsMenu = menuBar()->addMenu(tr("&Settings"));
806
 
  mSettingsMenu->addAction(mActionProjectProperties);
807
 
  mSettingsMenu->addAction(mActionCustomProjection);
808
 
  mSettingsMenu->addAction(mActionOptions);
809
 
  
810
 
  //
811
 
  // Plugins Menu
812
 
  mPluginMenu = menuBar()->addMenu(tr("&Plugins"));
813
 
  mPluginMenu->addAction(mActionShowPluginManager);
814
 
  mPluginMenu->addSeparator();
815
 
 
816
 
  // Add the plugin manager action to it
817
 
  //actionPluginManager->addTo(mPluginMenu);
818
 
  // Add separator. Plugins will add their menus to this
819
 
  // menu when they are loaded by the plugin manager
820
 
  //mPluginMenu->insertSeparator();
821
 
  // Add to the menubar
822
 
  //menuBar()->insertItem(tr("&Plugins"), mPluginMenu, -1, menuBar()->count() - 1);
823
 
 
824
 
  menuBar()->addSeparator();
825
 
  mHelpMenu = menuBar()->addMenu(tr("&Help"));
826
 
  mHelpMenu->addAction(mActionHelpContents);
827
 
  mHelpMenu->addSeparator();
828
 
  mHelpMenu->addAction(mActionQgisHomePage);
829
 
  mHelpMenu->addAction(mActionCheckQgisVersion);
830
 
  mHelpMenu->addSeparator();
831
 
  mHelpMenu->addAction(mActionHelpAbout);
832
 
}
833
 
 
834
 
void QgisApp::createToolBars()
835
 
{
836
 
  // Note: we need to set each object name to ensure that
837
 
  // qmainwindow::saveState and qmainwindow::restoreState
838
 
  // work properly
839
 
  
840
 
  //
841
 
  // File Toolbar
842
 
  mFileToolBar = addToolBar(tr("File"));
843
 
  mFileToolBar->setIconSize(QSize(24,24));
844
 
  mFileToolBar->setObjectName("FileToolBar");
845
 
  mFileToolBar->addAction(mActionFileNew);
846
 
  mFileToolBar->addAction(mActionFileNew);
847
 
  mFileToolBar->addAction(mActionFileSave);
848
 
  mFileToolBar->addAction(mActionFileSaveAs);
849
 
  mFileToolBar->addAction(mActionFileOpen);
850
 
  mFileToolBar->addAction(mActionFilePrint);
851
 
  //
852
 
  // Layer Toolbar
853
 
  mLayerToolBar = addToolBar(tr("Manage Layers"));
854
 
  mLayerToolBar->setIconSize(QSize(24,24));
855
 
  mLayerToolBar->setObjectName("LayerToolBar");
856
 
  mLayerToolBar->addAction(mActionAddNonDbLayer);
857
 
  mLayerToolBar->addAction(mActionAddRasterLayer);
858
 
#ifdef HAVE_POSTGRESQL
859
 
  mLayerToolBar->addAction(mActionAddLayer);
860
 
#endif
861
 
  mLayerToolBar->addAction(mActionAddWmsLayer);
862
 
  mLayerToolBar->addAction(mActionNewVectorLayer);
863
 
  mLayerToolBar->addAction(mActionRemoveLayer);
864
 
  mLayerToolBar->addAction(mActionInOverview);
865
 
  mLayerToolBar->addAction(mActionAddAllToOverview);
866
 
  mLayerToolBar->addAction(mActionRemoveAllFromOverview);
867
 
  mLayerToolBar->addAction(mActionShowAllLayers);
868
 
  mLayerToolBar->addAction(mActionHideAllLayers);
869
 
  //
870
 
  // Help Toolbar
871
 
  mHelpToolBar = addToolBar(tr("Help"));
872
 
  mHelpToolBar->setIconSize(QSize(24,24));
873
 
  mHelpToolBar->setObjectName("Help");
874
 
  mHelpToolBar->addAction(mActionHelpContents);
875
 
  //
876
 
  // Digitizing Toolbar
877
 
  mDigitizeToolBar = addToolBar(tr("Digitizing"));
878
 
  mDigitizeToolBar->setIconSize(QSize(24,24));
879
 
  mDigitizeToolBar->setObjectName("Digitizing");
880
 
  mDigitizeToolBar->addAction(mActionStartEditing);
881
 
  mDigitizeToolBar->addAction(mActionStopEditing);
882
 
  mDigitizeToolBar->addAction(mActionCapturePoint);
883
 
  mDigitizeToolBar->addAction(mActionCaptureLine);
884
 
  mDigitizeToolBar->addAction(mActionCapturePolygon);
885
 
  mDigitizeToolBar->addAction(mActionDeleteSelected);
886
 
  mDigitizeToolBar->addAction(mActionAddVertex);
887
 
  mDigitizeToolBar->addAction(mActionDeleteVertex);
888
 
  mDigitizeToolBar->addAction(mActionMoveVertex);
889
 
  mDigitizeToolBar->addAction(mActionEditCut);
890
 
  mDigitizeToolBar->addAction(mActionEditCopy);
891
 
  mDigitizeToolBar->addAction(mActionEditPaste);
892
 
  //
893
 
  // Map Navigation Toolbar
894
 
  mMapNavToolBar = addToolBar(tr("Map Navigation"));
895
 
  mMapNavToolBar->setIconSize(QSize(24,24));
896
 
  mMapNavToolBar->setObjectName("Map Navigation");
897
 
  mMapNavToolBar->addAction(mActionPan);
898
 
  mMapNavToolBar->addAction(mActionZoomIn);
899
 
  mMapNavToolBar->addAction(mActionZoomOut);
900
 
  mMapNavToolBar->addAction(mActionZoomFullExtent);
901
 
  mMapNavToolBar->addAction(mActionZoomToSelected);
902
 
  mMapNavToolBar->addAction(mActionZoomToLayer);
903
 
  mMapNavToolBar->addAction(mActionZoomLast);
904
 
  mMapNavToolBar->addAction(mActionDraw);
905
 
  //
906
 
  // Attributes Toolbar
907
 
  mAttributesToolBar = addToolBar(tr("Attributes"));
908
 
  mAttributesToolBar->setIconSize(QSize(24,24));
909
 
  mAttributesToolBar->setObjectName("Attributes");
910
 
  mAttributesToolBar->addAction(mActionIdentify);
911
 
  mAttributesToolBar->addAction(mActionSelect);
912
 
  mAttributesToolBar->addAction(mActionOpenTable);
913
 
  mAttributesToolBar->addAction(mActionMeasure);
914
 
  mAttributesToolBar->addAction(mActionMeasureArea);
915
 
  mAttributesToolBar->addAction(mActionShowBookmarks);
916
 
  mAttributesToolBar->addAction(mActionNewBookmark);
917
 
  //
918
 
  // Plugins Toolbar
919
 
  mPluginToolBar = addToolBar(tr("Plugins"));
920
 
  mPluginToolBar->setIconSize(QSize(24,24));
921
 
  mPluginToolBar->setObjectName("Plugins");
922
 
}
923
 
 
924
 
void QgisApp::createStatusBar()
925
 
{
926
 
  //
927
 
  // Add a panel to the status bar for the scale, coords and progress
928
 
  // And also rendering suppression checkbox
929
 
  //
930
 
  mProgressBar = new QProgressBar(statusBar());
931
 
  mProgressBar->setMaximumWidth(100);
932
 
  mProgressBar->hide();
933
 
  QWhatsThis::add(mProgressBar, tr("Progress bar that displays the status of rendering layers and other time-intensive operations"));
934
 
  statusBar()->addWidget(mProgressBar, 1,true);
935
 
  // Bumped the font up one point size since 8 was too 
936
 
  // small on some platforms. A point size of 9 still provides
937
 
  // plenty of display space on 1024x768 resolutions
938
 
  QFont myFont( "Arial", 9 );
939
 
  statusBar()->setFont(myFont);
940
 
  mScaleLabel = new QLabel(QString(),statusBar());
941
 
  mScaleLabel->setFont(myFont);
942
 
  mScaleLabel->setMinimumWidth(10);
943
 
  mScaleLabel->setMargin(3);
944
 
  mScaleLabel->setAlignment(Qt::AlignCenter);
945
 
  QWhatsThis::add(mScaleLabel, tr("Displays the current map scale"));
946
 
  QToolTip::add (mScaleLabel, tr("Current map scale"));
947
 
  statusBar()->addWidget(mScaleLabel, 0,true);
948
 
  //coords status bar widget
949
 
  mCoordsLabel = new QLabel(QString(), statusBar());
950
 
  mCoordsLabel->setMinimumWidth(10);
951
 
  mCoordsLabel->setFont(myFont);
952
 
  mCoordsLabel->setMargin(3);
953
 
  mCoordsLabel->setAlignment(Qt::AlignCenter);
954
 
  QWhatsThis::add(mCoordsLabel, tr("Shows the map coordinates at the current cursor postion. The display is continuously updated as the mouse is moved."));
955
 
  QToolTip::add (mCoordsLabel, tr("Map coordinates at mouse cursor position"));
956
 
  statusBar()->addWidget(mCoordsLabel, 0, true);
957
 
  // render suppression status bar widget
958
 
  mRenderSuppressionCBox = new QCheckBox(tr("Render"),statusBar());
959
 
  mRenderSuppressionCBox->setChecked(true);
960
 
  mRenderSuppressionCBox->setFont(myFont);
961
 
  QWhatsThis::add(mRenderSuppressionCBox, tr("When checked, the map layers are rendered in response to map navigation commands and other events. When not checked, no rendering is done. This allows you to add a large number of layers and symbolize them before rendering."));
962
 
  QToolTip::add( mRenderSuppressionCBox, tr("Toggle map rendering") );
963
 
  statusBar()->addWidget(mRenderSuppressionCBox,0,true);
964
 
  // On the fly projection status bar icon
965
 
  // Changed this to a tool button since a QPushButton is
966
 
  // sculpted on OS X and the icon is never displayed [gsherman]
967
 
  mOnTheFlyProjectionStatusButton = new QToolButton(statusBar());
968
 
  mOnTheFlyProjectionStatusButton->setMaximumWidth(20);
969
 
  // Maintain uniform widget height in status bar by setting button height same as labels
970
 
  // For Qt/Mac 3.3, the default toolbutton height is 30 and labels were expanding to match
971
 
  mOnTheFlyProjectionStatusButton->setMaximumHeight(mScaleLabel->height());
972
 
  QPixmap myProjPixmap;
973
 
  QString myIconPath = QgsApplication::themePath();
974
 
  myProjPixmap.load(myIconPath+"/mIconProjectionDisabled.png");
975
 
  mOnTheFlyProjectionStatusButton->setPixmap(myProjPixmap);
976
 
  assert(!myProjPixmap.isNull());
977
 
  QWhatsThis::add(mOnTheFlyProjectionStatusButton, tr("This icon shows whether on the fly projection is enabled or not. Click the icon to bring up the project properties dialog to alter this behaviour."));
978
 
  QToolTip::add( mOnTheFlyProjectionStatusButton, tr("Projection status - Click to open projection dialog"));
979
 
  connect(mOnTheFlyProjectionStatusButton, SIGNAL(clicked()),
980
 
      this, SLOT(projectPropertiesProjections()));//bring up the project props dialog when clicked
981
 
  statusBar()->addWidget(mOnTheFlyProjectionStatusButton,0,true);
982
 
  statusBar()->showMessage(tr("Ready"));
983
 
}
984
 
 
985
 
QString QgisApp::themePath()
986
 
{
987
 
  return mAppDir +"/share/qgis/themes/" + mThemeName + "/";
988
 
}
989
 
 
990
 
 
991
 
void QgisApp::setTheme(QString theThemeName)
992
 
{
993
 
  /*****************************************************************
994
 
  // Init the toolbar icons by setting the icon for each action.
995
 
  // All toolbar/menu items must be a QAction in order for this
996
 
  // to work.
997
 
  //
998
 
  // When new toolbar/menu QAction objects are added to the interface,
999
 
  // add an entry below to set the icon
1000
 
  //
1001
 
  // PNG names must match those defined for the default theme. The
1002
 
  // default theme is installed in <prefix>/share/qgis/themes/default.
1003
 
  //
1004
 
  // New core themes can be added by creating a subdirectory under src/themes
1005
 
  // and modifying the appropriate Makefile.am files. User contributed themes
1006
 
  // will be installed directly into <prefix>/share/qgis/themes/<themedir>.
1007
 
  //
1008
 
  // Themes can be selected from the preferences dialog. The dialog parses
1009
 
  // the themes directory and builds a list of themes (ie subdirectories)
1010
 
  // for the user to choose from.
1011
 
  //
1012
 
  // TODO: Check as each icon is grabbed and if it doesn't exist, use the
1013
 
  // one from the default theme (which is installed with qgis and should
1014
 
  // always be good)
1015
 
  */
1016
 
  QgsApplication::selectTheme(theThemeName);
1017
 
  QString myIconPath = QgsApplication::themePath();
1018
 
  mActionFileNew->setIconSet(QIcon(QPixmap(myIconPath + "/mActionFileNew.png")));
1019
 
  mActionFileSave->setIconSet(QIcon(QPixmap(myIconPath + "/mActionFileSave.png")));
1020
 
  mActionFileSaveAs->setIconSet(QIcon(QPixmap(myIconPath + "/mActionFileSaveAs.png")));
1021
 
  mActionFileOpen->setIconSet(QIcon(QPixmap(myIconPath + "/mActionFileOpen.png")));
1022
 
  mActionFilePrint->setIconSet(QIcon(QPixmap(myIconPath + "/mActionFilePrint.png")));
1023
 
  mActionSaveMapAsImage->setIconSet(QIcon(QPixmap(myIconPath + "/mActionSaveMapAsImage.png")));
1024
 
  mActionExportMapServer->setIconSet(QIcon(QPixmap(myIconPath + "/mActionExportMapServer.png")));
1025
 
  mActionFileExit->setIconSet(QIcon(QPixmap(myIconPath + "/mActionFileExit.png")));
1026
 
  mActionAddNonDbLayer->setIconSet(QIcon(QPixmap(myIconPath + "/mActionAddNonDbLayer.png")));
1027
 
  mActionAddRasterLayer->setIconSet(QIcon(QPixmap(myIconPath + "/mActionAddRasterLayer.png")));
1028
 
  mActionAddLayer->setIconSet(QIcon(QPixmap(myIconPath + "/mActionAddLayer.png")));
1029
 
  mActionRemoveLayer->setIconSet(QIcon(QPixmap(myIconPath + "/mActionRemoveLayer.png")));
1030
 
  mActionNewVectorLayer->setIconSet(QIcon(QPixmap(myIconPath + "/mActionNewVectorLayer.png")));
1031
 
  mActionAddAllToOverview->setIconSet(QIcon(QPixmap(myIconPath + "/mActionAddAllToOverview.png")));
1032
 
  mActionHideAllLayers->setIconSet(QIcon(QPixmap(myIconPath + "/mActionHideAllLayers.png")));
1033
 
  mActionShowAllLayers->setIconSet(QIcon(QPixmap(myIconPath + "/mActionShowAllLayers.png")));
1034
 
  mActionRemoveAllFromOverview->setIconSet(QIcon(QPixmap(myIconPath + "/mActionRemoveAllFromOverview.png")));
1035
 
  mActionProjectProperties->setIconSet(QIcon(QPixmap(myIconPath + "/mActionProjectProperties.png")));
1036
 
  mActionShowPluginManager->setIconSet(QIcon(QPixmap(myIconPath + "/mActionShowPluginManager.png")));
1037
 
  mActionCheckQgisVersion->setIconSet(QIcon(QPixmap(myIconPath + "/mActionCheckQgisVersion.png")));
1038
 
  mActionOptions->setIconSet(QIcon(QPixmap(myIconPath + "/mActionOptions.png")));
1039
 
  mActionHelpContents->setIconSet(QIcon(QPixmap(myIconPath + "/mActionHelpContents.png")));
1040
 
  mActionQgisHomePage->setIconSet(QIcon(QPixmap(myIconPath + "/mActionQgisHomePage.png")));
1041
 
  mActionHelpAbout->setIconSet(QIcon(QPixmap(myIconPath + "/mActionHelpAbout.png")));
1042
 
  mActionDraw->setIconSet(QIcon(QPixmap(myIconPath + "/mActionDraw.png")));
1043
 
  mActionCapturePoint->setIconSet(QIcon(QPixmap(myIconPath + "/mActionCapturePoint.png")));
1044
 
  mActionCaptureLine->setIconSet(QIcon(QPixmap(myIconPath + "/mActionCaptureLine.png")));
1045
 
  mActionCapturePolygon->setIconSet(QIcon(QPixmap(myIconPath + "/mActionCapturePolygon.png")));
1046
 
  mActionZoomIn->setIconSet(QIcon(QPixmap(myIconPath + "/mActionZoomIn.png")));
1047
 
  mActionZoomOut->setIconSet(QIcon(QPixmap(myIconPath + "/mActionZoomOut.png")));
1048
 
  mActionZoomFullExtent->setIconSet(QIcon(QPixmap(myIconPath + "/mActionZoomFullExtent.png")));
1049
 
  mActionZoomToSelected->setIconSet(QIcon(QPixmap(myIconPath + "/mActionZoomToSelected.png")));
1050
 
  mActionPan->setIconSet(QIcon(QPixmap(myIconPath + "/mActionPan.png")));
1051
 
  mActionZoomLast->setIconSet(QIcon(QPixmap(myIconPath + "/mActionZoomLast.png")));
1052
 
  mActionZoomToLayer->setIconSet(QIcon(QPixmap(myIconPath + "/mActionZoomToLayer.png")));
1053
 
  mActionIdentify->setIconSet(QIcon(QPixmap(myIconPath + "/mActionIdentify.png")));
1054
 
  mActionSelect->setIconSet(QIcon(QPixmap(myIconPath + "/mActionSelect.png")));
1055
 
  mActionOpenTable->setIconSet(QIcon(QPixmap(myIconPath + "/mActionOpenTable.png")));
1056
 
  mActionMeasure->setIconSet(QIcon(QPixmap(myIconPath + "/mActionMeasure.png")));
1057
 
  mActionMeasureArea->setIconSet(QIcon(QPixmap(myIconPath + "/mActionMeasureArea.png")));
1058
 
  mActionShowBookmarks->setIconSet(QIcon(QPixmap(myIconPath + "/mActionShowBookmarks.png")));
1059
 
  mActionNewBookmark->setIconSet(QIcon(QPixmap(myIconPath + "/mActionNewBookmark.png")));
1060
 
  mActionCustomProjection->setIconSet(QIcon(QPixmap(myIconPath + "/mActionCustomProjection.png")));
1061
 
  mActionAddWmsLayer->setIconSet(QIcon(QPixmap(myIconPath + "/mActionAddWmsLayer.png")));
1062
 
  mActionInOverview->setIconSet(QIcon(QPixmap(myIconPath + "/mActionInOverview.png")));
1063
 
}
1064
 
 
1065
 
void QgisApp::setupConnections()
1066
 
{
1067
 
  // connect the "cleanup" slot
1068
 
  connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(saveWindowState()));
1069
 
  //connect the legend, mapcanvas and overview canvas to the registry
1070
 
  
1071
 
  // connect map layer registry signals to legend
1072
 
  connect(QgsMapLayerRegistry::instance(), SIGNAL(layerWillBeRemoved(QString)),
1073
 
          mMapLegend, SLOT(removeLayer(QString)));
1074
 
  connect(QgsMapLayerRegistry::instance(), SIGNAL(removedAll()),
1075
 
          mMapLegend, SLOT(removeAll()));
1076
 
  connect(QgsMapLayerRegistry::instance(), SIGNAL(layerWasAdded(QgsMapLayer*)),
1077
 
          mMapLegend, SLOT(addLayer(QgsMapLayer *)));
1078
 
  
1079
 
  //signal when mouse moved over window (coords display in status bar)
1080
 
  connect(mMapCanvas, SIGNAL(xyCoordinates(QgsPoint &)), this, SLOT(showMouseCoordinate(QgsPoint &)));
1081
 
  //signal when mouse in capturePoint mode and mouse clicked on canvas
1082
 
  connect(mMapCanvas->mapRender(), SIGNAL(drawingProgress(int,int)), this, SLOT(showProgress(int,int)));
1083
 
  connect(mMapCanvas, SIGNAL(extentsChanged(QgsRect )),this,SLOT(showExtents(QgsRect )));
1084
 
  connect(mMapCanvas, SIGNAL(scaleChanged(QString)), this, SLOT(showScale(QString)));
1085
 
  connect(mMapCanvas, SIGNAL(scaleChanged(QString)), this, SLOT(updateMouseCoordinatePrecision()));
1086
 
 
1087
 
  connect(mRenderSuppressionCBox, SIGNAL(toggled(bool )), mMapCanvas, SLOT(setRenderFlag(bool)));
1088
 
}
1089
 
void QgisApp::createCanvas()
1090
 
{
1091
 
  // "theMapCanvas" used to find this canonical instance later
1092
 
  mMapCanvas = new QgsMapCanvas(NULL, "theMapCanvas" );
1093
 
  QWhatsThis::add(mMapCanvas, tr("Map canvas. This is where raster and vector layers are displayed when added to the map"));
1094
 
  
1095
 
  mMapCanvas->setMinimumWidth(10);
1096
 
  QVBoxLayout *myCanvasLayout = new QVBoxLayout;
1097
 
  myCanvasLayout->addWidget(mMapCanvas);
1098
 
  tabWidget->widget(0)->setLayout(myCanvasLayout);
1099
 
  // set the focus to the map canvas
1100
 
  mMapCanvas->setFocus();
1101
 
 
1102
 
  // create tools
1103
 
  mMapTools.mZoomIn = new QgsMapToolZoom(mMapCanvas, FALSE /* zoomIn */);
1104
 
  mMapTools.mZoomIn->setAction(mActionZoomIn);
1105
 
  mMapTools.mZoomOut = new QgsMapToolZoom(mMapCanvas, TRUE /* zoomOut */);
1106
 
  mMapTools.mZoomOut->setAction(mActionZoomOut);
1107
 
  mMapTools.mPan = new QgsMapToolPan(mMapCanvas);
1108
 
  mMapTools.mPan->setAction(mActionPan);
1109
 
  mMapTools.mIdentify = new QgsMapToolIdentify(mMapCanvas);
1110
 
  mMapTools.mIdentify->setAction(mActionIdentify);
1111
 
  mMapTools.mMeasureDist = new QgsMeasure(FALSE /* area */, mMapCanvas);
1112
 
  mMapTools.mMeasureDist->setAction(mActionMeasure);
1113
 
  mMapTools.mMeasureArea = new QgsMeasure(TRUE /* area */, mMapCanvas);
1114
 
  mMapTools.mMeasureArea->setAction(mActionMeasureArea);
1115
 
  mMapTools.mCapturePoint = new QgsMapToolCapture(mMapCanvas, QgsMapToolCapture::CapturePoint);
1116
 
  mMapTools.mCapturePoint->setAction(mActionCapturePoint);
1117
 
  mMapTools.mCaptureLine = new QgsMapToolCapture(mMapCanvas, QgsMapToolCapture::CaptureLine);
1118
 
  mMapTools.mCaptureLine->setAction(mActionCaptureLine);
1119
 
  mMapTools.mCapturePolygon = new QgsMapToolCapture(mMapCanvas, QgsMapToolCapture::CapturePolygon);
1120
 
  mMapTools.mCapturePolygon->setAction(mActionCapturePolygon);
1121
 
  mMapTools.mSelect = new QgsMapToolSelect(mMapCanvas);
1122
 
  mMapTools.mSelect->setAction(mActionSelect);
1123
 
  mMapTools.mVertexAdd = new QgsMapToolVertexEdit(mMapCanvas, QgsMapToolVertexEdit::AddVertex);
1124
 
  mMapTools.mVertexAdd->setAction(mActionAddVertex);
1125
 
  mMapTools.mVertexMove = new QgsMapToolVertexEdit(mMapCanvas, QgsMapToolVertexEdit::MoveVertex);
1126
 
  mMapTools.mVertexMove->setAction(mActionMoveVertex);
1127
 
  mMapTools.mVertexDelete = new QgsMapToolVertexEdit(mMapCanvas, QgsMapToolVertexEdit::DeleteVertex);
1128
 
  mMapTools.mVertexDelete->setAction(mActionDeleteVertex);
1129
 
}
1130
 
 
1131
 
void QgisApp::createOverview()
1132
 
{
1133
 
  // overview canvas
1134
 
  QgsMapOverviewCanvas* overviewCanvas = new QgsMapOverviewCanvas(NULL, mMapCanvas);
1135
 
  QWhatsThis::add(overviewCanvas, tr("Map overview canvas. This canvas can be used to display a locator map that shows the current extent of the map canvas. The current extent is shown as a red rectangle. Any layer on the map can be added to the overview canvas."));
1136
 
        
1137
 
  QBitmap overviewPanBmp(16, 16, pan_bits, true);
1138
 
  QBitmap overviewPanBmpMask(16, 16, pan_mask_bits, true);
1139
 
  mOverviewMapCursor = new QCursor(overviewPanBmp, overviewPanBmpMask, 5, 5);
1140
 
  overviewCanvas->setCursor(*mOverviewMapCursor);
1141
 
  QVBoxLayout *myOverviewLayout = new QVBoxLayout;
1142
 
  myOverviewLayout->addWidget(overviewCanvas);
1143
 
  overviewFrame->setLayout(myOverviewLayout);
1144
 
  
1145
 
  mMapCanvas->setOverview(overviewCanvas);
1146
 
  
1147
 
  // moved here to set anti aliasing to both map canvas and overview
1148
 
  QSettings mySettings;
1149
 
  mMapCanvas->enableAntiAliasing(mySettings.value("/qgis/enable_anti_aliasing",false).toBool());
1150
 
  mMapCanvas->useQImageToRender(mySettings.value("/qgis/use_qimage_to_render",false).toBool());
1151
 
 
1152
 
  int action = mySettings.value("/qgis/wheel_action", 0).toInt();
1153
 
  double zoomFactor = mySettings.value("/qgis/zoom_factor", 2).toDouble();
1154
 
  mMapCanvas->setWheelAction((QgsMapCanvas::WheelAction) action, zoomFactor);
1155
 
}
1156
 
 
1157
 
 
1158
 
void QgisApp::createLegend()
1159
 
{
1160
 
  //legend
1161
 
  mMapLegend = new QgsLegend(this,NULL, "theMapLegend");
1162
 
  mMapLegend->setObjectName("theMapLegend");
1163
 
  mMapLegend->setMapCanvas(mMapCanvas);
1164
 
  QWhatsThis::add(mMapLegend, tr("Map legend that displays all the layers currently on the map canvas. Click on the check box to turn a layer on or off. Double click on a layer in the legend to customize its appearance and set other properties."));
1165
 
  QVBoxLayout *myLegendLayout = new QVBoxLayout;
1166
 
  myLegendLayout->addWidget(mMapLegend);
1167
 
  toolBox->widget(0)->setLayout(myLegendLayout);
1168
 
  return;
1169
 
}
1170
 
 
1171
 
bool QgisApp::createDB()
1172
 
{
1173
 
  // Check qgis.db and make private copy if necessary
1174
 
  QFile qgisPrivateDbFile(QgsApplication::qgisUserDbFilePath());
1175
 
 
1176
 
  // first we look for ~/.qgis/qgis.db
1177
 
  if (!qgisPrivateDbFile.exists())
1178
 
  {
1179
 
    // if it doesnt exist we copy it in from the global resources dir
1180
 
    QString qgisMasterDbFileName = QgsApplication::qgisMasterDbFilePath();
1181
 
    QFile masterFile(qgisMasterDbFileName);
1182
 
 
1183
 
    // Must be sure there is destination directory ~/.qgis
1184
 
    QDir().mkpath(QgsApplication::qgisSettingsDirPath());
1185
 
 
1186
 
    //now copy the master file into the users .qgis dir
1187
 
    bool isDbFileCopied = masterFile.copy(qgisPrivateDbFile.name());
1188
 
 
1189
 
#ifdef QGISDEBUG
1190
 
    if (!isDbFileCopied)
1191
 
    {
1192
 
      std::cout << "[ERROR] Can not make qgis.db private copy" << std::endl;
1193
 
      return FALSE;
1194
 
    }
1195
 
#endif
1196
 
  }
1197
 
  return TRUE;
1198
 
}
1199
 
 
1200
 
// Update file menu with the current list of recently accessed projects
1201
 
void QgisApp::updateRecentProjectPaths()
1202
 
{
1203
 
  // Remove existing paths from the recent projects menu
1204
 
  int i;
1205
 
 
1206
 
  int menusize = mRecentProjectsMenu->actions().size();
1207
 
 
1208
 
  for(i = menusize; i < mRecentProjectPaths.size(); i++)
1209
 
  {
1210
 
    mRecentProjectsMenu->addAction("Dummy text");
1211
 
  }
1212
 
 
1213
 
  QList<QAction *> menulist = mRecentProjectsMenu->actions();
1214
 
 
1215
 
  assert(menulist.size() == mRecentProjectPaths.size());
1216
 
 
1217
 
  for (i = 0; i < mRecentProjectPaths.size(); i++)
1218
 
    {
1219
 
      menulist.at(i)->setText(mRecentProjectPaths.at(i));
1220
 
 
1221
 
      // Disable this menu item if the file has been removed, if not enable it
1222
 
      menulist.at(i)->setEnabled(QFile::exists((mRecentProjectPaths.at(i))));
1223
 
 
1224
 
    }
1225
 
} // QgisApp::updateRecentProjectPaths
1226
 
 
1227
 
// add this file to the recently opened/saved projects list
1228
 
void QgisApp::saveRecentProjectPath(QString projectPath, QSettings & settings)
1229
 
{
1230
 
  // Get canonical absolute path
1231
 
  QFileInfo myFileInfo(projectPath);
1232
 
  projectPath = myFileInfo.absFilePath();
1233
 
 
1234
 
  // If this file is already in the list, remove it
1235
 
  mRecentProjectPaths.removeAll(projectPath);
1236
 
 
1237
 
  // Prepend this file to the list
1238
 
  mRecentProjectPaths.prepend(projectPath);
1239
 
 
1240
 
  // Keep the list to 8 items by trimming excess off the bottom
1241
 
  while (mRecentProjectPaths.count() > 8)
1242
 
  {
1243
 
    mRecentProjectPaths.pop_back();
1244
 
  }
1245
 
 
1246
 
  // Persist the list
1247
 
  settings.writeEntry("/UI/recentProjectsList", mRecentProjectPaths);
1248
 
 
1249
 
  // Update menu list of paths
1250
 
  updateRecentProjectPaths();
1251
 
 
1252
 
} // QgisApp::saveRecentProjectPath
1253
 
 
1254
 
void QgisApp::saveWindowState()
1255
 
{
1256
 
  // store window and toolbar positions
1257
 
  QSettings settings;
1258
 
  // store the toolbar/dock widget settings using Qt4 settings API
1259
 
  settings.setValue("/Geometry/state", this->saveState());
1260
 
 
1261
 
  // store window geometry
1262
 
  QPoint p = this->pos();
1263
 
  QSize s = this->size();
1264
 
  settings.writeEntry("/Geometry/maximized", this->isMaximized());
1265
 
  settings.writeEntry("/Geometry/x", p.x());
1266
 
  settings.writeEntry("/Geometry/y", p.y());
1267
 
  settings.writeEntry("/Geometry/w", s.width());
1268
 
  settings.writeEntry("/Geometry/h", s.height());
1269
 
  settings.setValue("/Geometry/canvasSplitterState", canvasLegendSplit->saveState());
1270
 
  settings.setValue("/Geometry/legendSplitterState", legendOverviewSplit->saveState());
1271
 
}
1272
 
 
1273
 
void QgisApp::restoreWindowState()
1274
 
{
1275
 
  // restore the toolbar and dock widgets postions using Qt4 settings API
1276
 
  QSettings settings;
1277
 
  QVariant vstate = settings.value("/Geometry/state");
1278
 
  this->restoreState(vstate.toByteArray());
1279
 
 
1280
 
  // restore window geometry
1281
 
  QDesktopWidget *d = QApplication::desktop();
1282
 
  int dw = d->width();          // returns desktop width
1283
 
  int dh = d->height();         // returns desktop height
1284
 
  int w = settings.readNumEntry("/Geometry/w", 600);
1285
 
  int h = settings.readNumEntry("/Geometry/h", 400);
1286
 
  int x = settings.readNumEntry("/Geometry/x", (dw - 600) / 2);
1287
 
  int y = settings.readNumEntry("/Geometry/y", (dh - 400) / 2);
1288
 
  resize(w, h);
1289
 
  move(x, y);
1290
 
 
1291
 
  canvasLegendSplit->restoreState(settings.value("/Geometry/canvasSplitterState").toByteArray());
1292
 
  legendOverviewSplit->restoreState(settings.value("/Geometry/legendSplitterState").toByteArray());
1293
 
}
1294
 
///////////// END OF GUI SETUP ROUTINES ///////////////
1295
 
 
1296
 
void QgisApp::about()
1297
 
{
1298
 
  static QgsAbout *abt = NULL;
1299
 
  if (!abt) {
1300
 
     QApplication::setOverrideCursor(Qt::WaitCursor);
1301
 
     abt = new QgsAbout();
1302
 
     QString versionString = tr("Version ");
1303
 
     versionString += QGis::qgisVersion;
1304
 
     versionString += " (";
1305
 
     versionString += QGis::qgisSvnVersion;
1306
 
     versionString += ")";
1307
 
#ifdef HAVE_POSTGRESQL
1308
 
 
1309
 
versionString += tr(" with PostgreSQL support");
1310
 
#else
1311
 
 
1312
 
versionString += tr(" (no PostgreSQL support)");
1313
 
#endif
1314
 
 versionString += tr("\nCompiled against Qt ") + QT_VERSION_STR
1315
 
   + tr(", running against Qt ") + qVersion();
1316
 
 
1317
 
#ifdef WIN32
1318
 
  // special version stuff for windows (if required)
1319
 
  //  versionString += "\nThis is a Windows preview release - not for production use";
1320
 
#endif
1321
 
 
1322
 
abt->setVersion(versionString);
1323
 
QString urls = "<p align=\"center\">" +
1324
 
tr("Quantum GIS is licensed under the GNU General Public License") +
1325
 
"</p><p align=\"center\">" +
1326
 
tr("http://www.gnu.org/licenses") +
1327
 
"</p>";
1328
 
abt->setURLs(urls);
1329
 
QString watsNew = "<html><body>" + tr("Version") + " ";
1330
 
watsNew += QGis::qgisVersion;
1331
 
watsNew += "<h3>" + tr("New features") + "</h3>";
1332
 
watsNew += "<ul><li>"
1333
 
  + tr("Numerous bug fixes")
1334
 
+ "<li>"
1335
 
+ tr("Improvements in how segment lengths appear in the measure tool.  The current segment length is shown/updated in the list of segments")
1336
 
+ "<li>"
1337
 
+ tr("Improvement to zoom-in speed for rasters")
1338
 
+ "<li>"
1339
 
+ tr("Improve line/area measuring behaviour when the user has been informed that they are probably using the wrong projection for the map canvas")
1340
 
+ "<li>"
1341
 
+ tr("Added tooltips to the scale and coordinate position displays in the status bar")
1342
 
+ "<li>"
1343
 
+ tr("Removed ugly console on WIN32 when not debugging")
1344
 
+ "<li>"
1345
 
+ tr("Added icons to all GRASS tools. All GRASS tools are now on the toolbar")
1346
 
+ "<li>"
1347
 
+ tr("New GRASS modules added to the GRASS toolbox")
1348
 
+ "<li>"
1349
 
+ tr("The GRASS plugin is now fully internationalized")
1350
 
+ "<li>"
1351
 
+ tr("Launcher plugin added to core plugins ")
1352
 
+ "</ul></body></html>";
1353
 
 
1354
 
 
1355
 
abt->setWhatsNew(watsNew);
1356
 
 
1357
 
  // add the available plugins to the list
1358
 
  QString providerInfo = "<b>" + tr("Available Data Provider Plugins") + "</b><br>";
1359
 
  abt->setPluginInfo(providerInfo + mProviderRegistry->pluginList(true));
1360
 
  QApplication::restoreOverrideCursor();
1361
 
  }
1362
 
  abt->show();
1363
 
  abt->raise();
1364
 
  abt->setActiveWindow();
1365
 
}
1366
 
 
1367
 
/** Load up any plugins used in the last session
1368
 
*/
1369
 
 
1370
 
void QgisApp::restoreSessionPlugins(QString thePluginDirString)
1371
 
{
1372
 
 
1373
 
  QSettings mySettings;
1374
 
#ifdef QGISDEBUG
1375
 
 
1376
 
  std::cerr << " -------------------- Restoring plugins from last session " << thePluginDirString.toLocal8Bit().data() << std::endl;
1377
 
#endif
1378
 
  // check all libs in the current plugin directory and get name and descriptions
1379
 
#ifdef WIN32
1380
 
 
1381
 
  QDir myPluginDir(thePluginDirString, "*.dll", QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks);
1382
 
#else
1383
 
 
1384
 
  QDir myPluginDir(thePluginDirString, "*.so*", QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks);
1385
 
#endif
1386
 
 
1387
 
  if (myPluginDir.count() == 0)
1388
 
  {
1389
 
    //erk! do nothing
1390
 
    return;
1391
 
  }
1392
 
  else
1393
 
  {
1394
 
    for (unsigned i = 0; i < myPluginDir.count(); i++)
1395
 
    {
1396
 
      QString myFullPath = thePluginDirString + "/" + myPluginDir[i];
1397
 
#ifdef QGISDEBUG
1398
 
 
1399
 
      std::cerr << "Examining " << myFullPath.toLocal8Bit().data() << std::endl;
1400
 
#endif
1401
 
 
1402
 
      QLibrary *myLib = new QLibrary(myFullPath);
1403
 
      myLib->setLoadHints(QLibrary::ExportExternalSymbolsHint | QLibrary::ResolveAllSymbolsHint);
1404
 
      bool loaded = myLib->load();
1405
 
      if (loaded)
1406
 
      {
1407
 
#ifdef QGISDEBUG
1408
 
        //purposely leaving this one to stdout!
1409
 
        std::cout << "Loaded " << myLib->library().toLocal8Bit().data() << std::endl;
1410
 
#endif
1411
 
        name_t * myName =(name_t *) myLib->resolve("name");
1412
 
        description_t *  myDescription = (description_t *)  myLib->resolve("description");
1413
 
        version_t *  myVersion =  (version_t *) myLib->resolve("version");
1414
 
        if (myName && myDescription  && myVersion )
1415
 
        {
1416
 
          //check if the plugin was active on last session
1417
 
          QString myEntryName = myName();
1418
 
          // Windows stores a "true" value as a 1 in the registry so we
1419
 
          // have to use readBoolEntry in this function
1420
 
 
1421
 
          if (mySettings.readBoolEntry("/Plugins/" + myEntryName))
1422
 
          {
1423
 
#ifdef QGISDEBUG
1424
 
            std::cerr << " -------------------- loading " << myEntryName.toLocal8Bit().data() << std::endl;
1425
 
#endif
1426
 
 
1427
 
            loadPlugin(myName(), myDescription(), myFullPath);
1428
 
          }
1429
 
        }
1430
 
        else
1431
 
        {
1432
 
#ifdef QGISDEBUG
1433
 
          std::cerr << "Failed to get name, description, or type for " << myLib->library().toLocal8Bit().data() << std::endl;
1434
 
#endif
1435
 
 
1436
 
        }
1437
 
      }
1438
 
      else
1439
 
      {
1440
 
        std::cerr << "Failed to load " << myLib->library().toLocal8Bit().data() << std::endl;
1441
 
        std::cerr << "Reason: " << myLib->errorString().toLocal8Bit().data() << std::endl;
1442
 
      }
1443
 
      delete myLib;
1444
 
    }
1445
 
  }
1446
 
 
1447
 
}
1448
 
 
1449
 
 
1450
 
/**
1451
 
 
1452
 
  Convenience function for readily creating file filters.
1453
 
 
1454
 
  Given a long name for a file filter and a regular expression, return
1455
 
  a file filter string suitable for use in a QFileDialog::OpenFiles()
1456
 
  call.  The regular express, glob, will have both all lower and upper
1457
 
  case versions added.
1458
 
 
1459
 
*/
1460
 
static QString createFileFilter_(QString const &longName, QString const &glob)
1461
 
{
1462
 
  return longName + " (" + glob.lower() + " " + glob.upper() + ");;";
1463
 
}                               // createFileFilter_
1464
 
 
1465
 
 
1466
 
 
1467
 
/**
1468
 
  Builds the list of file filter strings to later be used by
1469
 
  QgisApp::addLayer()
1470
 
 
1471
 
  We query OGR for a list of supported vector formats; we then build a list
1472
 
  of file filter strings from that list.  We return a string that contains
1473
 
  this list that is suitable for use in a a QFileDialog::getOpenFileNames()
1474
 
  call.
1475
 
 
1476
 
  XXX Most of the file name filters need to be filled in; however we
1477
 
  XXX may want to wait until we've tested each format before committing
1478
 
  XXX them permanently instead of blindly relying on OGR to properly
1479
 
  XXX supply all needed spatial data.
1480
 
 
1481
 
*/
1482
 
static void buildSupportedVectorFileFilter_(QString & fileFilters)
1483
 
{
1484
 
 
1485
 
#ifdef DEPRECATED
1486
 
  static QString myFileFilters;
1487
 
 
1488
 
  // if we've already built the supported vector string, just return what
1489
 
  // we've already built
1490
 
  if ( ! ( myFileFilters.isEmpty() || myFileFilters.isNull() ) )
1491
 
  {
1492
 
    fileFilters = myFileFilters;
1493
 
 
1494
 
    return;
1495
 
  }
1496
 
 
1497
 
  // first get the GDAL driver manager
1498
 
 
1499
 
  OGRSFDriverRegistrar *driverRegistrar = OGRSFDriverRegistrar::GetRegistrar();
1500
 
 
1501
 
  if (!driverRegistrar)
1502
 
  {
1503
 
    QMessageBox::warning(0,tr("OGR Driver Manager"),tr("unable to get OGRDriverManager"));
1504
 
    return;                 // XXX good place to throw exception if we
1505
 
  }                           // XXX decide to do exceptions
1506
 
 
1507
 
  // then iterate through all of the supported drivers, adding the
1508
 
  // corresponding file filter
1509
 
 
1510
 
  OGRSFDriver *driver;          // current driver
1511
 
 
1512
 
  QString driverName;           // current driver name
1513
 
 
1514
 
  // Grind through all the drivers and their respective metadata.
1515
 
  // We'll add a file filter for those drivers that have a file
1516
 
  // extension defined for them; the others, welll, even though
1517
 
  // theoreticaly we can open those files because there exists a
1518
 
  // driver for them, the user will have to use the "All Files" to
1519
 
  // open datasets with no explicitly defined file name extension.
1520
 
#ifdef QGISDEBUG
1521
 
 
1522
 
  std::cerr << "Driver count: " << driverRegistrar->GetDriverCount() << std::endl;
1523
 
#endif
1524
 
 
1525
 
  for (int i = 0; i < driverRegistrar->GetDriverCount(); ++i)
1526
 
  {
1527
 
    driver = driverRegistrar->GetDriver(i);
1528
 
 
1529
 
    Q_CHECK_PTR(driver);
1530
 
 
1531
 
    if (!driver)
1532
 
    {
1533
 
      qWarning("unable to get driver %d", i);
1534
 
      continue;
1535
 
    }
1536
 
 
1537
 
    driverName = driver->GetName();
1538
 
 
1539
 
 
1540
 
 
1541
 
    if (driverName.startsWith("ESRI"))
1542
 
    {
1543
 
      myFileFilters += createFileFilter_("ESRI Shapefiles", "*.shp");
1544
 
    }
1545
 
    else if (driverName.startsWith("UK"))
1546
 
    {
1547
 
      // XXX needs file filter extension
1548
 
    }
1549
 
    else if (driverName.startsWith("SDTS"))
1550
 
    {
1551
 
      myFileFilters += createFileFilter_( "Spatial Data Transfer Standard",
1552
 
          "*catd.ddf" );
1553
 
    }
1554
 
    else if (driverName.startsWith("TIGER"))
1555
 
    {
1556
 
      // XXX needs file filter extension
1557
 
    }
1558
 
    else if (driverName.startsWith("S57"))
1559
 
    {
1560
 
      // XXX needs file filter extension
1561
 
    }
1562
 
    else if (driverName.startsWith("MapInfo"))
1563
 
    {
1564
 
      myFileFilters += createFileFilter_("MapInfo", "*.mif *.tab");
1565
 
      // XXX needs file filter extension
1566
 
    }
1567
 
    else if (driverName.startsWith("DGN"))
1568
 
    {
1569
 
      // XXX needs file filter extension
1570
 
    }
1571
 
    else if (driverName.startsWith("VRT"))
1572
 
    {
1573
 
      // XXX needs file filter extension
1574
 
    }
1575
 
    else if (driverName.startsWith("AVCBin"))
1576
 
    {
1577
 
      // XXX needs file filter extension
1578
 
    }
1579
 
    else if (driverName.startsWith("REC"))
1580
 
    {
1581
 
      // XXX needs file filter extension
1582
 
    }
1583
 
    else if (driverName.startsWith("Memory"))
1584
 
    {
1585
 
      // XXX needs file filter extension
1586
 
    }
1587
 
    else if (driverName.startsWith("Jis"))
1588
 
    {
1589
 
      // XXX needs file filter extension
1590
 
    }
1591
 
    else if (driverName.startsWith("GML"))
1592
 
    {
1593
 
      // XXX not yet supported; post 0.1 release task
1594
 
      myFileFilters += createFileFilter_( "Geography Markup Language",
1595
 
          "*.gml" );
1596
 
    }
1597
 
    else
1598
 
    {
1599
 
      // NOP, we don't know anything about the current driver
1600
 
      // with regards to a proper file filter string
1601
 
      qDebug( "%s:%d unknown driver %s", __FILE__, __LINE__, (const char *)driverName.toLocal8Bit().data() );
1602
 
    }
1603
 
 
1604
 
  }                           // each loaded GDAL driver
1605
 
 
1606
 
  std::cout << myFileFilters.toLocal8Bit().data() << std::endl;
1607
 
 
1608
 
  // can't forget the default case
1609
 
 
1610
 
  myFileFilters += "All files (*.*)";
1611
 
  fileFilters = myFileFilters;
1612
 
 
1613
 
#endif // DEPRECATED
1614
 
 
1615
 
  fileFilters = QgsProviderRegistry::instance()->fileVectorFilters();
1616
 
 
1617
 
}                               // buildSupportedVectorFileFilter_()
1618
 
 
1619
 
 
1620
 
 
1621
 
 
1622
 
/**
1623
 
  Open files, preferring to have the default file selector be the
1624
 
  last one used, if any; also, prefer to start in the last directory
1625
 
  associated with filterName.
1626
 
 
1627
 
  @param filterName the name of the filter; used for persistent store
1628
 
  key
1629
 
  @param filters    the file filters used for QFileDialog
1630
 
 
1631
 
  @param selectedFiles string list of selected files; will be empty
1632
 
  if none selected
1633
 
  @param enc        encoding?
1634
 
  @param title      the title for the dialog
1635
 
  @note
1636
 
 
1637
 
  Stores persistent settings under /UI/.  The sub-keys will be
1638
 
  filterName and filterName + "Dir".
1639
 
 
1640
 
  Opens dialog on last directory associated with the filter name, or
1641
 
  the current working directory if this is the first time invoked
1642
 
  with the current filter name.
1643
 
 
1644
 
*/
1645
 
static void openFilesRememberingFilter_(QString const &filterName, 
1646
 
    QString const &filters, QStringList & selectedFiles, QString& enc, QString &title)
1647
 
{
1648
 
 
1649
 
  bool haveLastUsedFilter = false; // by default, there is no last
1650
 
  // used filter
1651
 
 
1652
 
  QSettings settings;         // where we keep last used filter in
1653
 
  // persistant state
1654
 
 
1655
 
  QString lastUsedFilter = settings.readEntry("/UI/" + filterName,
1656
 
      QString::null,
1657
 
      &haveLastUsedFilter);
1658
 
 
1659
 
  QString lastUsedDir = settings.readEntry("/UI/" + filterName + "Dir",".");
1660
 
 
1661
 
  QString lastUsedEncoding = settings.readEntry("/UI/encoding");
1662
 
 
1663
 
#ifdef QGISDEBUG
1664
 
  std::cerr << "Opening file dialog with filters: " << filters.toLocal8Bit().data() << std::endl;
1665
 
#endif
1666
 
 
1667
 
  QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog(0,
1668
 
      title, lastUsedDir, filters, lastUsedEncoding);
1669
 
 
1670
 
  // allow for selection of more than one file
1671
 
  openFileDialog->setMode(QFileDialog::ExistingFiles);
1672
 
 
1673
 
  if (haveLastUsedFilter)       // set the filter to the last one used
1674
 
  {
1675
 
    openFileDialog->selectFilter(lastUsedFilter);
1676
 
  }
1677
 
 
1678
 
  if (openFileDialog->exec() == QDialog::Accepted)
1679
 
  {
1680
 
    selectedFiles = openFileDialog->selectedFiles();
1681
 
    enc = openFileDialog->encoding();
1682
 
    // Fix by Tim - getting the dirPath from the dialog
1683
 
    // directly truncates the last node in the dir path.
1684
 
    // This is a workaround for that
1685
 
    QString myFirstFileName = selectedFiles.first();
1686
 
    QFileInfo myFI(myFirstFileName);
1687
 
    QString myPath = myFI.dirPath();
1688
 
#ifdef QGISDEBUG
1689
 
    qDebug("Writing last used dir: " + myPath);
1690
 
#endif
1691
 
 
1692
 
    settings.writeEntry("/UI/" + filterName, openFileDialog->selectedFilter());
1693
 
    settings.writeEntry("/UI/" + filterName + "Dir", myPath);
1694
 
    settings.writeEntry("/UI/encoding", openFileDialog->encoding());
1695
 
  }
1696
 
 
1697
 
  delete openFileDialog;
1698
 
}   // openFilesRememberingFilter_
1699
 
 
1700
 
 
1701
 
/**
1702
 
  This method prompts the user for a list of vector filenames with a dialog.
1703
 
 
1704
 
  @todo XXX I'd really like to return false, but can't because this
1705
 
  XXX is for a slot that was defined void; need to fix.
1706
 
  */
1707
 
void QgisApp::addLayer()
1708
 
{
1709
 
  mMapCanvas->freeze();
1710
 
 
1711
 
  QStringList selectedFiles;
1712
 
#ifdef QGISDEBUG
1713
 
  std::cerr << "Vector file filters: " << mVectorFileFilter.toLocal8Bit().data() << std::endl;
1714
 
#endif
1715
 
 
1716
 
  QString enc;
1717
 
  QString title = tr("Open an OGR Supported Vector Layer");
1718
 
  openFilesRememberingFilter_("lastVectorFileFilter", mVectorFileFilter, selectedFiles, enc,
1719
 
      title);
1720
 
  if (selectedFiles.isEmpty())
1721
 
  {
1722
 
    // no files were selected, so just bail
1723
 
    mMapCanvas->freeze(false);
1724
 
 
1725
 
    return;
1726
 
  }
1727
 
 
1728
 
  addLayer(selectedFiles, enc);
1729
 
} // QgisApp::addLayer()
1730
 
 
1731
 
 
1732
 
 
1733
 
 
1734
 
bool QgisApp::addLayer(QFileInfo const & vectorFile)
1735
 
{
1736
 
  // let the user know we're going to possibly be taking a while
1737
 
// Let render() do its own cursor management
1738
 
//  QApplication::setOverrideCursor(Qt::WaitCursor);
1739
 
 
1740
 
  mMapCanvas->freeze();         // XXX why do we do this?
1741
 
 
1742
 
  // create the layer
1743
 
  QgsDebugMsg("completeBaseName is: " + vectorFile.completeBaseName());
1744
 
 
1745
 
  QgsVectorLayer *layer = new QgsVectorLayer(vectorFile.filePath(),
1746
 
      vectorFile.completeBaseName(),
1747
 
      "ogr");
1748
 
  Q_CHECK_PTR( layer );
1749
 
 
1750
 
  if ( ! layer )
1751
 
  {
1752
 
    mMapCanvas->freeze(false);
1753
 
    QApplication::restoreOverrideCursor();
1754
 
 
1755
 
    // XXX insert meaningful whine to the user here
1756
 
    return false;
1757
 
  }
1758
 
 
1759
 
  if (layer->isValid())
1760
 
  {
1761
 
    // init the context menu so it can connect to slots
1762
 
    // in main app
1763
 
    // XXX move to legend::addLayer() layer->initContextMenu(this);
1764
 
 
1765
 
    // XXX What about the rest of these?  Where should they be moved, if at
1766
 
    // XXX all?  Some of this functionality is taken care of in the
1767
 
    // XXX QgsProject::read() (If layers added via that.)
1768
 
 
1769
 
    //add single symbol renderer as default
1770
 
    QgsSingleSymbolRenderer *renderer = new QgsSingleSymbolRenderer(layer->vectorType());
1771
 
 
1772
 
    Q_CHECK_PTR( renderer );
1773
 
 
1774
 
    if ( ! renderer )
1775
 
    {
1776
 
      mMapCanvas->freeze(false);
1777
 
// Let render() do its own cursor management
1778
 
//      QApplication::restoreOverrideCursor();
1779
 
 
1780
 
      // XXX should we also delete the layer?
1781
 
 
1782
 
      // XXX insert meaningful whine to the user here
1783
 
      return false;
1784
 
    }
1785
 
 
1786
 
    layer->setRenderer(renderer);
1787
 
 
1788
 
    // Register this layer with the layers registry
1789
 
    QgsMapLayerRegistry::instance()->addMapLayer(layer);
1790
 
    layer->refreshLegend();
1791
 
 
1792
 
    // connect up any keypresses to be passed tot he layer (e.g. so esc can stop rendering)
1793
 
#ifdef QGISDEBUG
1794
 
    std::cout << " Connecting up maplayers keyPressed event to the QgisApp keyPress signal" << std::endl;
1795
 
#endif
1796
 
    QObject::connect(this,
1797
 
        SIGNAL(keyPressed(QKeyEvent *)),
1798
 
        layer,
1799
 
        SLOT(keyPressed(QKeyEvent* )));
1800
 
 
1801
 
  }
1802
 
  else
1803
 
  {
1804
 
    QString msg = vectorFile.completeBaseName() + " ";
1805
 
    msg += tr("is not a valid or recognized data source");
1806
 
    QMessageBox::critical(this, tr("Invalid Data Source"), msg);
1807
 
 
1808
 
    // since the layer is bad, stomp on it
1809
 
    delete layer;
1810
 
 
1811
 
    mMapCanvas->freeze(false);
1812
 
 
1813
 
// Let render() do its own cursor management
1814
 
//    QApplication::restoreOverrideCursor();
1815
 
 
1816
 
    return false;
1817
 
  }
1818
 
 
1819
 
  mMapCanvas->freeze(false);
1820
 
  // mMapLegend->update(); NOW UPDATED VIA SIGNAL/SLOT
1821
 
  qApp->processEvents();       // XXX why does this need to be called manually?
1822
 
  
1823
 
  mMapCanvas->refresh();
1824
 
 
1825
 
// Let render() do its own cursor management
1826
 
//  QApplication::restoreOverrideCursor();
1827
 
 
1828
 
  statusBar()->message(mMapCanvas->extent().stringRep(2));
1829
 
 
1830
 
  return true;
1831
 
 
1832
 
} // QgisApp::addLayer()
1833
 
 
1834
 
 
1835
 
 
1836
 
 
1837
 
 
1838
 
/** \brief overloaded vesion of the above method that takes a list of
1839
 
 * filenames instead of prompting user with a dialog.
1840
 
 
1841
 
 XXX yah know, this could be changed to just iteratively call the above
1842
 
 
1843
 
*/
1844
 
bool QgisApp::addLayer(QStringList const &theLayerQStringList, const QString& enc)
1845
 
{
1846
 
  mMapCanvas->freeze();
1847
 
 
1848
 
// Let render() do its own cursor management
1849
 
//  QApplication::setOverrideCursor(Qt::WaitCursor);
1850
 
 
1851
 
  for ( QStringList::ConstIterator it = theLayerQStringList.begin();
1852
 
      it != theLayerQStringList.end();
1853
 
      ++it )
1854
 
  {
1855
 
    QFileInfo fi(*it);
1856
 
    QString base = fi.completeBaseName();
1857
 
 
1858
 
    QgsDebugMsg("completeBaseName: "+base);
1859
 
 
1860
 
    // create the layer
1861
 
 
1862
 
    QgsVectorLayer *layer = new QgsVectorLayer(*it, base, "ogr");
1863
 
    Q_CHECK_PTR( layer );
1864
 
    // set the visibility based on user preference for newly added
1865
 
    // layers
1866
 
    layer->setVisible(mAddedLayersVisible);
1867
 
 
1868
 
    if ( ! layer )
1869
 
    {
1870
 
      mMapCanvas->freeze(false);
1871
 
 
1872
 
// Let render() do its own cursor management
1873
 
//      QApplication::restoreOverrideCursor();
1874
 
 
1875
 
      // XXX insert meaningful whine to the user here
1876
 
      return false;
1877
 
    }
1878
 
 
1879
 
    if (layer->isValid())
1880
 
    {
1881
 
      layer->setProviderEncoding(enc);
1882
 
      // init the context menu so it can connect to slots
1883
 
      // in main app
1884
 
 
1885
 
      // XXX now taken care of in legend layer->initContextMenu(this);
1886
 
 
1887
 
      //add single symbol renderer as default
1888
 
      QgsSingleSymbolRenderer *renderer = new QgsSingleSymbolRenderer(layer->vectorType());
1889
 
 
1890
 
      Q_CHECK_PTR( renderer );
1891
 
 
1892
 
      if ( ! renderer )
1893
 
      {
1894
 
        mMapCanvas->freeze(false);
1895
 
 
1896
 
// Let render() do its own cursor management
1897
 
//        QApplication::restoreOverrideCursor();
1898
 
 
1899
 
        // XXX insert meaningful whine to the user here
1900
 
        return false;
1901
 
      }
1902
 
 
1903
 
      layer->setRenderer(renderer);
1904
 
 
1905
 
      // Register this layer with the layers registry
1906
 
      QgsMapLayerRegistry::instance()->addMapLayer(layer);
1907
 
 
1908
 
      // connect up any keypresses to be passed tot he layer (e.g. so esc can stop rendering)
1909
 
#ifdef QGISDEBUG
1910
 
      std::cout << " Connecting up maplayers keyPressed event to the QgisApp keyPress signal" << std::endl;
1911
 
#endif
1912
 
      QObject::connect(this,
1913
 
          SIGNAL(keyPressed(QKeyEvent *)),
1914
 
          layer,
1915
 
          SLOT(keyPressed(QKeyEvent* )));
1916
 
    }
1917
 
    else
1918
 
    {
1919
 
      QString msg = *it + " ";
1920
 
      msg += tr("is not a valid or recognized data source");
1921
 
      QMessageBox::critical(this, tr("Invalid Data Source"), msg);
1922
 
 
1923
 
      // since the layer is bad, stomp on it
1924
 
      delete layer;
1925
 
 
1926
 
      // XXX should we return false here, or just grind through
1927
 
      // XXX the remaining arguments?
1928
 
    }
1929
 
 
1930
 
  }
1931
 
 
1932
 
  //qApp->processEvents();
1933
 
  // update legend
1934
 
  /*! \todo Need legend scrollview and legenditem classes */
1935
 
  // draw the map
1936
 
 
1937
 
  // mMapLegend->update(); NOW UPDATED VIA SIGNAL/SLOTS
1938
 
  qApp->processEvents();    // XXX why does this need to be called manually?
1939
 
  mMapCanvas->freeze(false);
1940
 
  mMapCanvas->refresh();
1941
 
 
1942
 
// Let render() do its own cursor management
1943
 
//  QApplication::restoreOverrideCursor();
1944
 
 
1945
 
  statusBar()->message(mMapCanvas->extent().stringRep(2));
1946
 
 
1947
 
 
1948
 
  return true;
1949
 
 
1950
 
} // QgisApp::addLayer()
1951
 
 
1952
 
 
1953
 
 
1954
 
/** This helper checks to see whether the filename appears to be a valid vector file name */
1955
 
bool QgisApp::isValidVectorFileName(QString theFileNameQString)
1956
 
{
1957
 
  return (theFileNameQString.lower().endsWith(".shp"));
1958
 
}
1959
 
 
1960
 
/** Overloaded of the above function provided for convenience that takes a qstring pointer */
1961
 
bool QgisApp::isValidVectorFileName(QString * theFileNameQString)
1962
 
{
1963
 
  //dereference and delegate
1964
 
  return isValidVectorFileName(*theFileNameQString);
1965
 
}
1966
 
 
1967
 
#ifndef HAVE_POSTGRESQL
1968
 
void QgisApp::addDatabaseLayer(){}
1969
 
#else
1970
 
void QgisApp::addDatabaseLayer()
1971
 
{
1972
 
  // only supports postgis layers at present
1973
 
 
1974
 
  // show the postgis dialog
1975
 
 
1976
 
  QgsDbSourceSelect *dbs = new QgsDbSourceSelect(this);
1977
 
 
1978
 
  mMapCanvas->freeze();
1979
 
 
1980
 
  if (dbs->exec())
1981
 
  {
1982
 
// Let render() do its own cursor management
1983
 
//    QApplication::setOverrideCursor(Qt::WaitCursor);
1984
 
 
1985
 
 
1986
 
    // repaint the canvas if it was covered by the dialog
1987
 
 
1988
 
    // add files to the map canvas
1989
 
    QStringList tables = dbs->selectedTables();
1990
 
 
1991
 
    QString connInfo = dbs->connInfo();
1992
 
    // for each selected table, connect to the database, parse the WKT geometry,
1993
 
    // and build a cavnasitem for it
1994
 
    // readWKB(connInfo,tables);
1995
 
    QStringList::Iterator it = tables.begin();
1996
 
    while (it != tables.end())
1997
 
    {
1998
 
 
1999
 
      // create the layer
2000
 
      //qWarning("creating layer");
2001
 
      QgsVectorLayer *layer = new QgsVectorLayer(connInfo + " table=" + *it, *it, "postgres");
2002
 
      if (layer->isValid())
2003
 
      {
2004
 
        // set initial visibility based on user preference
2005
 
        layer->setVisible(mAddedLayersVisible);
2006
 
 
2007
 
        // give it a random color
2008
 
        QgsSingleSymbolRenderer *renderer = new QgsSingleSymbolRenderer(layer->vectorType());  // add single symbol renderer as default
2009
 
        layer->setRenderer(renderer);
2010
 
 
2011
 
        // register this layer with the central layers registry
2012
 
        QgsMapLayerRegistry::instance()->addMapLayer(layer);
2013
 
        layer->refreshLegend();
2014
 
 
2015
 
        // connect up any keypresses to be passed tot he layer (e.g. so esc can stop rendering)
2016
 
  #ifdef QGISDEBUG
2017
 
        std::cout << " Connecting up maplayers keyPressed event to the QgisApp keyPress signal" << std::endl;
2018
 
  #endif
2019
 
        QObject::connect(this,
2020
 
            SIGNAL(keyPressed(QKeyEvent *)),
2021
 
            layer,
2022
 
            SLOT(keyPressed(QKeyEvent* )));
2023
 
      }
2024
 
      else
2025
 
      {
2026
 
        std::cerr << (*it).toLocal8Bit().data() << " is an invalid layer - not loaded" << std::endl;
2027
 
        QMessageBox::critical(this, tr("Invalid Layer"), tr("%1 is an invalid layer and cannot be loaded.").arg(*it));
2028
 
        delete layer;
2029
 
      }
2030
 
      //qWarning("incrementing iterator");
2031
 
      ++it;
2032
 
    }
2033
 
    statusBar()->message(mMapCanvas->extent().stringRep(2));
2034
 
  }
2035
 
 
2036
 
  delete dbs;
2037
 
  qApp->processEvents();
2038
 
  mMapCanvas->freeze(false);
2039
 
  mMapCanvas->refresh();
2040
 
 
2041
 
// Let render() do its own cursor management
2042
 
//  QApplication::restoreOverrideCursor();
2043
 
 
2044
 
} // QgisApp::addDatabaseLayer()
2045
 
#endif
2046
 
 
2047
 
void QgisApp::addWmsLayer()
2048
 
{
2049
 
  // Fudge for now
2050
 
 
2051
 
#ifdef QGISDEBUG
2052
 
  std::cout << "QgisApp::addWmsLayer: about to addRasterLayer" << std::endl;
2053
 
#endif
2054
 
 
2055
 
 
2056
 
  QgsServerSourceSelect *wmss = new QgsServerSourceSelect(this);
2057
 
 
2058
 
  mMapCanvas->freeze();
2059
 
 
2060
 
  if (wmss->exec())
2061
 
  {
2062
 
 
2063
 
    addRasterLayer(wmss->connInfo(),
2064
 
        wmss->connName(),
2065
 
        "wms",
2066
 
        wmss->selectedLayers(),
2067
 
        wmss->selectedStylesForSelectedLayers(),
2068
 
        wmss->selectedImageEncoding(),
2069
 
        wmss->selectedCrs(),
2070
 
        wmss->connProxyHost(),
2071
 
        wmss->connProxyPort(),
2072
 
        wmss->connProxyUser(),
2073
 
        wmss->connProxyPass()
2074
 
        );
2075
 
  }
2076
 
}
2077
 
 
2078
 
 
2079
 
 
2080
 
 
2081
 
/// file data representation
2082
 
enum dataType { IS_VECTOR, IS_RASTER, IS_BOGUS };
2083
 
 
2084
 
 
2085
 
 
2086
 
/** returns data type associated with the given QgsProject file DOM node
2087
 
 
2088
 
  The DOM node should represent the state associated with a specific layer.
2089
 
  */
2090
 
static
2091
 
  dataType
2092
 
dataType_( QDomNode & layerNode )
2093
 
{
2094
 
  QString type = layerNode.toElement().attribute( "type" );
2095
 
 
2096
 
  if ( QString::null == type )
2097
 
  {
2098
 
    qDebug( "%s:%d cannot find ``type'' attribute", __FILE__, __LINE__ );
2099
 
 
2100
 
    return IS_BOGUS;
2101
 
  }
2102
 
 
2103
 
  if ( "raster" == type )
2104
 
  {
2105
 
    qDebug( "%s:%d is a raster", __FILE__, __LINE__ );
2106
 
 
2107
 
    return IS_RASTER;
2108
 
  }
2109
 
  else if ( "vector" == type )
2110
 
  {
2111
 
    qDebug( "%s:%d is a vector", __FILE__, __LINE__ );
2112
 
 
2113
 
    return IS_VECTOR;
2114
 
  }
2115
 
 
2116
 
  qDebug( "%s:%d is unknown type %s", __FILE__, __LINE__, (const char *)type.toLocal8Bit().data() );
2117
 
 
2118
 
  return IS_BOGUS;
2119
 
} // dataType_( QDomNode & layerNode )
2120
 
 
2121
 
 
2122
 
/** return the data source for the given layer
2123
 
 
2124
 
  The QDomNode is a QgsProject DOM node corresponding to a map layer state.
2125
 
 
2126
 
  Essentially dumps <datasource> tag.
2127
 
 
2128
 
*/
2129
 
static
2130
 
  QString
2131
 
dataSource_( QDomNode & layerNode )
2132
 
{
2133
 
  QDomNode dataSourceNode = layerNode.namedItem( "datasource" );
2134
 
 
2135
 
  if ( dataSourceNode.isNull() )
2136
 
  {
2137
 
    qDebug( "%s:%d cannot find datasource node", __FILE__, __LINE__ );
2138
 
 
2139
 
    return QString::null;
2140
 
  }
2141
 
 
2142
 
  return dataSourceNode.toElement().text();
2143
 
 
2144
 
} // dataSource_( QDomNode & layerNode )
2145
 
 
2146
 
 
2147
 
 
2148
 
/// the three flavors for data
2149
 
typedef enum { IS_FILE, IS_DATABASE, IS_URL, IS_UNKNOWN } providerType;
2150
 
 
2151
 
 
2152
 
/** return the physical storage type associated with the given layer
2153
 
 
2154
 
  The QDomNode is a QgsProject DOM node corresponding to a map layer state.
2155
 
 
2156
 
  If the <provider> is "ogr", then it's a file type.
2157
 
 
2158
 
  However, if the layer is a raster, then there won't be a <provider> tag.  It
2159
 
  will always have an associated file.
2160
 
 
2161
 
  If the layer doesn't fall into either of the previous two categories, then
2162
 
  it's either a database or URL.  If the <datasource> tag has "url=", then
2163
 
  it's URL based.  If the <datasource> tag has "dbname=">, then the layer data
2164
 
  is in a database.
2165
 
 
2166
 
*/
2167
 
static
2168
 
  providerType
2169
 
providerType_( QDomNode & layerNode )
2170
 
{
2171
 
  // XXX but what about rasters that can be URLs?  _Can_ they be URLs?
2172
 
 
2173
 
  switch( dataType_( layerNode ) )
2174
 
  {
2175
 
    case IS_VECTOR:
2176
 
      {
2177
 
        QString dataSource = dataSource_( layerNode );
2178
 
 
2179
 
#ifdef QGISDEBUG
2180
 
        qDebug( "%s:%d datasource is %s", __FILE__, __LINE__, (const char *)dataSource.toLocal8Bit().data() );
2181
 
#endif
2182
 
        if ( dataSource.contains("host=") )
2183
 
        {
2184
 
          return IS_URL;
2185
 
        }
2186
 
#ifdef HAVE_POSTGRESQL
2187
 
        else if ( dataSource.contains("dbname=") )
2188
 
        {
2189
 
          return IS_DATABASE;
2190
 
        }
2191
 
#endif
2192
 
        // be default, then, this should be a file based layer data source
2193
 
        // XXX is this a reasonable assumption?
2194
 
 
2195
 
        return IS_FILE;
2196
 
      }
2197
 
 
2198
 
    case IS_RASTER:         // rasters are currently only accessed as
2199
 
      // physical files
2200
 
      return IS_FILE;
2201
 
 
2202
 
    default:
2203
 
      qDebug( "%s:%d unknown ``type'' attribute", __FILE__, __LINE__ );
2204
 
  }
2205
 
 
2206
 
  return IS_UNKNOWN;
2207
 
 
2208
 
} // providerType_
2209
 
 
2210
 
 
2211
 
 
2212
 
/** set the <datasource> to the new value
2213
 
*/
2214
 
static
2215
 
  void
2216
 
setDataSource_( QDomNode & layerNode, QString const & dataSource )
2217
 
{
2218
 
  QDomNode dataSourceNode = layerNode.namedItem("datasource");
2219
 
  QDomElement dataSourceElement = dataSourceNode.toElement();
2220
 
  QDomText dataSourceText = dataSourceElement.firstChild().toText();
2221
 
 
2222
 
 
2223
 
#ifdef QGISDEBUG
2224
 
  QString originalDataSource = dataSourceText.data();
2225
 
 
2226
 
  qDebug( "%s:%d datasource changed from %s", __FILE__, __LINE__, (const char *)originalDataSource.toLocal8Bit().data() );
2227
 
#endif
2228
 
 
2229
 
  dataSourceText.setData( dataSource );
2230
 
 
2231
 
#ifdef QGISDEBUG
2232
 
  QString newDataSource = dataSourceText.data();
2233
 
 
2234
 
  qDebug( "%s:%d to %s", __FILE__, __LINE__, (const char *)newDataSource.toLocal8Bit().data() );
2235
 
#endif
2236
 
} // setDataSource_
2237
 
 
2238
 
 
2239
 
 
2240
 
 
2241
 
/** this is used to locate files that have moved or otherwise are missing
2242
 
 
2243
 
*/
2244
 
static
2245
 
  void
2246
 
findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
2247
 
{
2248
 
  // Prepend that file name to the valid file format filter list since it
2249
 
  // makes it easier for the user to not only find the original file, but to
2250
 
  // perhaps find a similar file.
2251
 
 
2252
 
  QFileInfo originalDataSource( dataSource_(layerNode) );
2253
 
 
2254
 
  QString memoryQualifier;    // to differentiate between last raster and
2255
 
  // vector directories
2256
 
 
2257
 
  switch( dataType_( layerNode ) )
2258
 
  {
2259
 
    case IS_VECTOR:
2260
 
      {
2261
 
        memoryQualifier = "lastVectorFileFilter";
2262
 
 
2263
 
        break;
2264
 
      }
2265
 
    case IS_RASTER:
2266
 
      {
2267
 
        memoryQualifier = "lastRasterFileFilter";
2268
 
 
2269
 
        break;
2270
 
      }
2271
 
    default:
2272
 
      qDebug( "%s:%d unable to determine data type", __FILE__, __LINE__ );
2273
 
      return;
2274
 
  }
2275
 
 
2276
 
  // Prepend the original data source base name to make it easier to pick it
2277
 
  // out from a list of other files; however the appropriate filter strings
2278
 
  // for the file type will also be added in case the file name itself has
2279
 
  // changed, too.
2280
 
 
2281
 
  QString myFileFilters = originalDataSource.fileName() + ";;" + fileFilters;
2282
 
 
2283
 
  QStringList selectedFiles;
2284
 
  QString     enc;
2285
 
  QString     title( QObject::trUtf8("Open an OGR Supported Layer") );
2286
 
 
2287
 
  openFilesRememberingFilter_(memoryQualifier,
2288
 
      myFileFilters, 
2289
 
      selectedFiles, 
2290
 
      enc,
2291
 
      title);
2292
 
 
2293
 
  if (selectedFiles.isEmpty())
2294
 
  {
2295
 
    return;
2296
 
  }
2297
 
  else
2298
 
  {
2299
 
    setDataSource_( layerNode, selectedFiles.first() );
2300
 
    if ( ! QgsProject::instance()->read( layerNode ) )
2301
 
    {
2302
 
      qDebug( "%s:%d unable to re-read layer", __FILE__, __LINE__ );
2303
 
    }
2304
 
  }
2305
 
 
2306
 
} // findMissingFile_
2307
 
 
2308
 
 
2309
 
 
2310
 
 
2311
 
/** find relocated data source for the given layer
2312
 
 
2313
 
  This QDom object represents a QgsProject node that maps to a specific layer.
2314
 
 
2315
 
  @param layerNode QDom node containing layer project information
2316
 
 
2317
 
  @todo
2318
 
 
2319
 
  XXX Only implemented for file based layers.  It will need to be extended for
2320
 
  XXX other data source types such as databases.
2321
 
 
2322
 
*/
2323
 
static
2324
 
  void
2325
 
findLayer_( QString const & fileFilters, QDomNode const & constLayerNode ) 
2326
 
{
2327
 
  // XXX actually we could possibly get away with a copy of the node
2328
 
  QDomNode & layerNode = const_cast<QDomNode&>(constLayerNode);
2329
 
 
2330
 
  switch ( providerType_(layerNode) )
2331
 
  {
2332
 
    case IS_FILE:
2333
 
      qDebug( "%s:%d layer is file based", __FILE__, __LINE__ );
2334
 
      findMissingFile_( fileFilters, layerNode );
2335
 
      break;
2336
 
 
2337
 
    case IS_DATABASE:
2338
 
      qDebug( "%s:%d layer is database based", __FILE__, __LINE__ );
2339
 
      break;
2340
 
 
2341
 
    case IS_URL:
2342
 
      qDebug( "%s:%d layer is URL based", __FILE__, __LINE__ );
2343
 
      break;
2344
 
 
2345
 
    case IS_UNKNOWN:
2346
 
      qDebug( "%s:%d layer has an unkown type", __FILE__, __LINE__ );
2347
 
      break;
2348
 
  }
2349
 
 
2350
 
}; // findLayer_
2351
 
 
2352
 
 
2353
 
 
2354
 
 
2355
 
/** find relocated data sources for given layers
2356
 
 
2357
 
  These QDom objects represent QgsProject nodes that map to specific layers.
2358
 
 
2359
 
*/
2360
 
static
2361
 
  void
2362
 
findLayers_( QString const & fileFilters, list<QDomNode> const & layerNodes )
2363
 
{
2364
 
#ifdef QGISDEBUG
2365
 
  const char * fileFiltersC = fileFilters.ascii(); // debugger probe
2366
 
#endif
2367
 
 
2368
 
  for( list<QDomNode>::const_iterator i = layerNodes.begin();
2369
 
      i != layerNodes.end();
2370
 
      ++i )
2371
 
  {
2372
 
    findLayer_( fileFilters, *i );
2373
 
  }
2374
 
 
2375
 
} // findLayers_
2376
 
 
2377
 
 
2378
 
 
2379
 
 
2380
 
 
2381
 
 
2382
 
 
2383
 
void QgisApp::fileExit()
2384
 
{
2385
 
  if (saveDirty() != QMessageBox::Cancel)
2386
 
  {
2387
 
    removeAllLayers();
2388
 
    qApp->exit(0);
2389
 
  }
2390
 
}
2391
 
 
2392
 
 
2393
 
 
2394
 
void QgisApp::fileNew()
2395
 
{
2396
 
  fileNew(TRUE); // prompts whether to save project
2397
 
} // fileNew()
2398
 
 
2399
 
 
2400
 
//as file new but accepts flags to indicate whether we should prompt to save
2401
 
void QgisApp::fileNew(bool thePromptToSaveFlag)
2402
 
2403
 
  if (thePromptToSaveFlag)
2404
 
  {
2405
 
    int answer = saveDirty();
2406
 
 
2407
 
    if (answer == QMessageBox::Cancel)
2408
 
    {
2409
 
      return;
2410
 
    }
2411
 
  }
2412
 
  
2413
 
#ifdef QGISDEBUG
2414
 
    std::cout << "erasing project" << std::endl;
2415
 
#endif
2416
 
  
2417
 
  mMapCanvas->freeze(true);
2418
 
  QgsMapLayerRegistry::instance()->removeAllMapLayers();
2419
 
  mMapCanvas->clear();
2420
 
 
2421
 
  QgsProject* prj = QgsProject::instance();
2422
 
  prj->title( QString::null );
2423
 
  prj->filename( QString::null );
2424
 
  prj->clearProperties(); // why carry over properties from previous projects?
2425
 
  
2426
 
  QSettings settings;
2427
 
  
2428
 
  //set the colour for selections
2429
 
  //the default can be set in qgisoptions 
2430
 
  //use project properties to override the colour on a per project basis
2431
 
  int myRed = settings.value("/qgis/default_selection_color_red",255).toInt();
2432
 
  int myGreen = settings.value("/qgis/default_selection_color_green",255).toInt();
2433
 
  int myBlue = settings.value("/qgis/default_selection_color_blue",0).toInt();
2434
 
  prj->writeEntry("Gui","/SelectionColorRedPart",myRed);
2435
 
  prj->writeEntry("Gui","/SelectionColorGreenPart",myGreen);
2436
 
  prj->writeEntry("Gui","/SelectionColorBluePart",myBlue); 
2437
 
  QgsRenderer::mSelectionColor=QColor(myRed,myGreen,myBlue);
2438
 
 
2439
 
  //set the canvas to the default background colour
2440
 
  //the default can be set in qgisoptions 
2441
 
  //use project properties to override the colour on a per project basis
2442
 
  myRed = settings.value("/qgis/default_canvas_color_red",255).toInt();
2443
 
  myGreen = settings.value("/qgis/default_canvas_color_green",255).toInt();
2444
 
  myBlue = settings.value("/qgis/default_canvas_color_blue",255).toInt();
2445
 
  prj->writeEntry("Gui","/CanvasColorRedPart",myRed);
2446
 
  prj->writeEntry("Gui","/CanvasColorGreenPart",myGreen);
2447
 
  prj->writeEntry("Gui","/CanvasColorBluePart",myBlue);  
2448
 
  mMapCanvas->setCanvasColor(QColor(myRed,myGreen,myBlue));
2449
 
    
2450
 
  prj->dirty(false);
2451
 
 
2452
 
  setTitleBarText_( *this );
2453
 
    
2454
 
#ifdef QGISDEBUG
2455
 
  std::cout << "emiting new project signal" << std::endl ;
2456
 
#endif
2457
 
 
2458
 
  //note by Tim: I did some casual egrepping and this signal doesnt actually
2459
 
  //seem to be connected to anything....why is it here? Just for future needs?
2460
 
  //note by Martin: actually QgsComposer does use it
2461
 
  emit newProject();
2462
 
 
2463
 
  mMapCanvas->freeze(false);
2464
 
  mMapCanvas->refresh();
2465
 
  
2466
 
  //set the projections enabled icon in the status bar
2467
 
  int myProjectionEnabledFlag = prj->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0);
2468
 
  projectionsEnabled(myProjectionEnabledFlag);  
2469
 
  
2470
 
  pan(); // set map tool - panning
2471
 
 
2472
 
} // QgisApp::fileNew(bool thePromptToSaveFlag)
2473
 
 
2474
 
 
2475
 
void QgisApp::newVectorLayer()
2476
 
{
2477
 
 
2478
 
  QGis::WKBTYPE geometrytype;
2479
 
  QString fileformat;
2480
 
 
2481
 
  QgsGeomTypeDialog geomDialog(this);
2482
 
  if(geomDialog.exec()==QDialog::Rejected)
2483
 
  {
2484
 
    return;
2485
 
  }
2486
 
  geometrytype = geomDialog.selectedType();
2487
 
  fileformat = geomDialog.selectedFileFormat();
2488
 
 
2489
 
  std::list<std::pair<QString, QString> > attributes;
2490
 
  geomDialog.attributes(attributes);
2491
 
 
2492
 
  bool haveLastUsedFilter = false; // by default, there is no last
2493
 
  // used filter
2494
 
  QString enc;
2495
 
  QString filename;
2496
 
 
2497
 
  QSettings settings;         // where we keep last used filter in
2498
 
  // persistant state
2499
 
 
2500
 
  QString lastUsedFilter = settings.readEntry("/UI/lastVectorFileFilter",
2501
 
      QString::null,
2502
 
      &haveLastUsedFilter);
2503
 
 
2504
 
  QString lastUsedDir = settings.readEntry("/UI/lastVectorFileFilterDir",
2505
 
      ".");
2506
 
 
2507
 
  QString lastUsedEncoding = settings.readEntry("/UI/encoding");
2508
 
 
2509
 
#ifdef QGISDEBUG
2510
 
 
2511
 
  std::cerr << "Saving vector file dialog without filters: " << std::endl;
2512
 
#endif
2513
 
 
2514
 
  QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog(this,
2515
 
      tr("Save As"), lastUsedDir, "", lastUsedEncoding);
2516
 
 
2517
 
  // allow for selection of more than one file
2518
 
  openFileDialog->setMode(QFileDialog::AnyFile);
2519
 
  openFileDialog->setAcceptMode(QFileDialog::AcceptSave); 
2520
 
  openFileDialog->setConfirmOverwrite( true ); 
2521
 
 
2522
 
  if (haveLastUsedFilter)       // set the filter to the last one used
2523
 
  {
2524
 
    openFileDialog->selectFilter(lastUsedFilter);
2525
 
  }
2526
 
 
2527
 
  if (openFileDialog->exec() != QDialog::Accepted)
2528
 
  {
2529
 
    delete openFileDialog;
2530
 
    return;
2531
 
  }
2532
 
 
2533
 
  filename = openFileDialog->selectedFile();
2534
 
  enc = openFileDialog->encoding();
2535
 
 
2536
 
  // If the file exists, delete it otherwise we'll end up loading that
2537
 
  // file, which can cause problems (e.g., if the file contains
2538
 
  // linestrings, but we're wanting to create points, we'll end up
2539
 
  // with a linestring file).
2540
 
  QFile::remove(filename);
2541
 
 
2542
 
  settings.writeEntry("/UI/lastVectorFileFilter", openFileDialog->selectedFilter());
2543
 
 
2544
 
  settings.writeEntry("/UI/lastVectorFileFilterDir", openFileDialog->directory().absolutePath());
2545
 
  settings.writeEntry("/UI/encoding", openFileDialog->encoding());
2546
 
 
2547
 
  delete openFileDialog;
2548
 
 
2549
 
  //try to create the new layer with OGRProvider instead of QgsVectorFileWriter
2550
 
  QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
2551
 
  QString ogrlib = pReg->library("ogr");
2552
 
  // This var is not used...remove? TS FIXME
2553
 
  const char *cOgrLib = (const char *) ogrlib;
2554
 
  // load the data provider
2555
 
  QLibrary* myLib = new QLibrary((const char *) ogrlib);
2556
 
  bool loaded = myLib->load();
2557
 
  if (loaded)
2558
 
  {
2559
 
#ifdef QGISDEBUG
2560
 
    qWarning("ogr provider loaded");
2561
 
#endif
2562
 
    typedef bool (*createEmptyDataSourceProc)(const QString&, const QString&, const QString&, QGis::WKBTYPE, \
2563
 
        const std::list<std::pair<QString, QString> >&);
2564
 
    createEmptyDataSourceProc createEmptyDataSource=(createEmptyDataSourceProc)myLib->resolve("createEmptyDataSource");
2565
 
    if(createEmptyDataSource)
2566
 
    {
2567
 
      if(geometrytype == QGis::WKBPoint)
2568
 
      {
2569
 
        createEmptyDataSource(filename,fileformat, enc, QGis::WKBPoint, attributes);
2570
 
      }
2571
 
      else if (geometrytype == QGis::WKBLineString)
2572
 
      {
2573
 
        createEmptyDataSource(filename,fileformat, enc, QGis::WKBLineString, attributes);
2574
 
      }
2575
 
      else if(geometrytype == QGis::WKBPolygon)
2576
 
      {
2577
 
        createEmptyDataSource(filename,fileformat, enc, QGis::WKBPolygon, attributes);
2578
 
      }
2579
 
      else
2580
 
      {
2581
 
#ifdef QGISDEBUG
2582
 
        qWarning("QgisApp.cpp: geometry type not recognised");
2583
 
#endif
2584
 
        return;
2585
 
      }
2586
 
    }
2587
 
    else
2588
 
    {
2589
 
#ifdef QGISDEBUG
2590
 
      qWarning("Resolving newEmptyDataSource(...) failed");;
2591
 
#endif
2592
 
    }
2593
 
  }
2594
 
 
2595
 
  //then add the layer to the view
2596
 
  QStringList filelist;
2597
 
  filelist.append(filename);
2598
 
  addLayer(filelist, enc);
2599
 
  return;
2600
 
}
2601
 
 
2602
 
void QgisApp::fileOpen()
2603
 
{
2604
 
  // possibly save any pending work before opening a new project
2605
 
  int answer = saveDirty();
2606
 
 
2607
 
  if (answer != QMessageBox::Cancel)
2608
 
  {
2609
 
    // Retrieve last used project dir from persistent settings
2610
 
    QSettings settings;
2611
 
    QString lastUsedDir = settings.readEntry("/UI/lastProjectDir", ".");
2612
 
 
2613
 
    QFileDialog * openFileDialog = new QFileDialog(this,
2614
 
        tr("Choose a QGIS project file to open"),
2615
 
        lastUsedDir, QObject::tr("QGis files (*.qgs)"));
2616
 
    openFileDialog->setMode(QFileDialog::ExistingFile);
2617
 
 
2618
 
 
2619
 
    QString fullPath;
2620
 
    if (openFileDialog->exec() == QDialog::Accepted)
2621
 
    {
2622
 
      // Fix by Tim - getting the dirPath from the dialog
2623
 
      // directly truncates the last node in the dir path.
2624
 
      // This is a workaround for that
2625
 
      fullPath = openFileDialog->selectedFile();
2626
 
      QFileInfo myFI(fullPath);
2627
 
      QString myPath = myFI.dirPath();
2628
 
      // Persist last used project dir
2629
 
      settings.writeEntry("/UI/lastProjectDir", myPath);
2630
 
    }
2631
 
    else 
2632
 
    {
2633
 
      // if they didn't select anything, just return
2634
 
      delete openFileDialog;
2635
 
      return;
2636
 
    }
2637
 
 
2638
 
    delete openFileDialog;
2639
 
 
2640
 
    // clear out any stuff from previous project
2641
 
    removeAllLayers();
2642
 
 
2643
 
    QgsProject::instance()->filename( fullPath );
2644
 
 
2645
 
    try 
2646
 
    {
2647
 
      if ( QgsProject::instance()->read() )
2648
 
      {
2649
 
        setTitleBarText_( *this );
2650
 
        mMapCanvas->setMapUnits(QgsProject::instance()->mapUnits());
2651
 
        emit projectRead();     // let plug-ins know that we've read in a new
2652
 
        // project so that they can check any project
2653
 
        // specific plug-in state
2654
 
 
2655
 
        // add this to the list of recently used project files
2656
 
        saveRecentProjectPath(fullPath, settings);
2657
 
      }
2658
 
    }
2659
 
    catch ( QgsProjectBadLayerException & e )
2660
 
    {
2661
 
      QMessageBox::critical(this, 
2662
 
          tr("QGIS Project Read Error"), 
2663
 
          tr("") + "\n" + QString::fromLocal8Bit( e.what() ) );
2664
 
      qDebug( "%s:%d %d bad layers found", __FILE__, __LINE__, e.layers().size() );
2665
 
 
2666
 
      // attempt to find the new locations for missing layers
2667
 
      // XXX vector file hard-coded -- but what if it's raster?
2668
 
      findLayers_( mVectorFileFilter, e.layers() );
2669
 
    }
2670
 
    catch ( std::exception & e )
2671
 
    {
2672
 
      QMessageBox::critical(this, 
2673
 
          tr("QGIS Project Read Error"), 
2674
 
          tr("") + "\n" + QString::fromLocal8Bit( e.what() ) );
2675
 
      qDebug( "%s:%d BAD LAYERS FOUND", __FILE__, __LINE__ );
2676
 
    }
2677
 
  }
2678
 
  //loop through all layers in the layers registry and connect up 
2679
 
  // keybindings for the escape key
2680
 
  std::map<QString, QgsMapLayer *> myMapLayers 
2681
 
    = QgsMapLayerRegistry::instance()->mapLayers();
2682
 
  std::map<QString, QgsMapLayer *>::iterator myMapIterator;
2683
 
  for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator )
2684
 
  {
2685
 
 
2686
 
    QgsMapLayer * myMapLayer = myMapIterator->second;
2687
 
    QObject::connect(this,
2688
 
        SIGNAL(keyPressed(QKeyEvent *)),
2689
 
        myMapLayer,
2690
 
        SLOT(keyPressed(QKeyEvent* )));
2691
 
  }
2692
 
 
2693
 
  //set the projections enabled icon in the status bar
2694
 
  int myProjectionEnabledFlag =
2695
 
    QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0);
2696
 
  projectionsEnabled(myProjectionEnabledFlag);
2697
 
} // QgisApp::fileOpen
2698
 
 
2699
 
 
2700
 
 
2701
 
/**
2702
 
  adds a saved project to qgis, usually called on startup by specifying a
2703
 
  project file on the command line
2704
 
  */
2705
 
bool QgisApp::addProject(QString projectFile)
2706
 
{
2707
 
  mMapCanvas->freeze(true);
2708
 
 
2709
 
  // clear the map canvas
2710
 
  removeAllLayers();
2711
 
 
2712
 
  try
2713
 
  {
2714
 
    if ( QgsProject::instance()->read( projectFile ) )
2715
 
    {
2716
 
      setTitleBarText_( *this );
2717
 
      int  myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
2718
 
      int  myGreenInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorGreenPart",255);
2719
 
      int  myBlueInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorBluePart",255);
2720
 
      QColor myColor = QColor(myRedInt,myGreenInt,myBlueInt);
2721
 
      mMapCanvas->setCanvasColor(myColor); //this is fill colour before rendering starts
2722
 
      qDebug("Canvas background color restored...");
2723
 
 
2724
 
      emit projectRead(); // let plug-ins know that we've read in a new
2725
 
      // project so that they can check any project
2726
 
      // specific plug-in state
2727
 
 
2728
 
      // add this to the list of recently used project files
2729
 
      QSettings settings;
2730
 
      saveRecentProjectPath(projectFile, settings);
2731
 
    }
2732
 
    else
2733
 
    {
2734
 
      mMapCanvas->freeze(false);
2735
 
      mMapCanvas->refresh();
2736
 
      return false;
2737
 
    }
2738
 
  }
2739
 
  catch ( QgsProjectBadLayerException & e )
2740
 
  {
2741
 
    qDebug( "%s:%d %d bad layers found", __FILE__, __LINE__, e.layers().size() );
2742
 
 
2743
 
    if ( QMessageBox::Yes == QMessageBox::critical( this, 
2744
 
          tr("QGIS Project Read Error"), 
2745
 
          tr("") + "\n" + QString::fromLocal8Bit( e.what() ) + "\n" +
2746
 
          tr("Try to find missing layers?"),
2747
 
          QMessageBox::Yes | QMessageBox::Default, 
2748
 
          QMessageBox::No  | QMessageBox::Escape ) )
2749
 
    {
2750
 
      qDebug( "%s:%d want to find missing layers is true", __FILE__, __LINE__ );
2751
 
 
2752
 
      // attempt to find the new locations for missing layers
2753
 
      // XXX vector file hard-coded -- but what if it's raster?
2754
 
      findLayers_( mVectorFileFilter, e.layers() );
2755
 
    }
2756
 
 
2757
 
  }
2758
 
  catch ( std::exception & e )
2759
 
  {
2760
 
    qDebug( "%s:%d BAD LAYERS FOUND", __FILE__, __LINE__ );
2761
 
 
2762
 
    QMessageBox::critical( 0x0, 
2763
 
        tr("Unable to open project"), QString::fromLocal8Bit( e.what() ), QMessageBox::Ok, 
2764
 
        Qt::NoButton );
2765
 
 
2766
 
    mMapCanvas->freeze(false);
2767
 
    mMapCanvas->refresh();
2768
 
    return false;
2769
 
  }
2770
 
 
2771
 
  mMapCanvas->freeze(false);
2772
 
  mMapCanvas->refresh();
2773
 
  return true;
2774
 
} // QgisApp::addProject(QString projectFile)
2775
 
 
2776
 
 
2777
 
 
2778
 
bool QgisApp::fileSave()
2779
 
{
2780
 
  // if we don't have a filename, then obviously we need to get one; note
2781
 
  // that the project file name is reset to null in fileNew()
2782
 
  QFileInfo fullPath;
2783
 
 
2784
 
  // we need to remember if this is a new project so that we know to later
2785
 
  // update the "last project dir" settings; we know it's a new project if
2786
 
  // the current project file name is empty
2787
 
  bool isNewProject = false;
2788
 
 
2789
 
  if ( QgsProject::instance()->filename().isNull() )
2790
 
  {
2791
 
    isNewProject = true;
2792
 
 
2793
 
    // Retrieve last used project dir from persistent settings
2794
 
    QSettings settings;
2795
 
    QString lastUsedDir = settings.readEntry("/UI/lastProjectDir", ".");
2796
 
 
2797
 
    std::auto_ptr<QFileDialog> saveFileDialog( new QFileDialog(this,
2798
 
        tr("Choose a QGIS project file"),
2799
 
        lastUsedDir, QObject::tr("QGis files (*.qgs)")) );
2800
 
 
2801
 
    saveFileDialog->setMode(QFileDialog::AnyFile);
2802
 
    saveFileDialog->setAcceptMode(QFileDialog::AcceptSave); 
2803
 
    saveFileDialog->setConfirmOverwrite( true ); 
2804
 
 
2805
 
    if (saveFileDialog->exec() == QDialog::Accepted)
2806
 
    {
2807
 
      fullPath.setFile( saveFileDialog->selectedFile() );
2808
 
    }
2809
 
    else 
2810
 
    {
2811
 
      // if they didn't select anything, just return
2812
 
      // delete saveFileDialog; auto_ptr auto destroys
2813
 
      return false;
2814
 
    }
2815
 
 
2816
 
    // make sure we have the .qgs extension in the file name
2817
 
    if( "qgs" != fullPath.extension( false ) )
2818
 
    {
2819
 
      QString newFilePath = fullPath.filePath() + ".qgs";
2820
 
#ifdef QGISDEBUG
2821
 
      const char* filePathStr = newFilePath.ascii(); // debugger probe
2822
 
#endif
2823
 
      fullPath.setFile( newFilePath );
2824
 
    }
2825
 
 
2826
 
 
2827
 
#ifdef QGISDEBUG
2828
 
    const char* filePathStr = fullPath.filePath().ascii(); // debugger probe
2829
 
#endif
2830
 
    QgsProject::instance()->filename( fullPath.filePath() );
2831
 
  }
2832
 
 
2833
 
  try
2834
 
  {
2835
 
    if ( QgsProject::instance()->write() )
2836
 
    {
2837
 
      setTitleBarText_(*this); // update title bar
2838
 
      statusBar()->message(tr("Saved project to:") + " " + QgsProject::instance()->filename() );
2839
 
 
2840
 
      if (isNewProject)
2841
 
      {
2842
 
        // add this to the list of recently used project files
2843
 
        QSettings settings;
2844
 
        saveRecentProjectPath(fullPath.filePath(), settings);
2845
 
      }
2846
 
    }
2847
 
    else
2848
 
    {
2849
 
      QMessageBox::critical(this,
2850
 
          tr("Unable to save project"),
2851
 
          tr("Unable to save project to ") + QgsProject::instance()->filename() );
2852
 
    }
2853
 
  }
2854
 
  catch ( std::exception & e )
2855
 
  {
2856
 
    QMessageBox::critical( 0x0,
2857
 
        tr("Unable to save project ") + QgsProject::instance()->filename(),
2858
 
        QString::fromLocal8Bit( e.what() ),
2859
 
        QMessageBox::Ok,
2860
 
        Qt::NoButton );
2861
 
 
2862
 
  }
2863
 
  return true;
2864
 
} // QgisApp::fileSave
2865
 
 
2866
 
 
2867
 
 
2868
 
void QgisApp::fileSaveAs()
2869
 
{
2870
 
  // Retrieve last used project dir from persistent settings
2871
 
  QSettings settings;
2872
 
  QString lastUsedDir = settings.readEntry("/UI/lastProjectDir", ".");
2873
 
 
2874
 
  auto_ptr<QFileDialog> saveFileDialog( new QFileDialog(this,
2875
 
      tr("Choose a filename to save the QGIS project file as"),
2876
 
      lastUsedDir, QObject::tr("QGis files (*.qgs)")) );
2877
 
 
2878
 
  saveFileDialog->setMode(QFileDialog::AnyFile);
2879
 
 
2880
 
  saveFileDialog->setAcceptMode(QFileDialog::AcceptSave);
2881
 
 
2882
 
  saveFileDialog->setConfirmOverwrite( true );
2883
 
 
2884
 
  // if we don't have a filename, then obviously we need to get one; note
2885
 
  // that the project file name is reset to null in fileNew()
2886
 
  QFileInfo fullPath;
2887
 
 
2888
 
  if (saveFileDialog->exec() == QDialog::Accepted)
2889
 
  {
2890
 
    // Fix by Tim - getting the dirPath from the dialog
2891
 
    // directly truncates the last node in the dir path.
2892
 
    // This is a workaround for that
2893
 
    fullPath.setFile(saveFileDialog->selectedFile());
2894
 
    QString myPath = fullPath.dirPath();
2895
 
    // Persist last used project dir
2896
 
    settings.writeEntry("/UI/lastProjectDir", myPath);
2897
 
  } 
2898
 
  else
2899
 
  {
2900
 
    // if they didn't select anything, just return
2901
 
    // delete saveFileDialog; auto_ptr auto deletes
2902
 
    return;
2903
 
  }
2904
 
 
2905
 
  // make sure the .qgs extension is included in the path name. if not, add it...
2906
 
  if( "qgs" != fullPath.extension( false ) )
2907
 
  {
2908
 
    QString newFilePath = fullPath.filePath() + ".qgs";
2909
 
#ifdef QGISDEBUG
2910
 
    const char* filePathStr = newFilePath.ascii(); // debugger probe
2911
 
#endif
2912
 
    fullPath.setFile( newFilePath );
2913
 
  }
2914
 
 
2915
 
  try
2916
 
  {
2917
 
    QgsProject::instance()->filename( fullPath.filePath() );
2918
 
 
2919
 
    if ( QgsProject::instance()->write() )
2920
 
    {
2921
 
      setTitleBarText_(*this); // update title bar
2922
 
      statusBar()->message(tr("Saved project to:") + " " + QgsProject::instance()->filename() );
2923
 
      // add this to the list of recently used project files
2924
 
      saveRecentProjectPath(fullPath.filePath(), settings);
2925
 
    }
2926
 
    else
2927
 
    {
2928
 
      QMessageBox::critical(this,
2929
 
          tr("Unable to save project"),
2930
 
          tr("Unable to save project to ") + QgsProject::instance()->filename() );
2931
 
    }
2932
 
  }
2933
 
  catch ( std::exception & e )
2934
 
  {
2935
 
    QMessageBox::critical( 0x0,
2936
 
        tr("Unable to save project ") + QgsProject::instance()->filename(),
2937
 
        QString::fromLocal8Bit( e.what() ),
2938
 
        QMessageBox::Ok,
2939
 
        Qt::NoButton );
2940
 
  }
2941
 
} // QgisApp::fileSaveAs
2942
 
 
2943
 
 
2944
 
 
2945
 
 
2946
 
 
2947
 
 
2948
 
// Open the project file corresponding to the
2949
 
// path at the given index in mRecentProjectPaths
2950
 
void QgisApp::openProject(QAction *action)
2951
 
{
2952
 
 
2953
 
  // possibly save any pending work before opening a different project
2954
 
  QString debugme;
2955
 
  assert(action != NULL);
2956
 
 
2957
 
  debugme = action->text();
2958
 
 
2959
 
  int answer = saveDirty();
2960
 
  if (answer != QMessageBox::Cancel)
2961
 
  {
2962
 
    addProject(debugme);
2963
 
 
2964
 
  }
2965
 
  //set the projections enabled icon in the status bar
2966
 
  int myProjectionEnabledFlag =
2967
 
    QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0);
2968
 
  projectionsEnabled(myProjectionEnabledFlag);
2969
 
 
2970
 
} // QgisApp::openProject
2971
 
 
2972
 
/**
2973
 
  Open the specified project file; prompt to save previous project if necessary.
2974
 
  Used to process a commandline argument or OpenDocument AppleEvent.
2975
 
  */
2976
 
void QgisApp::openProject(const QString & fileName)
2977
 
{
2978
 
  // possibly save any pending work before opening a different project
2979
 
  int answer = saveDirty();
2980
 
 
2981
 
  if (answer != QMessageBox::Cancel)
2982
 
  {
2983
 
    try
2984
 
    {
2985
 
      if ( ! addProject(fileName) )
2986
 
      {
2987
 
#ifdef QGISDEBUG
2988
 
        std::cerr << "unable to load project " << fileName.toLocal8Bit().data() << "\n";
2989
 
#endif
2990
 
      }
2991
 
      else
2992
 
      {
2993
 
      }
2994
 
    }
2995
 
    catch ( QgsIOException & io_exception )
2996
 
    {
2997
 
      QMessageBox::critical( 0x0, 
2998
 
          tr("QGIS: Unable to load project"), 
2999
 
          tr("Unable to load project ") + fileName );
3000
 
    }
3001
 
  }
3002
 
  return ;
3003
 
}
3004
 
 
3005
 
 
3006
 
/**
3007
 
  Open a raster or vector file; ignore other files.
3008
 
  Used to process a commandline argument or OpenDocument AppleEvent.
3009
 
  @returns true if the file is successfully opened
3010
 
  */
3011
 
bool QgisApp::openLayer(const QString & fileName)
3012
 
{
3013
 
  QFileInfo fileInfo(fileName);
3014
 
  // try to load it as raster
3015
 
  bool ok = false;
3016
 
  CPLPushErrorHandler(CPLQuietErrorHandler); 
3017
 
  if (QgsRasterLayer::isValidRasterFileName(fileName))
3018
 
    ok = addRasterLayer(fileInfo, false);
3019
 
  else // nope - try to load it as a shape/ogr
3020
 
    ok = addLayer(fileInfo);
3021
 
  CPLPopErrorHandler();
3022
 
 
3023
 
  if (!ok)
3024
 
  {
3025
 
    // we have no idea what this file is...
3026
 
    std::cout << "Unable to load " << fileName.toLocal8Bit().data() << std::endl;
3027
 
  }
3028
 
 
3029
 
  return ok;
3030
 
}
3031
 
 
3032
 
 
3033
 
/*
3034
 
   void QgisApp::filePrint()
3035
 
   {
3036
 
//
3037
 
//  Warn the user first that priting is experimental still
3038
 
//
3039
 
QString myHeading = "QGIS Printing Support is Experimental";
3040
 
QString myMessage = "Please note that printing only works on A4 landscape at the moment.\n";
3041
 
myMessage += "For other page sizes your mileage may vary.\n";
3042
 
QMessageBox::information( this, tr(myHeading),tr(myMessage) );
3043
 
 
3044
 
QPrinter myQPrinter;
3045
 
if(myQPrinter.setup(this))
3046
 
{
3047
 
#ifdef QGISDEBUG
3048
 
std::cout << ".............................." << std::endl;
3049
 
std::cout << "...........Printing..........." << std::endl;
3050
 
std::cout << ".............................." << std::endl;
3051
 
#endif
3052
 
// Ithought we could just do this:
3053
 
//mMapCanvas->render(&myQPrinter);
3054
 
//but it doesnt work so now we try this....
3055
 
QPaintDeviceMetrics myMetrics( &myQPrinter ); // need width/height of printer surface
3056
 
std::cout << "Print device width: " << myMetrics.width() << std::endl;
3057
 
std::cout << "Print device height: " << myMetrics.height() << std::endl;
3058
 
QPainter myQPainter;
3059
 
myQPainter.begin( &myQPrinter );
3060
 
QPixmap myQPixmap(myMetrics.width(),myMetrics.height());
3061
 
myQPixmap.fill();
3062
 
mMapCanvas->freeze(false);
3063
 
mMapCanvas->setDirty(true);
3064
 
mMapCanvas->render(&myQPixmap);
3065
 
myQPainter.drawPixmap(0,0, myQPixmap);
3066
 
myQPainter.end();
3067
 
}
3068
 
}
3069
 
*/
3070
 
 
3071
 
void QgisApp::filePrint()
3072
 
{
3073
 
  mComposer->open();
3074
 
  mComposer->zoomFull();
3075
 
}
3076
 
 
3077
 
void QgisApp::saveMapAsImage()
3078
 
{
3079
 
  //create a map to hold the QImageIO names and the filter names
3080
 
  //the QImageIO name must be passed to the mapcanvas saveas image function
3081
 
  typedef QMap<QString, QString> FilterMap;
3082
 
  FilterMap myFilterMap;
3083
 
 
3084
 
  //find out the last used filter
3085
 
  QSettings myQSettings;  // where we keep last used filter in persistant state
3086
 
  QString myLastUsedFilter = myQSettings.readEntry("/UI/saveAsImageFilter");
3087
 
  QString myLastUsedDir = myQSettings.readEntry("/UI/lastSaveAsImageDir",".");
3088
 
 
3089
 
 
3090
 
  // get a list of supported output image types
3091
 
  int myCounterInt=0;
3092
 
  QString myFilters;
3093
 
  QList<QByteArray> formats = QPictureIO::outputFormats();
3094
 
  // Workaround for a problem with Qt4 - calls to outputFormats tend
3095
 
  // to return nothing :(
3096
 
  if (formats.count() == 0)
3097
 
  {
3098
 
    formats.append("png");
3099
 
    formats.append("jpg");
3100
 
  }
3101
 
 
3102
 
  for ( ; myCounterInt < formats.count(); myCounterInt++ )
3103
 
  {
3104
 
    QString myFormat=QString(formats.at( myCounterInt ));
3105
 
    QString myFilter = createFileFilter_(myFormat + " format", "*."+myFormat);
3106
 
    myFilters += myFilter;
3107
 
    myFilterMap[myFilter] = myFormat;
3108
 
  }
3109
 
#ifdef QGISDEBUG
3110
 
  std::cout << "Available Filters Map: " << std::endl;
3111
 
  FilterMap::Iterator myIterator;
3112
 
  for ( myIterator = myFilterMap.begin(); myIterator != myFilterMap.end(); ++myIterator )
3113
 
  {
3114
 
    std::cout << myIterator.key().toLocal8Bit().data() << "  :  " << myIterator.data().toLocal8Bit().data() << std::endl;
3115
 
  }
3116
 
 
3117
 
#endif
3118
 
 
3119
 
  //create a file dialog using the the filter list generated above
3120
 
  std::auto_ptr < QFileDialog > myQFileDialog( new QFileDialog(this,
3121
 
      tr("Choose a filename to save the map image as"),
3122
 
      myLastUsedDir, myFilters) );
3123
 
 
3124
 
  // allow for selection of more than one file
3125
 
  myQFileDialog->setMode(QFileDialog::AnyFile);
3126
 
 
3127
 
  myQFileDialog->setAcceptMode(QFileDialog::AcceptSave);
3128
 
 
3129
 
  myQFileDialog->setConfirmOverwrite( true );
3130
 
 
3131
 
 
3132
 
  if (!myLastUsedFilter.isEmpty())       // set the filter to the last one used
3133
 
  {
3134
 
    myQFileDialog->selectFilter(myLastUsedFilter);
3135
 
  }
3136
 
 
3137
 
 
3138
 
  //prompt the user for a filename
3139
 
  QString myOutputFileNameQString; // = myQFileDialog->getSaveFileName(); //delete this
3140
 
  if (myQFileDialog->exec() == QDialog::Accepted)
3141
 
  {
3142
 
    myOutputFileNameQString = myQFileDialog->selectedFile();
3143
 
  }
3144
 
 
3145
 
  QString myFilterString = myQFileDialog->selectedFilter()+";;";
3146
 
#ifdef QGISDEBUG
3147
 
 
3148
 
  std::cout << "Selected filter: " << myFilterString.toLocal8Bit().data() << std::endl;
3149
 
  std::cout << "Image type to be passed to mapcanvas: " << (myFilterMap[myFilterString]).toLocal8Bit().data() << std::endl;
3150
 
#endif
3151
 
 
3152
 
  // Add the file type suffix to the filename if required
3153
 
  if (!myOutputFileNameQString.endsWith(myFilterMap[myFilterString]))
3154
 
  {
3155
 
    myOutputFileNameQString += "." + myFilterMap[myFilterString];
3156
 
  }
3157
 
 
3158
 
  myQSettings.writeEntry("/UI/lastSaveAsImageFilter" , myFilterString);
3159
 
  myQSettings.writeEntry("/UI/lastSaveAsImageDir", myQFileDialog->directory().absolutePath());
3160
 
 
3161
 
  if ( myOutputFileNameQString !="")
3162
 
  {
3163
 
 
3164
 
    //save the mapview to the selected file
3165
 
    mMapCanvas->saveAsImage(myOutputFileNameQString,NULL,myFilterMap[myFilterString]);
3166
 
    statusBar()->message(tr("Saved map image to") + " " + myOutputFileNameQString);
3167
 
  }
3168
 
 
3169
 
} // saveMapAsImage
3170
 
 
3171
 
 
3172
 
 
3173
 
//overloaded version of the above function
3174
 
void QgisApp::saveMapAsImage(QString theImageFileNameQString, QPixmap * theQPixmap)
3175
 
{
3176
 
  if ( theImageFileNameQString=="")
3177
 
  {
3178
 
    //no filename chosen
3179
 
    return;
3180
 
  }
3181
 
  else
3182
 
  {
3183
 
    //force the size of the canvase
3184
 
    mMapCanvas->resize(theQPixmap->width(), theQPixmap->height());
3185
 
    //save the mapview to the selected file
3186
 
    mMapCanvas->saveAsImage(theImageFileNameQString,theQPixmap);
3187
 
  }
3188
 
} // saveMapAsImage
3189
 
 
3190
 
 
3191
 
//reimplements method from base (gui) class
3192
 
void QgisApp::addAllToOverview()
3193
 
{
3194
 
  std::map<QString, QgsMapLayer *> myMapLayers = QgsMapLayerRegistry::instance()->mapLayers();
3195
 
  std::map<QString, QgsMapLayer *>::iterator myMapIterator;
3196
 
  for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator )
3197
 
  {
3198
 
    QgsMapLayer * myMapLayer = myMapIterator->second;
3199
 
    myMapLayer->inOverview(true); // won't do anything if already in overview
3200
 
  }
3201
 
  mMapCanvas->updateOverview();
3202
 
  
3203
 
  // notify the project we've made a change
3204
 
  QgsProject::instance()->dirty(true);
3205
 
}
3206
 
 
3207
 
//reimplements method from base (gui) class
3208
 
void QgisApp::removeAllFromOverview()
3209
 
{
3210
 
  std::map<QString, QgsMapLayer *> myMapLayers = QgsMapLayerRegistry::instance()->mapLayers();
3211
 
  std::map<QString, QgsMapLayer *>::iterator myMapIterator;
3212
 
  for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator )
3213
 
  {
3214
 
    QgsMapLayer * myMapLayer = myMapIterator->second;
3215
 
    myMapLayer->inOverview(false);
3216
 
  }
3217
 
  mMapCanvas->updateOverview();
3218
 
  
3219
 
  // notify the project we've made a change
3220
 
  QgsProject::instance()->dirty(true);
3221
 
} // QgisApp::removeAllFromOverview()
3222
 
 
3223
 
 
3224
 
//reimplements method from base (gui) class
3225
 
void QgisApp::hideAllLayers()
3226
 
{
3227
 
#ifdef QGISDEBUG
3228
 
  std::cout << "hiding all layers!" << std::endl;
3229
 
#endif
3230
 
 
3231
 
  legend()->selectAll(false);
3232
 
 
3233
 
  // notify the project we've made a change
3234
 
  QgsProject::instance()->dirty(true);
3235
 
}
3236
 
 
3237
 
 
3238
 
// reimplements method from base (gui) class
3239
 
void QgisApp::showAllLayers()
3240
 
{
3241
 
#ifdef QGISDEBUG
3242
 
  std::cout << "Showing all layers!" << std::endl;
3243
 
#endif
3244
 
 
3245
 
  legend()->selectAll(true);
3246
 
 
3247
 
  // notify the project we've made a change
3248
 
  QgsProject::instance()->dirty(true);
3249
 
}
3250
 
 
3251
 
void QgisApp::exportMapServer()
3252
 
{
3253
 
  // check to see if there are any layers to export
3254
 
  // Possibly we may reinstate this in the future if we provide 'active project' export again
3255
 
  //if (mMapCanvas->layerCount() > 0)
3256
 
  //{
3257
 
    QString myMSExportPath = QgsApplication::msexportAppPath(); 
3258
 
    QProcess *process = new QProcess;
3259
 
#ifdef WIN32
3260
 
    // quote the application path on windows
3261
 
    myMSExportPath = QString("\"") + myMSExportPath + QString("\"");
3262
 
#endif
3263
 
    process->start(myMSExportPath);
3264
 
 
3265
 
    // Delete this object if the process terminates
3266
 
    connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), 
3267
 
        SLOT(processExited()));
3268
 
 
3269
 
    // Delete the process if the application quits
3270
 
    connect(qApp, SIGNAL(aboutToQuit()), process, SLOT(terminate()));
3271
 
 
3272
 
  //}
3273
 
  //else
3274
 
  //{
3275
 
  //  QMessageBox::warning(this, tr("No Map Layers"),
3276
 
  //      tr("No layers to export. You must add at least one layer to the map in order to export the view."));
3277
 
  //}
3278
 
}
3279
 
 
3280
 
 
3281
 
 
3282
 
void QgisApp::zoomIn()
3283
 
{
3284
 
  QgsDebugMsg ("Setting map tool to zoomIn");
3285
 
  
3286
 
  mMapCanvas->setMapTool(mMapTools.mZoomIn);
3287
 
 
3288
 
  // notify the project we've made a change
3289
 
  QgsProject::instance()->dirty(true);
3290
 
}
3291
 
 
3292
 
 
3293
 
void QgisApp::zoomOut()
3294
 
{
3295
 
  mMapCanvas->setMapTool(mMapTools.mZoomOut);
3296
 
 
3297
 
  // notify the project we've made a change
3298
 
  QgsProject::instance()->dirty(true);
3299
 
}
3300
 
 
3301
 
void QgisApp::zoomToSelected()
3302
 
{
3303
 
  mMapCanvas->zoomToSelected();
3304
 
 
3305
 
  // notify the project we've made a change
3306
 
  QgsProject::instance()->dirty(true);
3307
 
}
3308
 
 
3309
 
void QgisApp::pan()
3310
 
{
3311
 
  mMapCanvas->setMapTool(mMapTools.mPan);
3312
 
}
3313
 
 
3314
 
void QgisApp::zoomFull()
3315
 
{
3316
 
  mMapCanvas->zoomFullExtent();
3317
 
  // notify the project we've made a change
3318
 
  QgsProject::instance()->dirty(true);
3319
 
 
3320
 
}
3321
 
 
3322
 
void QgisApp::zoomPrevious()
3323
 
{
3324
 
  mMapCanvas->zoomPreviousExtent();
3325
 
  // notify the project we've made a change
3326
 
  QgsProject::instance()->dirty(true);
3327
 
 
3328
 
}
3329
 
 
3330
 
void QgisApp::identify()
3331
 
{
3332
 
  mMapCanvas->setMapTool(mMapTools.mIdentify);
3333
 
}
3334
 
 
3335
 
void QgisApp::measure()
3336
 
{
3337
 
  mMapCanvas->setMapTool(mMapTools.mMeasureDist);
3338
 
}
3339
 
 
3340
 
void QgisApp::measureArea()
3341
 
{
3342
 
  mMapCanvas->setMapTool(mMapTools.mMeasureArea);
3343
 
}
3344
 
 
3345
 
 
3346
 
 
3347
 
void QgisApp::attributeTable()
3348
 
{
3349
 
  QgsMapLayer *layer = mMapLegend->currentLayer();
3350
 
  if (layer)
3351
 
  {
3352
 
    layer->table(this);
3353
 
  }
3354
 
  else
3355
 
  {
3356
 
    QMessageBox::information(this, tr("No Layer Selected"),
3357
 
        tr("To open an attribute table, you must select a layer in the legend"));
3358
 
  }
3359
 
}
3360
 
 
3361
 
void QgisApp::deleteSelected()
3362
 
{
3363
 
  QgsMapLayer *layer = mMapLegend->currentLayer();
3364
 
  if(layer)
3365
 
  {
3366
 
    QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>(layer);
3367
 
    if(vlayer)
3368
 
    {
3369
 
      if(!vlayer->deleteSelectedFeatures())
3370
 
      {
3371
 
        QMessageBox::information(this, tr("Problem deleting features"),
3372
 
            tr("A problem occured during deletion of features"));
3373
 
      }
3374
 
    }
3375
 
    else
3376
 
    {
3377
 
      QMessageBox::information(this, tr("No Vector Layer Selected"),
3378
 
          tr("Deleting features only works on vector layers"));
3379
 
    }
3380
 
  }
3381
 
  else
3382
 
  {
3383
 
    QMessageBox::information(this, tr("No Layer Selected"),
3384
 
        tr("To delete features, you must select a vector layer in the legend"));
3385
 
  }
3386
 
 
3387
 
  // notify the project we've made a change
3388
 
  QgsProject::instance()->dirty(true);
3389
 
}
3390
 
 
3391
 
void QgisApp::capturePoint()
3392
 
{
3393
 
  // set current map tool to select
3394
 
  mMapCanvas->setMapTool(mMapTools.mCapturePoint);
3395
 
  
3396
 
  // FIXME: is this still actual or something old that's not used anymore?
3397
 
  //connect(t, SIGNAL(xyClickCoordinates(QgsPoint &)), this, SLOT(showCapturePointCoordinate(QgsPoint &)));
3398
 
}
3399
 
 
3400
 
void QgisApp::captureLine()
3401
 
{
3402
 
  mMapCanvas->setMapTool(mMapTools.mCaptureLine);
3403
 
}
3404
 
 
3405
 
void QgisApp::capturePolygon()
3406
 
{
3407
 
  mMapCanvas->setMapTool(mMapTools.mCapturePolygon);
3408
 
}
3409
 
 
3410
 
void QgisApp::select()
3411
 
{
3412
 
  mMapCanvas->setMapTool(mMapTools.mSelect);
3413
 
}
3414
 
 
3415
 
 
3416
 
void QgisApp::addVertex()
3417
 
{
3418
 
  mMapCanvas->setMapTool(mMapTools.mVertexAdd);
3419
 
  
3420
 
}
3421
 
 
3422
 
void QgisApp::moveVertex()
3423
 
{
3424
 
  mMapCanvas->setMapTool(mMapTools.mVertexMove);
3425
 
}
3426
 
 
3427
 
 
3428
 
void QgisApp::deleteVertex()
3429
 
{
3430
 
  mMapCanvas->setMapTool(mMapTools.mVertexDelete);
3431
 
}
3432
 
 
3433
 
 
3434
 
void QgisApp::editCut(QgsMapLayer * layerContainingSelection)
3435
 
{
3436
 
  QgsMapLayer * selectionLayer = (layerContainingSelection != 0) ?
3437
 
                                 (layerContainingSelection) :
3438
 
                                 (activeLayer());
3439
 
 
3440
 
  if (selectionLayer)
3441
 
  {
3442
 
    // Test for feature support in this layer
3443
 
    QgsVectorLayer* selectionVectorLayer = dynamic_cast<QgsVectorLayer*>(selectionLayer);
3444
 
 
3445
 
    if (selectionVectorLayer != 0)
3446
 
    {
3447
 
      clipboard()->replaceWithCopyOf( *(selectionVectorLayer->selectedFeatures()) );
3448
 
      selectionVectorLayer->deleteSelectedFeatures();
3449
 
    }
3450
 
  }
3451
 
}
3452
 
 
3453
 
 
3454
 
void QgisApp::editCopy(QgsMapLayer * layerContainingSelection)
3455
 
{
3456
 
  QgsMapLayer * selectionLayer = (layerContainingSelection != 0) ?
3457
 
                                 (layerContainingSelection) :
3458
 
                                 (activeLayer());
3459
 
 
3460
 
  if (selectionLayer)
3461
 
  {
3462
 
    // Test for feature support in this layer
3463
 
    QgsVectorLayer* selectionVectorLayer = dynamic_cast<QgsVectorLayer*>(selectionLayer);
3464
 
 
3465
 
    if (selectionVectorLayer != 0)
3466
 
    {
3467
 
      clipboard()->replaceWithCopyOf( *(selectionVectorLayer->selectedFeatures()) );
3468
 
    }
3469
 
  }
3470
 
}
3471
 
 
3472
 
 
3473
 
void QgisApp::editPaste(QgsMapLayer * destinationLayer)
3474
 
{
3475
 
  QgsMapLayer * pasteLayer = (destinationLayer != 0) ?
3476
 
                             (destinationLayer) :
3477
 
                             (activeLayer());
3478
 
 
3479
 
  if (pasteLayer)
3480
 
  {
3481
 
    // Test for feature support in this layer
3482
 
    QgsVectorLayer* pasteVectorLayer = dynamic_cast<QgsVectorLayer*>(pasteLayer);
3483
 
 
3484
 
    if (pasteVectorLayer != 0)
3485
 
    {
3486
 
      pasteVectorLayer->addFeatures( clipboard()->copyOf() );
3487
 
      mMapCanvas->refresh();
3488
 
    }
3489
 
  }
3490
 
}
3491
 
 
3492
 
 
3493
 
void QgisApp::pasteTransformations()
3494
 
{
3495
 
  QgsPasteTransformations *pt = new QgsPasteTransformations();
3496
 
 
3497
 
  mMapCanvas->freeze();
3498
 
 
3499
 
  pt->exec();
3500
 
}
3501
 
 
3502
 
 
3503
 
void QgisApp::refreshMapCanvas()
3504
 
{
3505
 
#ifdef QGISDEBUG
3506
 
  std::cout << "QgisApp:refreshMapCanvas" << std::endl;
3507
 
#endif
3508
 
 
3509
 
  mMapCanvas->refresh();
3510
 
}
3511
 
 
3512
 
void QgisApp::startEditing()
3513
 
{
3514
 
  QgsMapLayer* theLayer = mMapLegend->currentLayer();
3515
 
  if(!theLayer)
3516
 
    {
3517
 
      return;
3518
 
    }
3519
 
  //only vectorlayers can be edited
3520
 
  QgsVectorLayer* theVectorLayer = dynamic_cast<QgsVectorLayer*>(theLayer);
3521
 
  if(!theVectorLayer)
3522
 
    {
3523
 
      return;
3524
 
    }
3525
 
  theVectorLayer->startEditing();
3526
 
}
3527
 
  
3528
 
void QgisApp::stopEditing()
3529
 
{
3530
 
  QgsMapLayer* theLayer = mMapLegend->currentLayer();
3531
 
  if(!theLayer)
3532
 
    {
3533
 
      return;
3534
 
    }
3535
 
  //only vectorlayers can be edited
3536
 
  QgsVectorLayer* theVectorLayer = dynamic_cast<QgsVectorLayer*>(theLayer);
3537
 
  if(!theVectorLayer)
3538
 
    {
3539
 
      return;
3540
 
    }
3541
 
  theVectorLayer->stopEditing();
3542
 
}
3543
 
 
3544
 
void QgisApp::showMouseCoordinate(QgsPoint & p)
3545
 
{
3546
 
  mCoordsLabel->setText(p.stringRep(mMousePrecisionDecimalPlaces));
3547
 
  // Set minimum necessary width
3548
 
  if ( mCoordsLabel->width() > mCoordsLabel->minimumWidth() )
3549
 
  {
3550
 
    mCoordsLabel->setMinimumWidth(mCoordsLabel->width());
3551
 
  }
3552
 
}
3553
 
 
3554
 
void QgisApp::showScale(QString theScale)
3555
 
{
3556
 
  mScaleLabel->setText(theScale);
3557
 
  // Set minimum necessary width
3558
 
  if ( mScaleLabel->width() > mScaleLabel->minimumWidth() )
3559
 
  {
3560
 
    mScaleLabel->setMinimumWidth(mScaleLabel->width());
3561
 
  }
3562
 
}
3563
 
 
3564
 
void QgisApp::testButton()
3565
 
{
3566
 
  /* QgsShapeFileLayer *sfl = new QgsShapeFileLayer("foo");
3567
 
     mMapCanvas->addLayer(sfl); */
3568
 
  //      delete sfl;
3569
 
 
3570
 
}
3571
 
 
3572
 
void QgisApp::menubar_highlighted( int i )
3573
 
{
3574
 
  // used to save us from re-enabling layer menu items every single time the
3575
 
  // user tweaks the layers drop down menu
3576
 
  static bool enabled;
3577
 
 
3578
 
  if ( 6 == i )               // XXX I hate magic numbers; where is '6' defined
3579
 
    // XXX for Layers menu?
3580
 
  {
3581
 
    // first, if there are NO layers, disable everything that assumes we
3582
 
    // have at least one layer loaded
3583
 
    if ( QgsMapLayerRegistry::instance()->mapLayers().empty() )
3584
 
    {
3585
 
      mActionRemoveLayer->setEnabled(false);
3586
 
      mActionRemoveAllFromOverview->setEnabled(false);
3587
 
      mActionInOverview->setEnabled(false);
3588
 
      mActionShowAllLayers->setEnabled(false);
3589
 
      mActionHideAllLayers->setEnabled(false);
3590
 
      mActionOpenTable->setEnabled(false);
3591
 
      mActionLayerProperties->setEnabled(false);
3592
 
 
3593
 
      enabled = false;
3594
 
    }
3595
 
    else
3596
 
    {
3597
 
      if ( ! enabled )
3598
 
      {
3599
 
        mActionRemoveLayer->setEnabled(true);
3600
 
        mActionRemoveAllFromOverview->setEnabled(true);
3601
 
        mActionInOverview->setEnabled(true);
3602
 
        mActionShowAllLayers->setEnabled(true);
3603
 
        mActionHideAllLayers->setEnabled(true);
3604
 
        mActionOpenTable->setEnabled(true);
3605
 
        mActionLayerProperties->setEnabled(true);
3606
 
      }
3607
 
    }
3608
 
  }
3609
 
} // QgisApp::menubar_highlighted( int i )
3610
 
 
3611
 
 
3612
 
 
3613
 
 
3614
 
// toggle overview status
3615
 
void QgisApp::inOverview()
3616
 
{
3617
 
#ifdef QGISDEBUG
3618
 
  std::cout << "QGisApp::inOverview" << std::endl;
3619
 
#endif
3620
 
 
3621
 
  QgsMapLayer* layer = mMapLegend->currentLayer();
3622
 
  if(layer)
3623
 
  {
3624
 
    layer->inOverview( ! layer->showInOverviewStatus() );
3625
 
    mMapCanvas->updateOverview();
3626
 
  }
3627
 
} // QgisApp::inOverview(bool)
3628
 
 
3629
 
 
3630
 
 
3631
 
void QgisApp::removeLayer()
3632
 
{
3633
 
  mMapLegend->legendLayerRemove();
3634
 
}
3635
 
 
3636
 
 
3637
 
void QgisApp::removeAllLayers()
3638
 
{
3639
 
  QgsMapLayerRegistry::instance()->removeAllMapLayers();
3640
 
  mMapCanvas->refresh();
3641
 
} //remove all layers
3642
 
 
3643
 
 
3644
 
void QgisApp::zoomToLayerExtent()
3645
 
{
3646
 
  // zoom only if one or more layers loaded
3647
 
  if(QgsMapLayerRegistry::instance()->count() > 0)
3648
 
  {
3649
 
    QgsMapLayer *layer = mMapLegend->currentLayer();
3650
 
    if(layer)
3651
 
    {
3652
 
      // Check if the layer extent has to be transformed to the map canvas
3653
 
      // coordinate system
3654
 
#ifdef QGISDEBUG
3655
 
      std::cout << "Layer extent is : " << layer->extent() << std::endl;
3656
 
#endif
3657
 
      if (QgsProject::instance()->readNumEntry("SpatialRefSys",
3658
 
                                               "/ProjectionsEnabled",0)!=0)
3659
 
      {
3660
 
        QgsCoordinateTransform *ct = layer->coordinateTransform();
3661
 
        try 
3662
 
        {
3663
 
          QgsRect transformedExtent = ct->transform(layer->extent());
3664
 
          mMapCanvas->setExtent(transformedExtent);
3665
 
#ifdef QGISDEBUG
3666
 
          std::cout << "Canvas extent is : " << transformedExtent 
3667
 
                    << std::endl;
3668
 
#endif
3669
 
        }
3670
 
        catch(QgsCsException &cse)
3671
 
        {
3672
 
#ifdef QGISDEBUG
3673
 
          std::cout << "Caught transform error in zoomToLayerExtent(). "
3674
 
                    << "Setting untransformed extents." << std::endl;
3675
 
#endif  
3676
 
          mMapCanvas->setExtent(layer->extent());
3677
 
        }
3678
 
      }
3679
 
      else
3680
 
      {
3681
 
        mMapCanvas->setExtent(layer->extent());
3682
 
      }
3683
 
      mMapCanvas->refresh();
3684
 
 
3685
 
      // notify the project we've made a change
3686
 
      QgsProject::instance()->dirty(true);
3687
 
    }
3688
 
  }
3689
 
} // QgisApp::zoomToLayerExtent()
3690
 
 
3691
 
 
3692
 
QgisIface *QgisApp::getInterface()
3693
 
{
3694
 
  return mQgisInterface;
3695
 
}
3696
 
 
3697
 
void QgisApp::showPluginManager()
3698
 
{
3699
 
  QgsPluginManager *pm = new QgsPluginManager(this);
3700
 
  if (pm->exec())
3701
 
  {
3702
 
    // load selected plugins
3703
 
    std::vector < QgsPluginItem > pi = pm->getSelectedPlugins();
3704
 
    std::vector < QgsPluginItem >::iterator it = pi.begin();
3705
 
    while (it != pi.end())
3706
 
    {
3707
 
      QgsPluginItem plugin = *it;
3708
 
      loadPlugin(plugin.name(), plugin.description(), plugin.fullPath());
3709
 
      it++;
3710
 
    }
3711
 
  }
3712
 
}
3713
 
 
3714
 
void QgisApp::loadPlugin(QString name, QString description, QString theFullPathName)
3715
 
{
3716
 
  QSettings settings;
3717
 
  // first check to see if its already loaded
3718
 
  QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
3719
 
  QString lib = pRegistry->library(name);
3720
 
  if (lib.length() > 0)
3721
 
  {
3722
 
    // plugin is loaded
3723
 
    // QMessageBox::warning(this, "Already Loaded", description + " is already loaded");
3724
 
  }
3725
 
  else
3726
 
  {
3727
 
    QLibrary *myLib = new QLibrary(theFullPathName);
3728
 
#ifdef QGISDEBUG
3729
 
 
3730
 
    std::cerr << "Library name is " << myLib->library().toLocal8Bit().data() << std::endl;
3731
 
#endif
3732
 
 
3733
 
    bool loaded = myLib->load();
3734
 
    if (loaded)
3735
 
    {
3736
 
#ifdef QGISDEBUG
3737
 
      std::cerr << "Loaded test plugin library" << std::endl;
3738
 
      std::cerr << "Attempting to resolve the classFactory function" << std::endl;
3739
 
#endif
3740
 
 
3741
 
      type_t *pType = (type_t *) myLib->resolve("type");
3742
 
 
3743
 
 
3744
 
      switch (pType())
3745
 
      {
3746
 
        case QgisPlugin::RENDERER:
3747
 
        case QgisPlugin::UI:
3748
 
          {
3749
 
            // UI only -- doesn't use mapcanvas
3750
 
            create_ui *cf = (create_ui *) myLib->resolve("classFactory");
3751
 
            if (cf)
3752
 
            {
3753
 
              QgisPlugin *pl = cf(this, mQgisInterface);
3754
 
              if (pl)
3755
 
              {
3756
 
                pl->initGui();
3757
 
                // add it to the plugin registry
3758
 
                pRegistry->addPlugin(myLib->library(), name, pl);
3759
 
                //add it to the qsettings file [ts]
3760
 
                settings.writeEntry("/Plugins/" + name, true);
3761
 
              }
3762
 
              else
3763
 
              {
3764
 
                // something went wrong
3765
 
                QMessageBox::warning(this, tr("Error Loading Plugin"), tr("There was an error loading %1."));
3766
 
                //disable it to the qsettings file [ts]
3767
 
                settings.writeEntry("/Plugins/" + name, false);
3768
 
              }
3769
 
            }
3770
 
            else
3771
 
            {
3772
 
              //#ifdef QGISDEBUG
3773
 
              std::cerr << "Unable to find the class factory for " << theFullPathName.toLocal8Bit().data() << std::endl;
3774
 
              //#endif
3775
 
            }
3776
 
 
3777
 
          }
3778
 
          break;
3779
 
        case QgisPlugin::MAPLAYER:
3780
 
          {
3781
 
            // Map layer - requires interaction with the canvas
3782
 
            create_it *cf = (create_it *) myLib->resolve("classFactory");
3783
 
            if (cf)
3784
 
            {
3785
 
              QgsMapLayerInterface *pl = cf();
3786
 
              if (pl)
3787
 
              {
3788
 
                // set the main window pointer for the plugin
3789
 
                pl->setQgisMainWindow(this);
3790
 
                pl->initGui();
3791
 
                //add it to the qsettings file [ts]
3792
 
                settings.writeEntry("/Plugins/" + name, true);
3793
 
 
3794
 
              }
3795
 
              else
3796
 
              {
3797
 
                // something went wrong
3798
 
                QMessageBox::warning(this, tr("Error Loading Plugin"), tr("There was an error loading %1."));
3799
 
                //add it to the qsettings file [ts]
3800
 
                settings.writeEntry("/Plugins/" + name, false);
3801
 
              }
3802
 
            }
3803
 
            else
3804
 
            {
3805
 
              //#ifdef QGISDEBUG
3806
 
              std::cerr << "Unable to find the class factory for " << theFullPathName.toLocal8Bit().data() << std::endl;
3807
 
              //#endif
3808
 
            }
3809
 
          }
3810
 
          break;
3811
 
        default:
3812
 
          // type is unknown
3813
 
          //#ifdef QGISDEBUG
3814
 
          std::cerr << "Plugin " << theFullPathName.toLocal8Bit().data() << " did not return a valid type and cannot be loaded" << std::endl;
3815
 
          //#endif
3816
 
          break;
3817
 
      }
3818
 
 
3819
 
      /*  }else{
3820
 
          std::cout << "Unable to find the class factory for " << mFullPathName << std::endl;
3821
 
          } */
3822
 
 
3823
 
  }
3824
 
  else
3825
 
  {
3826
 
    //#ifdef QGISDEBUG
3827
 
    std::cerr << "Failed to load " << theFullPathName.toLocal8Bit().data() << "\n";
3828
 
    //#endif
3829
 
  }
3830
 
  delete myLib;
3831
 
}
3832
 
}
3833
 
void QgisApp::testMapLayerPlugins()
3834
 
{
3835
 
#ifndef WIN32
3836
 
  // map layer plugins live in their own directory (somewhere to be determined)
3837
 
  QDir mlpDir("../plugins/maplayer", "*.so.1.0.0", QDir::Name | QDir::IgnoreCase, QDir::Files);
3838
 
  if (mlpDir.count() == 0)
3839
 
  {
3840
 
    QMessageBox::information(this, tr("No MapLayer Plugins"), tr("No MapLayer plugins in ../plugins/maplayer"));
3841
 
  }
3842
 
  else
3843
 
  {
3844
 
    for (unsigned i = 0; i < mlpDir.count(); i++)
3845
 
    {
3846
 
#ifdef QGISDEBUG
3847
 
      std::cout << "Getting information for plugin: " << mlpDir[i].toLocal8Bit().data() << std::endl;
3848
 
      std::cout << "Attempting to load the plugin using dlopen\n";
3849
 
#endif
3850
 
      //          void *handle = dlopen("../plugins/maplayer/" + mlpDir[i], RTLD_LAZY);
3851
 
      void *handle = dlopen(("../plugins/maplayer/" + mlpDir[i]).toLocal8Bit().data(), RTLD_LAZY | RTLD_GLOBAL );
3852
 
      if (!handle)
3853
 
      {
3854
 
#ifdef QGISDEBUG
3855
 
        std::cout << "Error in dlopen: " << dlerror() << std::endl;
3856
 
#endif
3857
 
 
3858
 
      }
3859
 
      else
3860
 
      {
3861
 
#ifdef QGISDEBUG
3862
 
        std::cout << "dlopen suceeded" << std::endl;
3863
 
#endif
3864
 
 
3865
 
        dlclose(handle);
3866
 
      }
3867
 
 
3868
 
      QLibrary *myLib = new QLibrary("../plugins/maplayer/" + mlpDir[i]);
3869
 
#ifdef QGISDEBUG
3870
 
 
3871
 
      std::cout << "Library name is " << myLib->library().toLocal8Bit().data() << std::endl;
3872
 
#endif
3873
 
 
3874
 
      bool loaded = myLib->load();
3875
 
      if (loaded)
3876
 
      {
3877
 
#ifdef QGISDEBUG
3878
 
        std::cout << "Loaded test plugin library" << std::endl;
3879
 
        std::cout << "Attempting to resolve the classFactory function" << std::endl;
3880
 
#endif
3881
 
 
3882
 
        create_it *cf = (create_it *) myLib->resolve("classFactory");
3883
 
 
3884
 
        if (cf)
3885
 
        {
3886
 
#ifdef QGISDEBUG
3887
 
          std::cout << "Getting pointer to a MapLayerInterface object from the library\n";
3888
 
#endif
3889
 
 
3890
 
          QgsMapLayerInterface *pl = cf();
3891
 
          if (pl)
3892
 
          {
3893
 
#ifdef QGISDEBUG
3894
 
            std::cout << "Instantiated the maplayer test plugin\n";
3895
 
#endif
3896
 
            // set the main window pointer for the plugin
3897
 
            pl->setQgisMainWindow(this);
3898
 
#ifdef QGISDEBUG
3899
 
            //the call to getInt is deprecated and this line should be removed
3900
 
            //std::cout << "getInt returned " << pl->getInt() << " from map layer plugin\n";
3901
 
#endif
3902
 
            // set up the gui
3903
 
            pl->initGui();
3904
 
          }
3905
 
          else
3906
 
          {
3907
 
#ifdef QGISDEBUG
3908
 
            std::cout << "Unable to instantiate the maplayer test plugin\n";
3909
 
#endif
3910
 
 
3911
 
          }
3912
 
        }
3913
 
      }
3914
 
      else
3915
 
      {
3916
 
#ifdef QGISDEBUG
3917
 
        std::cout << "Failed to load " << mlpDir[i].toLocal8Bit().data() << "\n";
3918
 
#endif
3919
 
 
3920
 
      }
3921
 
    }
3922
 
  }
3923
 
#endif //#ifndef WIN32
3924
 
}
3925
 
void QgisApp::testPluginFunctions()
3926
 
{
3927
 
  // test maplayer plugins first
3928
 
  testMapLayerPlugins();
3929
 
  if (false)
3930
 
  {
3931
 
    // try to load plugins from the plugin directory and test each one
3932
 
 
3933
 
    QDir pluginDir("../plugins", "*.so*", QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks);
3934
 
    //pluginDir.setFilter(QDir::Files || QDir::NoSymLinks);
3935
 
    //pluginDir.setNameFilter("*.so*");
3936
 
    if (pluginDir.count() == 0)
3937
 
    {
3938
 
      QMessageBox::information(this, tr("No Plugins"),
3939
 
          tr("No plugins found in ../plugins. To test plugins, start qgis from the src directory"));
3940
 
    }
3941
 
    else
3942
 
    {
3943
 
 
3944
 
      for (unsigned i = 0; i < pluginDir.count(); i++)
3945
 
      {
3946
 
#ifdef QGISDEBUG
3947
 
        std::cout << "Getting information for plugin: " << pluginDir[i].toLocal8Bit().data() << std::endl;
3948
 
#endif
3949
 
 
3950
 
        QLibrary *myLib = new QLibrary("../plugins/" + pluginDir[i]); //"/home/gsherman/development/qgis/plugins/" + pluginDir[i]);
3951
 
#ifdef QGISDEBUG
3952
 
 
3953
 
        std::cout << "Library name is " << myLib->library().toLocal8Bit().data() << std::endl;
3954
 
#endif
3955
 
        //QLibrary myLib("../plugins/" + pluginDir[i]);
3956
 
#ifdef QGISDEBUG
3957
 
 
3958
 
        std::cout << "Attempting to load ../plugins/" << pluginDir[i].toLocal8Bit().data() << std::endl;
3959
 
#endif
3960
 
        /*  void *handle = dlopen("/home/gsherman/development/qgis/plugins/" + pluginDir[i], RTLD_LAZY);
3961
 
            if (!handle) {
3962
 
            std::cout << "Error in dlopen: " <<  dlerror() << std::endl;
3963
 
 
3964
 
            }else{
3965
 
            std::cout << "dlopen suceeded" << std::endl;
3966
 
            dlclose(handle);
3967
 
            }
3968
 
 
3969
 
*/
3970
 
        bool loaded = myLib->load();
3971
 
        if (loaded)
3972
 
        {
3973
 
#ifdef QGISDEBUG
3974
 
          std::cout << "Loaded test plugin library" << std::endl;
3975
 
          std::cout << "Getting the name of the plugin" << std::endl;
3976
 
#endif
3977
 
 
3978
 
          name_t *pName = (name_t *) myLib->resolve("name");
3979
 
          if (pName)
3980
 
          {
3981
 
            QMessageBox::information(this, tr("Name"), tr("Plugin %1 is named %2").arg(pluginDir[i]).arg(pName()));
3982
 
          }
3983
 
#ifdef QGISDEBUG
3984
 
          std::cout << "Attempting to resolve the classFactory function" << std::endl;
3985
 
#endif
3986
 
 
3987
 
          create_t *cf = (create_t *) myLib->resolve("classFactory");
3988
 
 
3989
 
          if (cf)
3990
 
          {
3991
 
#ifdef QGISDEBUG
3992
 
            std::cout << "Getting pointer to a QgisPlugin object from the library\n";
3993
 
#endif
3994
 
 
3995
 
            QgisPlugin *pl = cf(this, mQgisInterface);
3996
 
#ifdef QGISDEBUG
3997
 
 
3998
 
            std::cout << "Displaying name, version, and description\n";
3999
 
            std::cout << "Plugin name: " << pl->name().toLocal8Bit().data() << std::endl;
4000
 
            std::cout << "Plugin version: " << pl->version().toLocal8Bit().data() << std::endl;
4001
 
            std::cout << "Plugin description: " << pl->description().toLocal8Bit().data() << std::endl;
4002
 
#endif
4003
 
 
4004
 
            QMessageBox::information(this, tr("Plugin Information"), tr("QGis loaded the following plugin:") +
4005
 
                tr("Name: %1").arg(pl->name()) + "\n" + tr("Version: %1").arg(pl->version()) + "\n" +
4006
 
                tr("Description: %1").arg(pl->description()));
4007
 
            // unload the plugin (delete it)
4008
 
#ifdef QGISDEBUG
4009
 
 
4010
 
            std::cout << "Attempting to resolve the unload function" << std::endl;
4011
 
#endif
4012
 
            /*
4013
 
               unload_t *ul = (unload_t *) myLib.resolve("unload");
4014
 
               if (ul) {
4015
 
               ul(pl);
4016
 
               std::cout << "Unloaded the plugin\n";
4017
 
               } else {
4018
 
               std::cout << "Unable to resolve unload function. Plugin was not unloaded\n";
4019
 
               }
4020
 
               */
4021
 
          }
4022
 
        }
4023
 
        else
4024
 
        {
4025
 
          QMessageBox::warning(this, tr("Unable to Load Plugin"),
4026
 
              tr("QGIS was unable to load the plugin from: %1").arg(pluginDir[i]));
4027
 
#ifdef QGISDEBUG
4028
 
 
4029
 
          std::cout << "Unable to load library" << std::endl;
4030
 
#endif
4031
 
 
4032
 
        }
4033
 
      }
4034
 
    }
4035
 
  }
4036
 
}
4037
 
 
4038
 
 
4039
 
void QgisApp::checkQgisVersion()
4040
 
{
4041
 
  QApplication::setOverrideCursor(Qt::WaitCursor);
4042
 
  /* QUrlOperator op = new QUrlOperator( "http://mrcc.com/qgis/version.txt" );
4043
 
     connect(op, SIGNAL(data()), SLOT(urlData()));
4044
 
     connect(op, SIGNAL(finished(QNetworkOperation)), SLOT(urlFinished(QNetworkOperation)));
4045
 
 
4046
 
     op.get(); */
4047
 
  mSocket = new QTcpSocket(this);
4048
 
  connect(mSocket, SIGNAL(connected()), SLOT(socketConnected()));
4049
 
  connect(mSocket, SIGNAL(connectionClosed()), SLOT(socketConnectionClosed()));
4050
 
  connect(mSocket, SIGNAL(readyRead()), SLOT(socketReadyRead()));
4051
 
  connect(mSocket, SIGNAL(error(QAbstractSocket::SocketError)), 
4052
 
                   SLOT(socketError(QAbstractSocket::SocketError)));
4053
 
  mSocket->connectToHost("mrcc.com", 80);
4054
 
}
4055
 
 
4056
 
void QgisApp::socketConnected()
4057
 
{
4058
 
  QTextStream os(mSocket);
4059
 
  mVersionMessage = "";
4060
 
  // send the qgis version string
4061
 
  // os << qgisVersion << "\r\n";
4062
 
  os << "GET /qgis/version.txt HTTP/1.0\n\n";
4063
 
 
4064
 
 
4065
 
}
4066
 
 
4067
 
void QgisApp::socketConnectionClosed()
4068
 
{
4069
 
  QApplication::restoreOverrideCursor();
4070
 
  // strip the header
4071
 
  QString contentFlag = "#QGIS Version";
4072
 
  int pos = mVersionMessage.find(contentFlag);
4073
 
  if (pos > -1)
4074
 
  {
4075
 
    pos += contentFlag.length();
4076
 
    /* std::cout << mVersionMessage << "\n ";
4077
 
       std::cout << "Pos is " << pos <<"\n"; */
4078
 
    mVersionMessage = mVersionMessage.mid(pos);
4079
 
    QStringList parts = QStringList::split("|", mVersionMessage);
4080
 
    // check the version from the  server against our version
4081
 
    QString versionInfo;
4082
 
    int currentVersion = parts[0].toInt();
4083
 
    if (currentVersion > QGis::qgisVersionInt)
4084
 
    {
4085
 
      // show version message from server
4086
 
      versionInfo = tr("There is a new version of QGIS available") + "\n";
4087
 
    }
4088
 
    else
4089
 
    {
4090
 
      if (QGis::qgisVersionInt > currentVersion)
4091
 
      {
4092
 
        versionInfo = tr("You are running a development version of QGIS") + "\n";
4093
 
      }
4094
 
      else
4095
 
      {
4096
 
        versionInfo = tr("You are running the current version of QGIS") + "\n";
4097
 
      }
4098
 
    }
4099
 
    if (parts.count() > 1)
4100
 
    {
4101
 
      versionInfo += parts[1] + "\n\n" + tr("Would you like more information?");
4102
 
      ;
4103
 
      int result = QMessageBox::information(this, tr("QGIS Version Information"), versionInfo, tr("Yes"), tr("No"));
4104
 
      if (result == 0)
4105
 
      {
4106
 
        // show more info
4107
 
        QgsMessageViewer *mv = new QgsMessageViewer(this);
4108
 
        mv->setCaption(tr("QGIS - Changes in SVN Since Last Release"));
4109
 
        mv->setMessageAsHtml(parts[2]);
4110
 
        mv->exec();
4111
 
      }
4112
 
    }
4113
 
    else
4114
 
    {
4115
 
      QMessageBox::information(this, tr("QGIS Version Information"), versionInfo);
4116
 
    }
4117
 
  }
4118
 
  else
4119
 
  {
4120
 
    QMessageBox::warning(this, tr("QGIS Version Information"), tr("Unable to get current version information from server"));
4121
 
  }
4122
 
}
4123
 
void QgisApp::socketError(QAbstractSocket::SocketError e)
4124
 
{
4125
 
  if (e == QAbstractSocket::RemoteHostClosedError)
4126
 
    return;
4127
 
 
4128
 
  QApplication::restoreOverrideCursor();
4129
 
  // get error type
4130
 
  QString detail;
4131
 
  switch (e)
4132
 
  {
4133
 
    case QAbstractSocket::ConnectionRefusedError:
4134
 
      detail = tr("Connection refused - server may be down");
4135
 
      break;
4136
 
    case QAbstractSocket::HostNotFoundError:
4137
 
      detail = tr("QGIS server was not found");
4138
 
      break;
4139
 
    case QAbstractSocket::NetworkError:
4140
 
      detail = tr("Network error while communicating with server");
4141
 
      break;
4142
 
    default:
4143
 
      detail = tr("Unknown network socket error");
4144
 
      break;
4145
 
  }
4146
 
 
4147
 
  // show version message from server
4148
 
  QMessageBox::critical(this, tr("QGIS Version Information"), tr("Unable to communicate with QGIS Version server") + "\n" + detail);
4149
 
}
4150
 
 
4151
 
void QgisApp::socketReadyRead()
4152
 
{
4153
 
  while (mSocket->bytesAvailable() > 0)
4154
 
  {
4155
 
    char *data = new char[mSocket->bytesAvailable() + 1];
4156
 
    memset(data, '\0', mSocket->bytesAvailable() + 1);
4157
 
    mSocket->readBlock(data, mSocket->bytesAvailable());
4158
 
    mVersionMessage += data;
4159
 
    delete[]data;
4160
 
  }
4161
 
 
4162
 
}
4163
 
void QgisApp::options()
4164
 
{
4165
 
  QgsOptions *optionsDialog = new QgsOptions(this);
4166
 
  if(optionsDialog->exec())
4167
 
  {
4168
 
    // set the theme if it changed
4169
 
    setTheme(optionsDialog->theme());
4170
 
    // set the visible flag for new layers
4171
 
    mAddedLayersVisible = optionsDialog->newVisible();
4172
 
    QSettings mySettings;
4173
 
    mMapCanvas->enableAntiAliasing(mySettings.value("/qgis/enable_anti_aliasing").toBool());
4174
 
    mMapCanvas->useQImageToRender(mySettings.value("/qgis/use_qimage_to_render").toBool());
4175
 
  
4176
 
    int action = mySettings.value("/qgis/wheel_action", 0).toInt();
4177
 
    double zoomFactor = mySettings.value("/qgis/zoom_factor", 2).toDouble();
4178
 
    mMapCanvas->setWheelAction((QgsMapCanvas::WheelAction) action, zoomFactor);
4179
 
 
4180
 
    bool splitterRedraw = mySettings.value("/qgis/splitterRedraw", true).toBool();
4181
 
    canvasLegendSplit->setOpaqueResize(splitterRedraw);
4182
 
    legendOverviewSplit->setOpaqueResize(splitterRedraw);
4183
 
  }
4184
 
}
4185
 
 
4186
 
void QgisApp::helpContents()
4187
 
{
4188
 
  openURL("index.html");
4189
 
}
4190
 
 
4191
 
void QgisApp::helpQgisHomePage()
4192
 
{
4193
 
  openURL("http://qgis.org", false);
4194
 
}
4195
 
 
4196
 
void QgisApp::openURL(QString url, bool useQgisDocDirectory)
4197
 
{
4198
 
  // open help in user browser
4199
 
  if (useQgisDocDirectory)
4200
 
  {
4201
 
    url = "file://" +QgsApplication::pkgDataPath() + "/doc/" + url;
4202
 
  }
4203
 
#ifdef Q_OS_MACX
4204
 
  /* Use Mac OS X Launch Services which uses the user's default browser
4205
 
   * and will just open a new window if that browser is already running.
4206
 
   * QProcess creates a new browser process for each invocation and expects a
4207
 
   * commandline application rather than a bundled application.
4208
 
   */
4209
 
  CFURLRef urlRef = CFURLCreateWithBytes(kCFAllocatorDefault,
4210
 
      reinterpret_cast<const UInt8*>(url.utf8().data()), url.length(),
4211
 
      kCFStringEncodingUTF8, NULL);
4212
 
  OSStatus status = LSOpenCFURLRef(urlRef, NULL);
4213
 
  CFRelease(urlRef);
4214
 
#else
4215
 
  // find a browser
4216
 
  QSettings settings;
4217
 
  QString browser = settings.readEntry("/qgis/browser");
4218
 
  if (browser.length() == 0)
4219
 
  {
4220
 
    // ask user for browser and use it
4221
 
    bool ok;
4222
 
    QString myHeading = tr("QGIS Browser Selection");
4223
 
    QString myMessage = tr("Enter the name of a web browser to use (eg. konqueror).\n");
4224
 
    myMessage += tr("Enter the full path if the browser is not in your PATH.\n");
4225
 
    myMessage += tr("You can change this option later by selecting Options from the Settings menu (Help Browser tab).");
4226
 
    QString text = QInputDialog::getText(myHeading,
4227
 
        myMessage,
4228
 
        QLineEdit::Normal,
4229
 
        QString::null, &ok, this);
4230
 
    if (ok && !text.isEmpty())
4231
 
    {
4232
 
      // user entered something and pressed OK
4233
 
      browser = text;
4234
 
      // save the setting
4235
 
      settings.writeEntry("/qgis/browser", browser);
4236
 
    }
4237
 
    else
4238
 
    {
4239
 
      browser = "";
4240
 
    }
4241
 
 
4242
 
  }
4243
 
  if (browser.length() > 0)
4244
 
  {
4245
 
    // find the installed location of the help files
4246
 
    // open index.html using browser
4247
 
    //XXX for debug on win32      QMessageBox::information(this,"Help opening...", browser + " - " + url);
4248
 
    QProcess *helpProcess = new QProcess(this);
4249
 
    QStringList myArgs;
4250
 
    myArgs << url;
4251
 
    helpProcess->start(browser,myArgs);
4252
 
  }
4253
 
  /*  mHelpViewer = new QgsHelpViewer(this,"helpviewer",false);
4254
 
      mHelpViewer->showContent(mAppDir +"/share/doc","index.html");
4255
 
      mHelpViewer->show(); */
4256
 
#endif
4257
 
}
4258
 
 
4259
 
/** Get a pointer to the currently selected map layer */
4260
 
QgsMapLayer *QgisApp::activeLayer()
4261
 
{
4262
 
  return (mMapLegend->currentLayer());
4263
 
}
4264
 
 
4265
 
QString QgisApp::activeLayerSource()
4266
 
{
4267
 
  QString source;
4268
 
  QgsMapLayer* layer = mMapLegend->currentLayer();
4269
 
  if(layer)
4270
 
    {
4271
 
      return (layer->source());
4272
 
    }
4273
 
  return "";
4274
 
}
4275
 
 
4276
 
/** Add a vector layer directly without prompting user for location
4277
 
  The caller must provide information compatible with the provider plugin
4278
 
  using the vectorLayerPath and baseName. The provider can use these
4279
 
  parameters in any way necessary to initialize the layer. The baseName
4280
 
  parameter is used in the Map Legend so it should be formed in a meaningful
4281
 
  way.
4282
 
  */
4283
 
void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)
4284
 
{
4285
 
  mMapCanvas->freeze();
4286
 
 
4287
 
// Let render() do its own cursor management
4288
 
//  QApplication::setOverrideCursor(Qt::WaitCursor);
4289
 
 
4290
 
  // create the layer
4291
 
  QgsVectorLayer *layer;
4292
 
  /* Eliminate the need to instantiate the layer based on provider type.
4293
 
     The caller is responsible for cobbling together the needed information to
4294
 
     open the layer
4295
 
     */
4296
 
#ifdef QGISDEBUG
4297
 
 
4298
 
  std::cout << "Creating new vector layer using " <<
4299
 
    vectorLayerPath.toLocal8Bit().data() << " with baseName of " << baseName.toLocal8Bit().data() <<
4300
 
    " and providerKey of " << providerKey.toLocal8Bit().data() << std::endl;
4301
 
#endif
4302
 
 
4303
 
  layer = new QgsVectorLayer(vectorLayerPath, baseName, providerKey);
4304
 
 
4305
 
  if( layer && layer->isValid() )
4306
 
  {
4307
 
    // Register this layer with the layers registry
4308
 
    QgsMapLayerRegistry::instance()->addMapLayer(layer);
4309
 
    // init the context menu so it can connect to slots in main app
4310
 
    // now taken care of in legend layer->initContextMenu(this);
4311
 
 
4312
 
    // give it a random color
4313
 
    QgsSingleSymbolRenderer *renderer = new QgsSingleSymbolRenderer(layer->vectorType());  //add single symbol renderer as default
4314
 
    layer->setRenderer(renderer);
4315
 
    layer->refreshLegend();
4316
 
    // add it to the mapcanvas collection
4317
 
    // mMapCanvas->addLayer(layer); No longer necessary since adding to registry will add to canvas
4318
 
 
4319
 
    // connect up any keypresses to be passed tot he layer (e.g. so esc can stop rendering)
4320
 
#ifdef QGISDEBUG
4321
 
    std::cout << " Connecting up maplayers keyPressed event to the QgisApp keyPress signal" << std::endl;
4322
 
#endif
4323
 
    QObject::connect(this,
4324
 
        SIGNAL(keyPressed(QKeyEvent * )),
4325
 
        layer,
4326
 
        SLOT(keyPressed(QKeyEvent* )));
4327
 
 
4328
 
    QgsProject::instance()->dirty(false); // XXX this might be redundant
4329
 
 
4330
 
    statusBar()->message(mMapCanvas->extent().stringRep(2));
4331
 
 
4332
 
  }
4333
 
  else
4334
 
  {
4335
 
    QMessageBox::critical(this,tr("Layer is not valid"),
4336
 
        tr("The layer is not a valid layer and can not be added to the map"));
4337
 
  }
4338
 
  qApp->processEvents();
4339
 
  mMapCanvas->freeze(false);
4340
 
  mMapCanvas->refresh();
4341
 
 
4342
 
// Let render() do its own cursor management
4343
 
//  QApplication::restoreOverrideCursor();
4344
 
 
4345
 
} // QgisApp::addVectorLayer
4346
 
 
4347
 
 
4348
 
 
4349
 
void QgisApp::addMapLayer(QgsMapLayer *theMapLayer)
4350
 
{
4351
 
  mMapCanvas->freeze();
4352
 
 
4353
 
// Let render() do its own cursor management
4354
 
//  QApplication::setOverrideCursor(Qt::WaitCursor);
4355
 
 
4356
 
  if(theMapLayer->isValid())
4357
 
  {
4358
 
    // Register this layer with the layers registry
4359
 
    QgsMapLayerRegistry::instance()->addMapLayer(theMapLayer);
4360
 
    // init the context menu so it can connect to slots in main app
4361
 
    // XXX now taken care of in legend theMapLayer->initContextMenu(this);
4362
 
    // add it to the mapcanvas collection
4363
 
    // not necessary since adding to registry adds to canvas mMapCanvas->addLayer(theMapLayer);
4364
 
 
4365
 
    statusBar()->message(mMapCanvas->extent().stringRep(2));
4366
 
 
4367
 
  }
4368
 
  else
4369
 
  {
4370
 
    QMessageBox::critical(this,tr("Layer is not valid"),
4371
 
        tr("The layer is not a valid layer and can not be added to the map"));
4372
 
  }
4373
 
  qApp->processEvents();
4374
 
  mMapCanvas->freeze(false);
4375
 
  mMapCanvas->refresh();
4376
 
 
4377
 
// Let render() do its own cursor management
4378
 
//  QApplication::restoreOverrideCursor();
4379
 
 
4380
 
}
4381
 
 
4382
 
void QgisApp::setExtent(QgsRect theRect)
4383
 
{
4384
 
  mMapCanvas->setExtent(theRect);
4385
 
}
4386
 
 
4387
 
 
4388
 
 
4389
 
 
4390
 
int QgisApp::saveDirty()
4391
 
{
4392
 
  int answer = 0;
4393
 
  mMapCanvas->freeze(true);
4394
 
 
4395
 
#ifdef QGISDEBUG
4396
 
 
4397
 
  std::cout << "Layer count is " << mMapCanvas->layerCount() << std::endl;
4398
 
  std::cout << "Project is ";
4399
 
  if ( QgsProject::instance()->dirty() )
4400
 
  {
4401
 
    std::cout << "dirty" << std::endl;
4402
 
  }
4403
 
  else
4404
 
  {
4405
 
    std::cout << "not dirty" << std::endl;
4406
 
  }
4407
 
 
4408
 
  std::cout << "Map canvas is ";
4409
 
  if (mMapCanvas->isDirty())
4410
 
  {
4411
 
    std::cout << "dirty" << std::endl;
4412
 
  }
4413
 
  else
4414
 
  {
4415
 
    std::cout << "not dirty" << std::endl;
4416
 
  }
4417
 
#endif
4418
 
 
4419
 
  if ((QgsProject::instance()->dirty() || (mMapCanvas->isDirty()) && mMapCanvas->layerCount() > 0))
4420
 
  {
4421
 
    // flag project as dirty since dirty state of canvas is reset if "dirty"
4422
 
    // is based on a zoom or pan
4423
 
    QgsProject::instance()->dirty( true );
4424
 
    // old code: mProjectIsDirtyFlag = true;
4425
 
 
4426
 
    // prompt user to save
4427
 
    answer = QMessageBox::information(this, tr("Save?"),
4428
 
        tr("<p>Do you want to save the current project?</p>"),
4429
 
        QMessageBox::Yes | QMessageBox::Default,
4430
 
        QMessageBox::No,
4431
 
        QMessageBox::Cancel | QMessageBox::Escape);
4432
 
    if (QMessageBox::Yes == answer )
4433
 
    {
4434
 
      if (!fileSave())
4435
 
        answer = QMessageBox::Cancel;
4436
 
    }
4437
 
  }
4438
 
 
4439
 
  mMapCanvas->freeze(false);
4440
 
 
4441
 
  return answer;
4442
 
 
4443
 
} // QgisApp::saveDirty()
4444
 
 
4445
 
 
4446
 
void QgisApp::closeEvent(QCloseEvent* event)
4447
 
{
4448
 
  // We'll close in our own good time, thank you very much
4449
 
  event->ignore();
4450
 
  // Do the usual checks and ask if they want to save, etc
4451
 
  fileExit();
4452
 
}
4453
 
 
4454
 
 
4455
 
void QgisApp::whatsThis()
4456
 
{
4457
 
  QWhatsThis::enterWhatsThisMode();
4458
 
} // QgisApp::whatsThis()
4459
 
 
4460
 
 
4461
 
std::map<QString, int> QgisApp::menuMapByName()
4462
 
{
4463
 
  // Must populate the maps with each call since menus might have been
4464
 
  // added or deleted
4465
 
  populateMenuMaps();
4466
 
  // Return the menu items mapped by name (key is name, value is menu id)
4467
 
  return mMenuMapByName;
4468
 
}
4469
 
std::map<int, QString> QgisApp::menuMapById()
4470
 
{
4471
 
  // Must populate the maps with each call since menus might have been
4472
 
  // added or deleted
4473
 
  populateMenuMaps();
4474
 
  // Return the menu items mapped by menu id (key is menu id, value is name)
4475
 
  return mMenuMapById;
4476
 
}
4477
 
void QgisApp::populateMenuMaps()
4478
 
{
4479
 
  // Populate the two menu maps by iterating through the menu bar
4480
 
  mMenuMapByName.clear();
4481
 
  mMenuMapById.clear();
4482
 
  int idx = 0;
4483
 
  int menuId;
4484
 
  // Loop until we get an id of -1, which indicates there are no more
4485
 
  // items.
4486
 
  do
4487
 
  {
4488
 
    menuId = menuBar()->idAt(idx++);
4489
 
    std::cout << "Menu id " << menuId << " is " << menuBar()->text(menuId).toLocal8Bit().data() << std::endl;
4490
 
    mMenuMapByName[menuBar()->text(menuId)] = menuId;
4491
 
    mMenuMapById[menuId] = menuBar()->text(menuId);
4492
 
  }
4493
 
  while(menuId != -1);
4494
 
}
4495
 
 
4496
 
QMenu* QgisApp::getPluginMenu(QString menuName)
4497
 
{
4498
 
  // This is going to record the menu item that the potentially new
4499
 
  // menu item is going to be inserted before. A value of 0 will a new
4500
 
  // menu item to be appended.
4501
 
  QAction* before = 0;
4502
 
 
4503
 
  QList<QAction*> actions = mPluginMenu->actions();
4504
 
  // Avoid 1 because the first item (number 0) is 'Plugin Manager',
4505
 
  // which we  want to stay first. Search in reverse order as that
4506
 
  // makes it easier to find out where which item a new menu item
4507
 
  // should go before (since the insertMenu() function requires a
4508
 
  // 'before' argument).
4509
 
  for (unsigned int i = actions.count()-1; i > 0; --i)
4510
 
  {
4511
 
    if (actions.at(i)->text() == menuName)
4512
 
    {
4513
 
      return actions.at(i)->menu();
4514
 
    }
4515
 
    // Find out where to put the menu item, assuming that it is a new one
4516
 
    //
4517
 
    // This bit of code assumes that the menu items are already in
4518
 
    // alphabetical order, which they will be if the menus are all
4519
 
    // created using this function.
4520
 
    if (menuName.localeAwareCompare(actions.at(i)->text()) <= 0)
4521
 
      before = actions.at(i);
4522
 
  }
4523
 
 
4524
 
  // It doesn't exist, so create 
4525
 
  QMenu* menu = new QMenu(menuName, this);
4526
 
  // Where to put it? - we worked that out above...
4527
 
  mPluginMenu->insertMenu(before, menu);
4528
 
 
4529
 
  return menu;
4530
 
}
4531
 
 
4532
 
void QgisApp::addPluginMenu(QString name, QAction* action)
4533
 
{
4534
 
  QMenu* menu = getPluginMenu(name);
4535
 
  menu->addAction(action);
4536
 
}
4537
 
 
4538
 
void QgisApp::removePluginMenu(QString name, QAction* action)
4539
 
{
4540
 
  QMenu* menu = getPluginMenu(name);
4541
 
  menu->removeAction(action);
4542
 
  if (menu->actions().count() == 0)
4543
 
    {
4544
 
      mPluginMenu->removeAction(menu->menuAction());
4545
 
    }
4546
 
}
4547
 
 
4548
 
int QgisApp::addPluginToolBarIcon (QAction * qAction)
4549
 
{
4550
 
  qAction->addTo(mPluginToolBar);
4551
 
  return 0;
4552
 
}
4553
 
void QgisApp::removePluginToolBarIcon(QAction *qAction)
4554
 
{
4555
 
  qAction->removeFrom(mPluginToolBar);
4556
 
}
4557
 
 
4558
 
void QgisApp::projectionsEnabled(bool theFlag)
4559
 
{
4560
 
  QString myIconPath = QgsApplication::themePath();
4561
 
  if (theFlag)
4562
 
  {
4563
 
    QPixmap myProjPixmap;
4564
 
    myProjPixmap.load(myIconPath+"/mIconProjectionEnabled.png");
4565
 
    //assert(!myProjPixmap.isNull());
4566
 
    mOnTheFlyProjectionStatusButton->setPixmap(myProjPixmap);
4567
 
  }
4568
 
  else
4569
 
  {
4570
 
    QPixmap myProjPixmap;
4571
 
    myProjPixmap.load(myIconPath+"/mIconProjectionDisabled.png");
4572
 
    //assert(!myProjPixmap.isNull());
4573
 
    mOnTheFlyProjectionStatusButton->setPixmap(myProjPixmap);
4574
 
  }
4575
 
}
4576
 
// slot to update the progress bar in the status bar
4577
 
void QgisApp::showProgress(int theProgress, int theTotalSteps)
4578
 
{
4579
 
#ifdef QGISDEBUG
4580
 
  std::cout << "showProgress called with " << theProgress << "/" << theTotalSteps << std::endl;
4581
 
#endif
4582
 
 
4583
 
  if (theProgress==theTotalSteps)
4584
 
  {
4585
 
    mProgressBar->reset();
4586
 
    mProgressBar->hide();
4587
 
   }
4588
 
  else
4589
 
  {
4590
 
    //only call show if not already hidden to reduce flicker
4591
 
    if (!mProgressBar->isVisible())
4592
 
    {
4593
 
      mProgressBar->show();
4594
 
    }
4595
 
    mProgressBar->setMaximum(theTotalSteps);
4596
 
    mProgressBar->setValue(theProgress);
4597
 
  }
4598
 
 
4599
 
 
4600
 
}
4601
 
 
4602
 
void QgisApp::showExtents(QgsRect theExtents)
4603
 
{
4604
 
  // update the statusbar with the current extents.
4605
 
  statusBar()->message(QString(tr("Extents: ")) + theExtents.stringRep(true));
4606
 
 
4607
 
} // QgisApp::showExtents
4608
 
 
4609
 
 
4610
 
void QgisApp::updateMouseCoordinatePrecision()
4611
 
{
4612
 
  // Work out what mouse display precision to use. This only needs to
4613
 
  // be when the settings change or the zoom level changes. This
4614
 
  // function needs to be called every time one of the above happens.
4615
 
 
4616
 
  // Get the display precision from the project settings
4617
 
  bool automatic = QgsProject::instance()->readBoolEntry("PositionPrecision","/Automatic");
4618
 
  int dp = 0;
4619
 
 
4620
 
  if (automatic)
4621
 
  {
4622
 
    // Work out a suitable number of decimal places for the mouse
4623
 
    // coordinates with the aim of always having enough decimal places
4624
 
    // to show the difference in position between adjacent pixels.
4625
 
    // Also avoid taking the log of 0.
4626
 
    if (getMapCanvas()->mupp() != 0.0)
4627
 
      dp = static_cast<int> (ceil(-1.0*log10(getMapCanvas()->mupp())));
4628
 
  }
4629
 
  else
4630
 
    dp = QgsProject::instance()->readNumEntry("PositionPrecision","/DecimalPlaces");
4631
 
 
4632
 
  // Keep dp sensible
4633
 
  if (dp < 0) dp = 0;
4634
 
 
4635
 
  mMousePrecisionDecimalPlaces = dp;
4636
 
}
4637
 
 
4638
 
void QgisApp::showStatusMessage(QString theMessage)
4639
 
{
4640
 
#ifdef QGISDEBUG
4641
 
  //  std::cout << "QgisApp::showStatusMessage: entered with '" << theMessage << "'." << std::endl;
4642
 
#endif
4643
 
 
4644
 
  statusBar()->message(theMessage);
4645
 
}
4646
 
 
4647
 
void QgisApp::projectPropertiesProjections()
4648
 
{
4649
 
  // Driver to display the project props dialog and switch to the
4650
 
  // projections tab
4651
 
  mShowProjectionTab = true;
4652
 
  projectProperties();
4653
 
}
4654
 
 
4655
 
void QgisApp::projectProperties()
4656
 
{
4657
 
  /* Display the property sheet for the Project */
4658
 
  // set wait cursor since construction of the project properties
4659
 
  // dialog results in the construction of the spatial reference
4660
 
  // system QMap
4661
 
  QApplication::setOverrideCursor(Qt::WaitCursor);
4662
 
  QgsProjectProperties *pp = new QgsProjectProperties(this);
4663
 
  // if called from the status bar, show the projection tab
4664
 
  if(mShowProjectionTab)
4665
 
  {
4666
 
    pp->showProjectionsTab();
4667
 
    mShowProjectionTab = false;
4668
 
  }
4669
 
  qApp->processEvents();
4670
 
  // Be told if the mouse display precision may have changed by the user
4671
 
  // changing things in the project properties dialog box
4672
 
  connect(pp, SIGNAL(displayPrecisionChanged()), this, 
4673
 
      SLOT(updateMouseCoordinatePrecision()));
4674
 
  //listen to changes in on the fly projection state
4675
 
  connect(pp, SIGNAL(projectionEnabled(bool)), this, 
4676
 
      SLOT(projectionsEnabled(bool)));
4677
 
  QApplication::restoreOverrideCursor();
4678
 
  //pass any refresg signals off to canvases
4679
 
  //connect (pp,SIGNAL(refresh()), mMapCanvas, SLOT(refresh()));
4680
 
  connect (pp,SIGNAL(mapUnitsChanged()), mMapCanvas, SLOT(mapUnitsChanged()));  
4681
 
 
4682
 
  bool wasProjected = pp->isProjected();
4683
 
  long oldSRSID =  QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectSRSID",GEOSRS_ID);
4684
 
 
4685
 
  // Display the modal dialog box.
4686
 
  pp->exec();
4687
 
  
4688
 
  long newSRSID =  QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectSRSID",GEOSRS_ID);
4689
 
  
4690
 
  // projections have been turned on/off or dest SRS has changed while projections are on
4691
 
  if (wasProjected != pp->isProjected() || (pp->isProjected() && oldSRSID != newSRSID))
4692
 
  {
4693
 
    mMapCanvas->updateFullExtent();
4694
 
  }
4695
 
  
4696
 
  int  myRedInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorRedPart",255);
4697
 
  int  myGreenInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorGreenPart",255);
4698
 
  int  myBlueInt = QgsProject::instance()->readNumEntry("Gui","/CanvasColorBluePart",255);
4699
 
  QColor myColor = QColor(myRedInt,myGreenInt,myBlueInt);
4700
 
  mMapCanvas->setCanvasColor(myColor); // this is fill colour before rendering onto canvas
4701
 
  
4702
 
  // Set the window title.
4703
 
  setTitleBarText_( *this );
4704
 
  
4705
 
  // delete the property sheet object
4706
 
  delete pp;
4707
 
} // QgisApp::projectProperties
4708
 
 
4709
 
 
4710
 
QgsMapLayerRegistry * QgisApp::getLayerRegistry()
4711
 
{
4712
 
  return QgsMapLayerRegistry::instance();
4713
 
}
4714
 
 
4715
 
 
4716
 
 
4717
 
 
4718
 
QgsClipboard * QgisApp::clipboard()
4719
 
{
4720
 
  return &mInternalClipboard;
4721
 
}
4722
 
 
4723
 
void QgisApp::activateDeactivateLayerRelatedActions(const QgsMapLayer* layer)
4724
 
{
4725
 
  if(!layer)
4726
 
    {
4727
 
      return;
4728
 
    }
4729
 
 
4730
 
  /***********Vector layers****************/
4731
 
  if(layer->type() == QgsMapLayer::VECTOR || layer->type() == QgsMapLayer::DATABASE)
4732
 
    {
4733
 
      mActionSelect->setEnabled(true);
4734
 
      mActionOpenTable->setEnabled(true);
4735
 
      mActionIdentify->setEnabled(true);
4736
 
      mActionEditCopy->setEnabled(true);
4737
 
 
4738
 
      const QgsVectorLayer* vlayer = dynamic_cast<const QgsVectorLayer*>(layer);
4739
 
      const QgsVectorDataProvider* dprovider = vlayer->getDataProvider();
4740
 
 
4741
 
      if (dprovider)
4742
 
        {
4743
 
          //start editing/stop editing
4744
 
          if(dprovider->capabilities() & QgsVectorDataProvider::AddFeatures)
4745
 
            {
4746
 
              mActionStartEditing->setEnabled(true);
4747
 
              mActionStopEditing->setEnabled(true);
4748
 
              mActionEditPaste->setEnabled(true);
4749
 
            }
4750
 
          else
4751
 
            {
4752
 
              mActionStartEditing->setEnabled(false);
4753
 
              mActionStopEditing->setEnabled(false);
4754
 
              mActionEditPaste->setEnabled(false);
4755
 
            }
4756
 
 
4757
 
          //does provider allow deleting of features?
4758
 
          if(dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures)
4759
 
            {
4760
 
              mActionDeleteSelected->setEnabled(true);
4761
 
              mActionEditCut->setEnabled(true);
4762
 
            }
4763
 
          else
4764
 
            {
4765
 
              mActionDeleteSelected->setEnabled(false);
4766
 
              mActionEditCut->setEnabled(false);
4767
 
            }
4768
 
 
4769
 
 
4770
 
          if(vlayer->vectorType() == QGis::Point)
4771
 
            {
4772
 
              if(dprovider->capabilities() & QgsVectorDataProvider::AddFeatures)
4773
 
                {
4774
 
                  mActionCapturePoint->setEnabled(true);
4775
 
                }
4776
 
              else
4777
 
                {
4778
 
                  mActionCapturePoint->setEnabled(false);
4779
 
                }
4780
 
              mActionCaptureLine->setEnabled(false);
4781
 
              mActionCapturePolygon->setEnabled(false);
4782
 
              mActionAddVertex->setEnabled(false);
4783
 
              mActionDeleteVertex->setEnabled(false);
4784
 
              if(dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries)
4785
 
                {
4786
 
                  mActionMoveVertex->setEnabled(true);
4787
 
                }
4788
 
              return;
4789
 
            }
4790
 
          else if(vlayer->vectorType() == QGis::Line)
4791
 
            {
4792
 
              if(dprovider->capabilities() & QgsVectorDataProvider::AddFeatures)
4793
 
                {
4794
 
                  mActionCaptureLine->setEnabled(true);
4795
 
                }
4796
 
              else
4797
 
                {
4798
 
                  mActionCaptureLine->setEnabled(false);
4799
 
                }
4800
 
              mActionCapturePoint->setEnabled(false);
4801
 
              mActionCapturePolygon->setEnabled(false);
4802
 
            }
4803
 
          else if(vlayer->vectorType() == QGis::Polygon)
4804
 
            {
4805
 
              if(dprovider->capabilities() & QgsVectorDataProvider::AddFeatures)
4806
 
                {
4807
 
                  mActionCapturePolygon->setEnabled(true);
4808
 
                }
4809
 
              else
4810
 
                {
4811
 
                  mActionCapturePolygon->setEnabled(false);
4812
 
                }
4813
 
              mActionCapturePoint->setEnabled(false);
4814
 
              mActionCaptureLine->setEnabled(false);
4815
 
            }
4816
 
 
4817
 
          //are add/delete/move vertex supported?
4818
 
          if(dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries)
4819
 
            {
4820
 
              mActionAddVertex->setEnabled(true);
4821
 
              mActionMoveVertex->setEnabled(true);
4822
 
              mActionDeleteVertex->setEnabled(true);
4823
 
            }
4824
 
          else
4825
 
            {
4826
 
              mActionAddVertex->setEnabled(false);
4827
 
              mActionMoveVertex->setEnabled(false);
4828
 
              mActionDeleteVertex->setEnabled(false);
4829
 
            }
4830
 
          return;
4831
 
        }
4832
 
    }
4833
 
  /*************Raster layers*************/
4834
 
  else if(layer->type() == QgsMapLayer::RASTER)
4835
 
    {
4836
 
      mActionSelect->setEnabled(false);
4837
 
      mActionOpenTable->setEnabled(false);
4838
 
      mActionStartEditing->setEnabled(false);
4839
 
      mActionStopEditing->setEnabled(false);
4840
 
      mActionCapturePoint->setEnabled(false);
4841
 
      mActionCaptureLine->setEnabled(false);
4842
 
      mActionCapturePolygon->setEnabled(false);
4843
 
      mActionDeleteSelected->setEnabled(false);
4844
 
      mActionAddVertex->setEnabled(false);
4845
 
      mActionDeleteVertex->setEnabled(false);
4846
 
      mActionMoveVertex->setEnabled(false);
4847
 
      mActionEditCopy->setEnabled(false);
4848
 
      mActionEditCut->setEnabled(false);
4849
 
      mActionEditPaste->setEnabled(false);
4850
 
 
4851
 
      const QgsRasterLayer* vlayer = dynamic_cast<const QgsRasterLayer*> (layer);
4852
 
      const QgsRasterDataProvider* dprovider = vlayer->getDataProvider();
4853
 
      if (dprovider)
4854
 
      {
4855
 
        // does provider allow the identify map tool?
4856
 
        if (dprovider->capabilities() & QgsRasterDataProvider::Identify)
4857
 
        {
4858
 
          mActionIdentify->setEnabled(TRUE);
4859
 
        }
4860
 
        else
4861
 
        {
4862
 
          mActionIdentify->setEnabled(FALSE);
4863
 
        }
4864
 
      }
4865
 
    }
4866
 
}
4867
 
 
4868
 
 
4869
 
//copy the click coord to clipboard and let the user know its there
4870
 
void QgisApp::showCapturePointCoordinate(QgsPoint & theQgsPoint)
4871
 
{
4872
 
#ifdef QGISDEBUG
4873
 
  std::cout << "Capture point (clicked on map) at position " << theQgsPoint.stringRep(2).toLocal8Bit().data() << std::endl;
4874
 
#endif
4875
 
 
4876
 
  QClipboard *myClipboard = QApplication::clipboard();
4877
 
  //if we are on x11 system put text into selection ready for middle button pasting
4878
 
  if (myClipboard->supportsSelection())
4879
 
  {
4880
 
    myClipboard->setText(theQgsPoint.stringRep(2),QClipboard::Selection);
4881
 
    QString myMessage = tr("Clipboard contents set to: ");
4882
 
    statusBar()->message(myMessage + myClipboard->text(QClipboard::Selection));
4883
 
  }
4884
 
  else
4885
 
  {
4886
 
    //user has an inferior operating system....
4887
 
    myClipboard->setText(theQgsPoint.stringRep(2),QClipboard::Clipboard );
4888
 
    QString myMessage = tr("Clipboard contents set to: ");
4889
 
    statusBar()->message(myMessage + myClipboard->text(QClipboard::Clipboard));
4890
 
  }
4891
 
#ifdef QGISDEBUG
4892
 
  /* Well use this in ver 0.5 when we do digitising! */
4893
 
  /*
4894
 
     QgsVectorFileWriter myFileWriter("/tmp/test.shp", wkbPoint);
4895
 
     if (myFileWriter.initialise())
4896
 
     {
4897
 
     myFileWriter.createField("TestInt",OFTInteger,8,0);
4898
 
     myFileWriter.createField("TestRead",OFTReal,8,3);
4899
 
     myFileWriter.createField("TestStr",OFTString,255,0);
4900
 
     myFileWriter.writePoint(&theQgsPoint);
4901
 
     }
4902
 
     */
4903
 
#endif
4904
 
}
4905
 
 
4906
 
 
4907
 
 
4908
 
/////////////////////////////////////////////////////////////////
4909
 
//
4910
 
//
4911
 
// Only functions relating to raster layer management in this
4912
 
// section (look for a similar comment block to this to find
4913
 
// the end of this section).
4914
 
//
4915
 
// Tim Sutton
4916
 
//
4917
 
//
4918
 
/////////////////////////////////////////////////////////////////
4919
 
 
4920
 
 
4921
 
/** @todo XXX I'd *really* like to return, ya know, _false_.
4922
 
*/
4923
 
//create a raster layer object and delegate to addRasterLayer(QgsRasterLayer *)
4924
 
void QgisApp::addRasterLayer()
4925
 
{
4926
 
  //mMapCanvas->freeze(true);
4927
 
 
4928
 
  QString fileFilters;
4929
 
 
4930
 
 
4931
 
  QStringList selectedFiles;
4932
 
  QString e;//only for parameter correctness
4933
 
  QString title = tr("Open a GDAL Supported Raster Data Source");
4934
 
  openFilesRememberingFilter_("lastRasterFileFilter", mRasterFileFilter, selectedFiles,e,
4935
 
      title);
4936
 
 
4937
 
  if (selectedFiles.isEmpty())
4938
 
  {
4939
 
    // no files were selected, so just bail
4940
 
    return;
4941
 
  }
4942
 
 
4943
 
  addRasterLayer(selectedFiles);
4944
 
  mMapCanvas->freeze(false);
4945
 
  mMapCanvas->refresh();
4946
 
}// QgisApp::addRasterLayer()
4947
 
 
4948
 
//
4949
 
// This is the method that does the actual work of adding a raster layer - the others
4950
 
// here simply create a raster layer object and delegate here. It is the responsibility
4951
 
// of the calling method to manage things such as the frozen state of the mapcanvas and
4952
 
// using waitcursors etc. - this method wont and SHOULDNT do it
4953
 
//
4954
 
bool QgisApp::addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRedrawFlag)
4955
 
{
4956
 
 
4957
 
  Q_CHECK_PTR( theRasterLayer );
4958
 
 
4959
 
  if ( ! theRasterLayer )
4960
 
  {
4961
 
    // XXX insert meaningful whine to the user here; although be
4962
 
    // XXX mindful that a null layer may mean exhausted memory resources
4963
 
    return false;
4964
 
  }
4965
 
 
4966
 
  if (theRasterLayer->isValid())
4967
 
  {
4968
 
    // register this layer with the central layers registry
4969
 
    QgsMapLayerRegistry::instance()->addMapLayer(theRasterLayer);
4970
 
    theRasterLayer->refreshLegend();
4971
 
    // XXX doesn't the mMapCanvas->addLayer() do this?
4972
 
    // XXX now it does
4973
 
    //     QObject::connect(theRasterLayer,
4974
 
    //             SIGNAL(repaintRequested()),
4975
 
    //             mMapCanvas,
4976
 
    //             SLOT(refresh()));
4977
 
 
4978
 
    // connect up any request the raster may make to update the app progress
4979
 
    QObject::connect(theRasterLayer,
4980
 
        SIGNAL(drawingProgress(int,int)),
4981
 
        this,
4982
 
        SLOT(showProgress(int,int)));
4983
 
    // connect up any request the raster may make to update the statusbar message
4984
 
    QObject::connect(theRasterLayer,
4985
 
        SIGNAL(setStatus(QString)),
4986
 
        this,
4987
 
        SLOT(showStatusMessage(QString)));
4988
 
    // connect up any keypresses to be passed tot he layer (e.g. so esc can stop rendering)
4989
 
#ifdef QGISDEBUG
4990
 
    std::cout << " Connecting up maplayers keyPressed event to the QgisApp keyPress signal" << std::endl;
4991
 
#endif
4992
 
    QObject::connect(this ,
4993
 
        SIGNAL(keyPressed(QKeyEvent * )),
4994
 
        theRasterLayer,
4995
 
        SLOT(keyPressed(QKeyEvent* )));
4996
 
 
4997
 
    // init the context menu so it can connect to slots in main app
4998
 
    // XXX now taken care of in legend theRasterLayer->initContextMenu(this);
4999
 
 
5000
 
    // add it to the mapcanvas collection
5001
 
    // no longer necessary since adding to registry automatically adds to canvas
5002
 
    // mMapCanvas->addLayer(theRasterLayer);
5003
 
 
5004
 
  }
5005
 
  else
5006
 
  {
5007
 
    delete theRasterLayer;
5008
 
    return false;
5009
 
  }
5010
 
 
5011
 
  if (theForceRedrawFlag)
5012
 
  {
5013
 
    qApp->processEvents();
5014
 
    mMapCanvas->freeze(false);
5015
 
    mMapCanvas->refresh();
5016
 
  }
5017
 
  return true;
5018
 
 
5019
 
}
5020
 
 
5021
 
 
5022
 
//create a raster layer object and delegate to addRasterLayer(QgsRasterLayer *)
5023
 
 
5024
 
bool QgisApp::addRasterLayer(QFileInfo const & rasterFile, bool guiWarning)
5025
 
{
5026
 
  // let the user know we're going to possibly be taking a while
5027
 
  QApplication::setOverrideCursor(Qt::WaitCursor);
5028
 
 
5029
 
  mMapCanvas->freeze(true);
5030
 
 
5031
 
  // XXX ya know QgsRasterLayer can snip out the basename on its own;
5032
 
  // XXX why do we have to pass it in for it?
5033
 
  QgsRasterLayer *layer =
5034
 
    new QgsRasterLayer(rasterFile.filePath(), rasterFile.completeBaseName());
5035
 
 
5036
 
  if (!addRasterLayer(layer))
5037
 
  {
5038
 
    mMapCanvas->freeze(false);
5039
 
    QApplication::restoreOverrideCursor();
5040
 
 
5041
 
// Let render() do its own cursor management
5042
 
//    QApplication::restoreOverrideCursor();
5043
 
 
5044
 
    if(guiWarning)
5045
 
    {
5046
 
      // don't show the gui warning (probably because we are loading from command line)
5047
 
      QString msg(rasterFile.completeBaseName()
5048
 
          + tr(" is not a valid or recognized raster data source"));
5049
 
      QMessageBox::critical(this, tr("Invalid Data Source"), msg);
5050
 
    }
5051
 
    delete layer;
5052
 
    return false;
5053
 
  }
5054
 
  else
5055
 
  {
5056
 
    statusBar()->message(mMapCanvas->extent().stringRep(2));
5057
 
    layer->refreshLegend();
5058
 
    mMapCanvas->freeze(false);
5059
 
    QApplication::restoreOverrideCursor();
5060
 
 
5061
 
// Let render() do its own cursor management
5062
 
//    QApplication::restoreOverrideCursor();
5063
 
 
5064
 
    return true;
5065
 
  }
5066
 
 
5067
 
} // QgisApp::addRasterLayer
5068
 
 
5069
 
 
5070
 
 
5071
 
/** Add a raster layer directly without prompting user for location
5072
 
  The caller must provide information compatible with the provider plugin
5073
 
  using the rasterLayerPath and baseName. The provider can use these
5074
 
  parameters in any way necessary to initialize the layer. The baseName
5075
 
  parameter is used in the Map Legend so it should be formed in a meaningful
5076
 
  way.
5077
 
 
5078
 
  \note   Copied from the equivalent addVectorLayer function in this file
5079
 
  TODO    Make it work for rasters specifically.
5080
 
  */
5081
 
void QgisApp::addRasterLayer(QString const & rasterLayerPath,
5082
 
    QString const & baseName,
5083
 
    QString const & providerKey,
5084
 
    QStringList const & layers,
5085
 
    QStringList const & styles,
5086
 
    QString const & format,
5087
 
    QString const & crs,
5088
 
    QString const & proxyHost, 
5089
 
    int proxyPort, 
5090
 
    QString const & proxyUser,
5091
 
    QString const & proxyPassword)
5092
 
{
5093
 
 
5094
 
#ifdef QGISDEBUG
5095
 
  std::cout << "QgisApp::addRasterLayer: about to get library for " << providerKey.toLocal8Bit().data() << std::endl;
5096
 
#endif
5097
 
 
5098
 
  mMapCanvas->freeze();
5099
 
 
5100
 
// Let render() do its own cursor management
5101
 
//  QApplication::setOverrideCursor(Qt::WaitCursor);
5102
 
 
5103
 
  // create the layer
5104
 
  QgsRasterLayer *layer;
5105
 
  /* Eliminate the need to instantiate the layer based on provider type.
5106
 
     The caller is responsible for cobbling together the needed information to
5107
 
     open the layer
5108
 
     */
5109
 
#ifdef QGISDEBUG
5110
 
 
5111
 
  std::cout << "QgisApp::addRasterLayer: Creating new raster layer using " <<
5112
 
    rasterLayerPath.toLocal8Bit().data() << " with baseName of " << baseName.toLocal8Bit().data() <<
5113
 
    " and layer list of " << layers.join(", ").toLocal8Bit().data() <<
5114
 
    " and style list of " << styles.join(", ").toLocal8Bit().data() <<
5115
 
    " and format of " << format.toLocal8Bit().data() <<
5116
 
    " and providerKey of " << providerKey.toLocal8Bit().data() <<
5117
 
    " and CRS of " << crs.toLocal8Bit().data() << std::endl;
5118
 
#endif
5119
 
 
5120
 
  // TODO: Remove the 0 when the raster layer becomes a full provider gateway.
5121
 
  layer = new QgsRasterLayer(0, rasterLayerPath, baseName, providerKey, layers, styles, format, crs,
5122
 
                             proxyHost, proxyPort, proxyUser, proxyPassword);
5123
 
 
5124
 
#ifdef QGISDEBUG
5125
 
  std::cout << "QgisApp::addRasterLayer: Constructed new layer." << std::endl;
5126
 
#endif
5127
 
 
5128
 
  if( layer && layer->isValid() )
5129
 
  {
5130
 
    // Register this layer with the layers registry
5131
 
    QgsMapLayerRegistry::instance()->addMapLayer(layer);
5132
 
    // init the context menu so it can connect to slots in main app
5133
 
    // now taken care of in legend layer->initContextMenu(this);
5134
 
 
5135
 
    // connect up any request the raster may make to update the app progress
5136
 
    QObject::connect(layer,
5137
 
        SIGNAL(drawingProgress(int,int)),
5138
 
        this,
5139
 
        SLOT(showProgress(int,int)));
5140
 
    // connect up any request the raster may make to update the statusbar message
5141
 
    QObject::connect(layer,
5142
 
        SIGNAL(setStatus(QString)),
5143
 
        this,
5144
 
        SLOT(showStatusMessage(QString)));
5145
 
 
5146
 
    // connect up any keypresses to be passed tot he layer (e.g. so esc can stop rendering)
5147
 
#ifdef QGISDEBUG
5148
 
    std::cout << " Connecting up maplayers keyPressed event to the QgisApp keyPress signal" << std::endl;
5149
 
#endif
5150
 
    QObject::connect(this,
5151
 
        SIGNAL(keyPressed(QKeyEvent * )),
5152
 
        layer,
5153
 
        SLOT(keyPressed(QKeyEvent* )));
5154
 
 
5155
 
    QgsProject::instance()->dirty(false); // XXX this might be redundant
5156
 
 
5157
 
    statusBar()->message(mMapCanvas->extent().stringRep(2));
5158
 
 
5159
 
  }
5160
 
  else
5161
 
  {
5162
 
    QMessageBox::critical(this,tr("Layer is not valid"),
5163
 
        tr("The layer is not a valid layer and can not be added to the map"));
5164
 
  }
5165
 
 
5166
 
  qApp->processEvents();
5167
 
  mMapCanvas->freeze(false);
5168
 
  mMapCanvas->refresh();
5169
 
 
5170
 
// Let render() do its own cursor management
5171
 
//  QApplication::restoreOverrideCursor();
5172
 
 
5173
 
} // QgisApp::addRasterLayer
5174
 
 
5175
 
 
5176
 
 
5177
 
//create a raster layer object and delegate to addRasterLayer(QgsRasterLayer *)
5178
 
bool QgisApp::addRasterLayer(QStringList const &theFileNameQStringList, bool guiWarning)
5179
 
{
5180
 
  if (theFileNameQStringList.empty())
5181
 
  {
5182
 
    // no files selected so bail out, but
5183
 
    // allow mMapCanvas to handle events
5184
 
    // first
5185
 
    mMapCanvas->freeze(false);
5186
 
    return false;
5187
 
  }
5188
 
 
5189
 
  mMapCanvas->freeze(true);
5190
 
 
5191
 
// Let render() do its own cursor management
5192
 
//  QApplication::setOverrideCursor(Qt::WaitCursor);
5193
 
 
5194
 
  // this is messy since some files in the list may be rasters and others may
5195
 
  // be ogr layers. We'll set returnValue to false if one or more layers fail
5196
 
  // to load.
5197
 
  bool returnValue = true;
5198
 
  for (QStringList::ConstIterator myIterator = theFileNameQStringList.begin();
5199
 
      myIterator != theFileNameQStringList.end();
5200
 
      ++myIterator)
5201
 
  {
5202
 
    if (QgsRasterLayer::isValidRasterFileName(*myIterator))
5203
 
    {
5204
 
      QFileInfo myFileInfo(*myIterator);
5205
 
      // get the directory the .adf file was in
5206
 
      QString myDirNameQString = myFileInfo.dirPath();
5207
 
      QString myBaseNameQString = myFileInfo.completeBaseName();
5208
 
      //only allow one copy of a ai grid file to be loaded at a
5209
 
      //time to prevent the user selecting all adfs in 1 dir which
5210
 
      //actually represent 1 coverage,
5211
 
 
5212
 
      // create the layer
5213
 
      QgsRasterLayer *layer = new QgsRasterLayer(*myIterator, myBaseNameQString);
5214
 
 
5215
 
      // set initial visibility based on user preference
5216
 
      layer->setVisible(mAddedLayersVisible);
5217
 
 
5218
 
      addRasterLayer(layer);
5219
 
 
5220
 
      //only allow one copy of a ai grid file to be loaded at a
5221
 
      //time to prevent the user selecting all adfs in 1 dir which
5222
 
      //actually represent 1 coverate,
5223
 
 
5224
 
      if (myBaseNameQString.lower().endsWith(".adf"))
5225
 
      {
5226
 
        break;
5227
 
      }
5228
 
    }
5229
 
    else
5230
 
    {
5231
 
      // Issue message box warning unless we are loading from cmd line since
5232
 
      // non-rasters are passed to this function first and then sucessfully
5233
 
      // loaded afterwards (see main.cpp)
5234
 
 
5235
 
      if(guiWarning)
5236
 
      {
5237
 
        QString msg(*myIterator + tr(" is not a supported raster data source"));
5238
 
        QMessageBox::critical(this, tr("Unsupported Data Source"), msg);
5239
 
      }
5240
 
      returnValue = false;
5241
 
    }
5242
 
  }
5243
 
 
5244
 
  statusBar()->message(mMapCanvas->extent().stringRep(2));
5245
 
  mMapCanvas->freeze(false);
5246
 
 
5247
 
// Let render() do its own cursor management
5248
 
//  QApplication::restoreOverrideCursor();
5249
 
 
5250
 
  return returnValue;
5251
 
 
5252
 
}// QgisApp::addRasterLayer()
5253
 
 
5254
 
 
5255
 
 
5256
 
 
5257
 
///////////////////////////////////////////////////////////////////
5258
 
//
5259
 
//
5260
 
//
5261
 
//
5262
 
//    RASTER ONLY RELATED FUNCTIONS BLOCK ENDS....
5263
 
//
5264
 
//
5265
 
//
5266
 
//
5267
 
///////////////////////////////////////////////////////////////////
5268
 
 
5269
 
 
5270
 
void QgisApp::keyPressEvent ( QKeyEvent * e )
5271
 
{
5272
 
  // The following statment causes a crash on WIN32 and should be 
5273
 
  // enclosed in an #ifdef QGISDEBUG if its really necessary. Its
5274
 
  // commented out for now. [gsherman]
5275
 
  //    std::cout << e->text().toLocal8Bit().data() << " (keypress recevied)" << std::endl;
5276
 
  emit keyPressed (e);
5277
 
  e->ignore();
5278
 
 
5279
 
}
5280
 
// Debug hook - used to output diagnostic messages when evoked (usually from the menu)
5281
 
/* Temporarily disabled...
5282
 
   void QgisApp::debugHook()
5283
 
   {
5284
 
   std::cout << "Hello from debug hook" << std::endl; 
5285
 
// show the map canvas extent
5286
 
std::cout << mMapCanvas->extent() << std::endl; 
5287
 
}
5288
 
*/
5289
 
void QgisApp::customProjection()
5290
 
{
5291
 
  // Create an instance of the Custom Projection Designer modeless dialog.
5292
 
  // Autodelete the dialog when closing since a pointer is not retained.
5293
 
  QgsCustomProjectionDialog * myDialog = new QgsCustomProjectionDialog(this,
5294
 
      Qt::WDestructiveClose);
5295
 
  myDialog->show();
5296
 
}
5297
 
void QgisApp::showBookmarks()
5298
 
{
5299
 
  // Create or show the single instance of the Bookmarks modeless dialog.
5300
 
  // Closing a QWidget only hides it so it can be shown again later.
5301
 
  static QgsBookmarks *bookmarks = NULL;
5302
 
  if (bookmarks == NULL)
5303
 
  {
5304
 
    bookmarks = new QgsBookmarks(this, Qt::WindowMinMaxButtonsHint);
5305
 
  }
5306
 
  bookmarks->show();
5307
 
  bookmarks->raise();
5308
 
  bookmarks->setActiveWindow();
5309
 
}
5310
 
 
5311
 
void QgisApp::newBookmark()
5312
 
{
5313
 
  // Get the name for the bookmark. Everything else we fetch from
5314
 
  // the mapcanvas
5315
 
 
5316
 
  bool ok;
5317
 
  QString bookmarkName = QInputDialog::getText(tr("New Bookmark"), 
5318
 
      tr("Enter a name for the new bookmark:"), QLineEdit::Normal,
5319
 
      QString::null, &ok, this);
5320
 
  if( ok && !bookmarkName.isEmpty())
5321
 
  {
5322
 
    if (createDB())
5323
 
    {
5324
 
      // create the bookmark
5325
 
      QgsBookmarkItem *bmi = new QgsBookmarkItem(bookmarkName, 
5326
 
          QgsProject::instance()->title(), mMapCanvas->extent(), -1,
5327
 
          QgsApplication::qgisUserDbFilePath());
5328
 
      bmi->store();
5329
 
      delete bmi;
5330
 
      // emit a signal to indicate that the bookmark was added
5331
 
      emit bookmarkAdded();
5332
 
    }
5333
 
    else
5334
 
    {
5335
 
      QMessageBox::warning(this,tr("Error"), tr("Unable to create the bookmark. Your user database may be missing or corrupted"));
5336
 
    }
5337
 
  }
5338
 
}      
5339
 
 
5340
 
void QgisApp::showAllToolbars()
5341
 
{
5342
 
  setToolbarVisibility(true);
5343
 
}
5344
 
 
5345
 
void QgisApp::hideAllToolbars()
5346
 
{
5347
 
  setToolbarVisibility(false);
5348
 
}
5349
 
 
5350
 
void QgisApp::setToolbarVisibility(bool visibility)
5351
 
{
5352
 
  mFileToolBar->setVisible(visibility);
5353
 
  mLayerToolBar->setVisible(visibility);
5354
 
  mMapNavToolBar->setVisible(visibility);
5355
 
  mDigitizeToolBar->setVisible(visibility);
5356
 
  mAttributesToolBar->setVisible(visibility);
5357
 
  mPluginToolBar->setVisible(visibility);
5358
 
  mHelpToolBar->setVisible(visibility);
5359
 
}