Logo Search packages:      
Sourcecode: qgis version File versions

QgisApp::QgisApp ( QWidget *  parent = 0,
const char *  name = 0,
WFlags  fl = WType_TopLevel 



Definition at line 304 of file qgisapp.cpp.

References addLayer(), currentLayerChanged(), QgsMapLayerRegistry::instance(), killSplashScreen(), layerProperties(), mAddedLayersHidden, mAppDir, mCoordsLabel, mMapCanvas, mMapLegend, mOverviewCanvas, mPluginMenu, mProgressBar, mRenderSuppresionCBox, mScaleLabel, myHideSplashFlag, removeLayer(), restoreSessionPlugins(), restoreWindowState(), rightClickLegendMenu(), saveWindowState(), QgsMapCanvas::setIsOverviewCanvas(), QgsMapCanvas::setLegend(), QgsLegend::setMapCanvas(), setOverviewZOrder(), setTheme(), setupToolbarPopups(), showMouseCoordinate(), showScale(), and QgsMapCanvas::userInteractionAllowed().

        : QgisAppBase(parent, name, fl),
    // Splash screen global is declared in qgisapp.h header
    QSettings settings;

    myHideSplashFlag = settings.readBoolEntry("/qgis/hideSplash");

    if (!myHideSplashFlag)
        gSplashScreen = new SplashScreen(); //this is supposed to be instantiated in main.cpp but we get segfaults...
        gSplashScreen->setStatus(tr("Loading QGIS..."));

        //  gSplashScreen->setStatus(tr("QGIS ready"));

    // register all GDAL and OGR plug-ins

    QPixmap icon;
    icon = QPixmap(qgis_xpm);
    // store startup location
    QDir *d = new QDir();
    mStartupPath = d->absPath();
    delete d;
    QBitmap zoomincur;
    //  zoomincur = QBitmap(cursorzoomin);
    QBitmap zoomincurmask;
    //  zoomincurmask = QBitmap(cursorzoomin_mask);
    if (!myHideSplashFlag)
        gSplashScreen->setStatus(tr("Setting up QGIS gui..."));
    QGridLayout *canvasLegendLayout = new QGridLayout(frameMain, 1, 1, 4, 6, "canvasLegendLayout");
    QSplitter *canvasLegendSplit = new QSplitter(frameMain);
    QGridLayout *legendOverviewLayout = new QGridLayout(canvasLegendSplit, 1, 2, 4, 6, "canvasLegendLayout");
    QSplitter *legendOverviewSplit = new QSplitter(Qt::Vertical,canvasLegendSplit);
    mMapLegend = new QgsLegend(legendOverviewSplit, "theMapLegend", this);
    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."));

    // "theOverviewCanvas" used to find canonical
    // instance later
    mOverviewCanvas = new QgsMapCanvas(legendOverviewSplit, "theOverviewCanvas");
    QWhatsThis::add(mOverviewCanvas, 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."));
    //tell the overview canvas it is an overview canvas so it will suppress labels etc
    // lock the canvas to prevent user interaction

    // mL = new QScrollView(canvasLegendSplit);

    // add a canvas
    // "theMapCanvas" used to find this canonical
    // instance later
    mMapCanvas = new QgsMapCanvas(canvasLegendSplit, "theMapCanvas" );
    QWhatsThis::add(mMapCanvas, tr("Map canvas. This is where raster and vector layers are displayed when added to the map"));
    // we need to cache the layer registry instance so plugins can get to it
    // now explicitly refer to Singleton -- mLayerRegistry = QgsMapLayerRegistry::instance();
    // resize it to fit in the frame
    //    QRect r = frmCanvas->rect();
    //    canvas->resize(r.width(), r.height());
    mMapCanvas->setBackgroundColor(Qt::white); //QColor (220, 235, 255));
    canvasLegendLayout->addWidget(canvasLegendSplit, 0, 0);

    mMapLegend->setBackgroundColor(QColor(192, 192, 192));

    QString caption = tr("Quantum GIS - ");
    caption += QString("%1 ('%2')").arg(QGis::qgisVersion).arg(QGis::qgisReleaseName);


    //signal when mouse moved over window (coords display in status bar)
    connect(mMapCanvas, SIGNAL(xyCoordinates(QgsPoint &)), this, SLOT(showMouseCoordinate(QgsPoint &)));
    //signal when mouse in capturePoint mode and mouse clicked on canvas
    connect(mMapCanvas, SIGNAL(xyClickCoordinates(QgsPoint &)), this, SLOT(showCapturePointCoordinate(QgsPoint &)));
    connect(mMapCanvas, SIGNAL(setProgress(int,int)), this, SLOT(showProgress(int,int)));
    connect(mMapCanvas, SIGNAL(extentsChanged(QgsRect )),this,SLOT(showExtents(QgsRect )));
    connect(mMapCanvas, SIGNAL(scaleChanged(QString)), this, SLOT(showScale(QString)));
    connect(mMapCanvas, SIGNAL(addedLayer(QgsMapLayer *)), mMapLegend, SLOT(addLayer(QgsMapLayer *)));
    connect(mMapCanvas, SIGNAL(removedLayer(QString)), mMapLegend, SLOT(removeLayer(QString)));
    connect(mMapCanvas, SIGNAL(removedAll()), mMapLegend, SLOT(removeAll()));

    connect(mMapLegend, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(layerProperties(QListViewItem *)));
    connect(mMapLegend, SIGNAL(rightButtonPressed(QListViewItem *, const QPoint &, int)),
            this, SLOT(rightClickLegendMenu(QListViewItem *, const QPoint &, int)));
    connect(mMapLegend, SIGNAL(zOrderChanged(QgsLegend *)), mMapCanvas, SLOT(setZOrderFromLegend(QgsLegend *)));
    connect(mMapLegend, SIGNAL(zOrderChanged(QgsLegend *)), this, SLOT(setOverviewZOrder(QgsLegend *)));
    connect(mMapLegend, SIGNAL(currentChanged(QListViewItem *)), this, SLOT(currentLayerChanged(QListViewItem *)));

    // Add the whats this toolbar button
    //TODO Fix this ToolBar pointer to be named consistently

    // Add the empty plugin menu
    mPluginMenu = new QPopupMenu(this);
    // Add the plugin manager action to it
    // Add separator. Plugins will add their menus to this
    // menu when they are loaded by the plugin manager
    // Add to the menubar
    menuBar()->insertItem(tr("&Plugins"), mPluginMenu, -1, menuBar()->count() - 1);

    // create the layer popup menu
    mMapCursor = 0;

    // create the interfce
    mQgisInterface = new QgisIface(this);

    // set the legend control for the map canvas

    // disable functions based on build type

    // connect the "cleanup" slot
    connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(saveWindowState()));

    // Add a panel to the status bar for the scale, coords and progress
    // And also rendering suppression checkbox

    mProgressBar = new QProgressBar(100,this);
    QWhatsThis::add(mProgressBar, tr("Progress bar that displays the status of rendering layers and other time-intensive operations"));
    statusBar()->addWidget(mProgressBar, 1,true);
    mScaleLabel = new QLabel(QString("Scale"),this);
    QWhatsThis::add(mScaleLabel, tr("Displays the current map scale"));
    statusBar()->addWidget(mScaleLabel, 0,true);
    mCoordsLabel = new QLabel(QString("Coordinates:"), this);
    QWhatsThis::add(mCoordsLabel, tr("Shows the map coordinates at the current cursor postion. The display is continuously updated as the mouse is moved."));
    statusBar()->addWidget(mCoordsLabel, 0, true);
    mRenderSuppresionCBox = new QCheckBox(tr("Render"),this);
    QWhatsThis::add(mRenderSuppresionCBox, 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."));

    connect(mRenderSuppresionCBox, SIGNAL(toggled(bool )),
            mMapCanvas, SLOT(setRenderFlag(bool)));
    connect(mRenderSuppresionCBox, SIGNAL(toggled(bool )),
            mOverviewCanvas, SLOT(setRenderFlag(bool)));

    // Create the plugin registry and load plugins

    if (! myHideSplashFlag)
        gSplashScreen->setStatus(tr("Loading plugins..."));

    // store the application dir
#if defined(WIN32) || defined(Q_OS_MACX)
    mAppDir = qApp->applicationDirPath();

    mAppDir = PREFIX;

    // Get pointer to the provider registry singleton
#if defined(WIN32) || defined(Q_OS_MACX)

    QString plib = mAppDir + "/lib/qgis";

    QString plib = PLUGINPATH;

    mProviderRegistry = QgsProviderRegistry::instance(plib);


    std::cout << "Plugins are installed in " << plib << std::endl;

    // load any plugins that were running in the last session

    std::cerr << "About to restore plugins session" << std::endl;


    // set the provider plugin path

    std::cout << "Setting plugin lib dir to " << plib << std::endl;

    // Create the map layer registry. Any layers loaded will
    // register themselves here. Deleting layers shouls ONLY
    // be done by means of a removeMapLayer call to the regsitry.
    // This allows a single layer instance to be shared
    // between more than one canvas. The registry is a singleton
    // and is constructed using the static instance call.

    // syntactic sugar shortcut for instance handle
    QgsMapLayerRegistry * mapLayerRegistry = QgsMapLayerRegistry::instance();

    //connect the legend, mapcanvas and overview canvas to the registry
    connect(mapLayerRegistry, SIGNAL(layerWillBeRemoved(QString)), mMapCanvas, SLOT(remove
    // XXX following not necessary because canvas will notify its legend; I think
    // connect(mapLayerRegistry, SIGNAL(layerWillBeRemoved(QString)), mMapLegend, SLOT(removeLayer(QString)));
    connect(mapLayerRegistry, SIGNAL(layerWillBeRemoved(QString)), mOverviewCanvas, SLOT(remove
    connect(mapLayerRegistry, SIGNAL(removedAll()), mOverviewCanvas, SLOT(removeAll()));
    connect(mapLayerRegistry, SIGNAL(removedAll()), mMapCanvas, SLOT(removeAll()));

    connect(mapLayerRegistry, SIGNAL(layerWasAdded(QgsMapLayer*)), mMapCanvas, SLOT(addLayer(QgsMapLayer *)));
    connect(mapLayerRegistry, SIGNAL(layerWasAdded(QgsMapLayer*)), mOverviewCanvas, SLOT(addLayer(QgsMapLayer *)));

    if (! myHideSplashFlag)
        gSplashScreen->setStatus(tr("Setting theme..."));

    // get the users theme preference from the settings
    QString themeName = settings.readEntry("/qgis/theme","default");

    // set the theme

    // Set the initial visibility flag for layers
    // This user option allows the user to turn off inital drawing of
    // layers when they are added to the map. This is useful when adding
    // many layers and the user wants to adjusty symbology, etc prior to
    // actually viewing the layer.
    mAddedLayersHidden = settings.readBoolEntry("/qgis/new_layers_visible", true);

    if (! myHideSplashFlag)
        gSplashScreen->setStatus(tr("QGIS Ready"));

        // Set up the timer so the splash screen stays up for
        // another 1 seconds, then kill it.
        QTimer::singleShot( 1000, this, SLOT(killSplashScreen()) );
    // set the focus to the map canvase

} // QgisApp ctor

Generated by  Doxygen 1.6.0   Back to index