Logo Search packages:      
Sourcecode: qgis version File versions

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

Constructor.

mQgisInterface->setParent(this);

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),
        myHideSplashFlag(false)
{
    //
    // 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..."));
        qApp->processEvents();

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

    // register all GDAL and OGR plug-ins
    OGRRegisterAll();

    QPixmap icon;
    icon = QPixmap(qgis_xpm);
    setIcon(icon);
    // 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..."));
        qApp->processEvents();
    }
    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);
    mMapLegend->addColumn(tr("Layers"));
    mMapLegend->setSorting(-1);
    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
    mOverviewCanvas->setIsOverviewCanvas(true);
    // lock the canvas to prevent user interaction
    mOverviewCanvas->userInteractionAllowed(false);

    // 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));
    mMapCanvas->setMinimumWidth(400);
    canvasLegendLayout->addWidget(canvasLegendSplit, 0, 0);

    mMapLegend->setBackgroundColor(QColor(192, 192, 192));
    mMapLegend->setMapCanvas(mMapCanvas);
    mMapLegend->setResizeMode(QListView::AllColumns);

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

    setCaption(caption);

    //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
    QWhatsThis::whatsThisButton(helpToolbar);

    // Add the empty plugin menu
    mPluginMenu = new QPopupMenu(this);
    // Add the plugin manager action to it
    actionPluginManager->addTo(mPluginMenu);
    // Add separator. Plugins will add their menus to this
    // menu when they are loaded by the plugin manager
    mPluginMenu->insertSeparator();
    // 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);
    ///mQgisInterface->setParent(this);

    // set the legend control for the map canvas
    mMapCanvas->setLegend(mMapLegend);


    // disable functions based on build type
#ifndef HAVE_POSTGRESQL

    actionAddLayer->removeFrom(popupMenuLayers);
    actionAddLayer->removeFrom(DataToolbar);
#endif
    // connect the "cleanup" slot
    connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(saveWindowState()));
    restoreWindowState();

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

    mProgressBar = new QProgressBar(100,this);
    mProgressBar->setMaximumWidth(100);
    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);
    mScaleLabel->setMinimumWidth(100);
    QWhatsThis::add(mScaleLabel, tr("Displays the current map scale"));
    statusBar()->addWidget(mScaleLabel, 0,true);
    mCoordsLabel = new QLabel(QString("Coordinates:"), this);
    mCoordsLabel->setMinimumWidth(200);
    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);
    mRenderSuppresionCBox->setChecked(true);
    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."));
    statusBar()->addWidget(mRenderSuppresionCBox,0,true);

    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..."));
        qApp->processEvents();
    }

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

    mAppDir = PREFIX;
#endif

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

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

    QString plib = PLUGINPATH;
#endif

    mProviderRegistry = QgsProviderRegistry::instance(plib);

#ifdef QGISDEBUG

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

    // load any plugins that were running in the last session
#ifdef QGISDEBUG

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

    restoreSessionPlugins(plib);

    // set the provider plugin path
#ifdef QGISDEBUG

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

    //
    // 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
            (QString)));
    // 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
            (QString)));
    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..."));
        qApp->processEvents();
    }

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

    // set the theme
    setTheme(themeName);
    setupToolbarPopups(themeName);

    // 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()) );
        qApp->processEvents();
    }
    // set the focus to the map canvase
    mMapCanvas->setFocus();


} // QgisApp ctor


Generated by  Doxygen 1.6.0   Back to index