MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl) : QMainWindow(parent,fl) { //required by Qt4 to initialise the ui setupUi(this); // Instantiate Provider Registry #if defined(Q_WS_MAC) QString myPluginsDir = "/Users/timsutton/apps/qgis.app/Contents/MacOS/lib/qgis"; #else QString myPluginsDir = "/home/timlinux/apps/lib/qgis"; #endif QgsProviderRegistry::instance(myPluginsDir); // Create the Map Canvas mpMapCanvas= new QgsMapCanvas(0, 0); mpMapCanvas->enableAntiAliasing(true); mpMapCanvas->useImageToRender(false); mpMapCanvas->setCanvasColor(QColor(255, 255, 255)); mpMapCanvas->freeze(false); mpMapCanvas->setVisible(true); mpMapCanvas->refresh(); mpMapCanvas->show(); // Lay our widgets out in the main window mpLayout = new QVBoxLayout(frameMap); mpLayout->addWidget(mpMapCanvas); //create the action behaviours connect(mpActionPan, SIGNAL(triggered()), this, SLOT(panMode())); connect(mpActionZoomIn, SIGNAL(triggered()), this, SLOT(zoomInMode())); connect(mpActionZoomOut, SIGNAL(triggered()), this, SLOT(zoomOutMode())); connect(mpActionAddLayer, SIGNAL(triggered()), this, SLOT(addLayer())); //create a little toolbar mpMapToolBar = addToolBar(tr("File")); mpMapToolBar->addAction(mpActionAddLayer); mpMapToolBar->addAction(mpActionZoomIn); mpMapToolBar->addAction(mpActionZoomOut); mpMapToolBar->addAction(mpActionPan); //create the maptools mpPanTool = new QgsMapToolPan(mpMapCanvas); mpPanTool->setAction(mpActionPan); mpZoomInTool = new QgsMapToolZoom(mpMapCanvas, FALSE); // false = in mpZoomInTool->setAction(mpActionZoomIn); mpZoomOutTool = new QgsMapToolZoom(mpMapCanvas, TRUE ); //true = out mpZoomOutTool->setAction(mpActionZoomOut); }
MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl) : QMainWindow(parent,fl) { //required by Qt4 to initialise the ui setupUi(this); // Create the Map Canvas mpMapCanvas= new QgsMapCanvas(0, 0); mpMapCanvas->enableAntiAliasing(true); mpMapCanvas->useImageToRender(false); mpMapCanvas->setCanvasColor(QColor(255, 255, 255)); mpMapCanvas->freeze(false); mpMapCanvas->setVisible(true); mpMapCanvas->refresh(); mpMapCanvas->show(); // Lay our widgets out in the main window mpLayout = new QVBoxLayout(frameMap); mpLayout->addWidget(mpMapCanvas); //create the action behaviours connect(mpActionPan, SIGNAL(triggered()), this, SLOT(panMode())); connect(mpActionZoomIn, SIGNAL(triggered()), this, SLOT(zoomInMode())); connect(mpActionZoomOut, SIGNAL(triggered()), this, SLOT(zoomOutMode())); connect(mpActionAddLayer, SIGNAL(triggered()), this, SLOT(addLayer())); //create a little toolbar mpMapToolBar = addToolBar(tr("File")); mpMapToolBar->addAction(mpActionAddLayer); mpMapToolBar->addAction(mpActionZoomIn); mpMapToolBar->addAction(mpActionZoomOut); mpMapToolBar->addAction(mpActionPan); //create the maptools mpPanTool = new QgsMapToolPan(mpMapCanvas); mpPanTool->setAction(mpActionPan); mpZoomInTool = new QgsMapToolZoom(mpMapCanvas, FALSE); // false = in mpZoomInTool->setAction(mpActionZoomIn); mpZoomOutTool = new QgsMapToolZoom(mpMapCanvas, TRUE ); //true = out mpZoomOutTool->setAction(mpActionZoomOut); }
void HlpFlightPlannerApp::initApp() { #if defined(Q_WS_MAC) QString pluginPath = "/Users/denis/apps/qgis.app/Contents/MacOS/lib/qgis"; #elif defined(Q_WS_WIN) QString pluginPath = "c:\\hfp\\qgis\plugins"; QString prefixPath = "c:\\hfp\\qgis"; #else QString pluginPath = "/usr/local/lib/qgis/plugins/"; QString prefixPath = "/usr/local"; #endif QgsApplication::setPluginPath( pluginPath ); QgsApplication::setPrefixPath( prefixPath, true); QgsApplication::initQgis(); QSettings settings; settings.setValue( "/qgis/digitizing/marker_only_for_selected", true ); // Central widget QWidget *centralWidget = this->centralWidget(); QGridLayout *centralLayout = new QGridLayout( centralWidget ); centralWidget->setLayout( centralLayout ); centralLayout->setContentsMargins( 0, 0, 0, 0 ); // Map canvas mMapCanvas = new QgsMapCanvas( centralWidget, "theMapCanvas" ); mMapCanvas->setCanvasColor( QColor( 255, 255, 255 ) ); mMapCanvas->setWheelAction( QgsMapCanvas::WheelZoomToMouseCursor, 2 ); centralLayout->addWidget( mMapCanvas, 0, 0, 2, 1 ); connect( mMapCanvas, SIGNAL( mapToolSet( QgsMapTool *, QgsMapTool * ) ), this, SLOT( mapToolChanged( QgsMapTool *, QgsMapTool * ) ) ); // Message bar mInfoBar = new QgsMessageBar( centralWidget ); mInfoBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ); centralLayout->addWidget( mInfoBar, 0, 0, 1, 1 ); // Map manager mMapManager = new HlpMapManager( this ); connect( ui->mActionMapManager, SIGNAL(toggled(bool)), mMapManager, SLOT( setVisible( bool )) ); connect( mMapManager->toggleViewAction(), SIGNAL(toggled(bool)), ui->mActionMapManager, SLOT( setChecked( bool ) ) ); addDockWidget( Qt::LeftDockWidgetArea, mMapManager ); // create map layer registry if doesn't exist QgsMapLayerRegistry::instance(); // CRS mMapCanvas->setCrsTransformEnabled( true ); mMapCanvas->setDestinationCrs( HlpProject::instance()->epsg() ); mMapCanvas->refresh(); QgsMapToPixel test = mMapCanvas->mapSettings().mapToPixel(); // add the layers QMap<QString, QgsMapLayer*> layerList = HlpProject::instance()->createLayers(); if ( layerList.isEmpty() ) { // TODO: what? return; } mFlightlineLayer = dynamic_cast<QgsVectorLayer*>( layerList.value("flightline") ); mProfileLayer = dynamic_cast<QgsVectorLayer*>( layerList.value("profile") ); mWaypointLayer = dynamic_cast<QgsVectorLayer*>( layerList.value("waypoint") ); mFlightlineLayer->startEditing(); mProfileLayer->startEditing(); mWaypointLayer->startEditing(); // layers registries connect( HlpMapRegistry::instance(), SIGNAL(layersChanged(bool)), this, SLOT(setLayerSet(bool)) ); // Map tools mPanTool = new QgsMapToolPan( mMapCanvas ); connect( ui->mActionPan, SIGNAL(triggered()), this, SLOT(panMode())); mPanTool->setAction(ui->mActionPan); mAddProfileTool = new HlpAddProfile( mMapCanvas, mProfileLayer ); connect( ui->mActionAddProfile, SIGNAL( triggered() ), this, SLOT( addProfile() ) ); mAddProfileTool->setAction(ui->mActionAddProfile); // Other actions connect( ui->mActionZoomIn, SIGNAL(triggered()), this, SLOT(zoomIn()) ); connect( ui->mActionZoomOut, SIGNAL(triggered()), this, SLOT(zoomOut()) ); }