Logo Search packages:      
Sourcecode: qgis version File versions

bool QgisApp::addLayer ( QStringList const &  theLayerQStringList  ) 

overloaded vesion of the privat addLayer method that takes a list of filenames instead of prompting user with a dialog.

overloaded vesion of the above method that takes a list of filenames instead of prompting user with a dialog.

Returns:
true if successfully added layer
Note:
This should be deprecated because it's possible to have a heterogeneous set of files; i.e., a mix of raster and vector. It's much better to try to just open one file at a time.

XXX yah know, this could be changed to just iteratively call the above

Todo:
Need legend scrollview and legenditem classes

Definition at line 1158 of file qgisapp.cpp.

References QgsMapLayerRegistry::addMapLayer(), QgsMapCanvas::extent(), QgsMapCanvas::freeze(), QgsSingleSymRenderer::initializeSymbology(), QgsMapLayerRegistry::instance(), QgsVectorLayer::isValid(), keyPressed(), mAddedLayersHidden, mMapCanvas, mOverviewCanvas, QgsMapCanvas::render(), QgsVectorLayer::setRenderer(), QgsMapLayer::setVisible(), and QgsRect::stringRep().

{
    // check to see if we have an ogr provider available
    QString pOgr = mProviderRegistry->library("ogr");

    if ( pOgr.isEmpty() )
    {
        QMessageBox::critical(this,
                              tr("No OGR Provider"),
                              tr("No OGR data provider was found in the QGIS lib directory"));
        return false;
    }
    else
    {
        mMapCanvas->freeze();

        QApplication::setOverrideCursor(Qt::WaitCursor);


        for ( QStringList::ConstIterator it = theLayerQStringList.begin();
                it != theLayerQStringList.end();
                ++it )
        {
            QFileInfo fi(*it);
            QString base = fi.baseName();


            // create the layer

            QgsVectorLayer *layer = new QgsVectorLayer(*it, base, "ogr");

            Q_CHECK_PTR( layer );
            // set the visibility based on user preference for newly added
            // layers
            layer->setVisible(mAddedLayersHidden);

            if ( ! layer )
            {
                mMapCanvas->freeze(false);
                QApplication::restoreOverrideCursor();

                // XXX insert meaningful whine to the user here
                return false;
            }

            if (layer->isValid())
            {
                //Register the layer with the layer registry
                QgsMapLayerRegistry::instance()->addMapLayer(layer);
                // init the context menu so it can connect to slots
                // in main app

                // XXX now taken care of in legend layer->initContextMenu(this);

                //add single symbol renderer as default
                QgsSingleSymRenderer *renderer = new QgsSingleSymRenderer();

                Q_CHECK_PTR( renderer );

                if ( ! renderer )
                {
                    mMapCanvas->freeze(false);
                    QApplication::restoreOverrideCursor();

                    // XXX insert meaningful whine to the user here
                    return false;
                }

                layer->setRenderer(renderer);
                renderer->initializeSymbology(layer);

                // map canvas and overview canvas already know about this layer
                // when it is added to map registry
                //              mMapCanvas->addLayer(layer);
                //              // XXX some day use other means to  connect up a request from the raster layer to show in overview map
                //              QObject::connect(layer,
                //                      SIGNAL(showInOverview(QString,bool)),
                //                      this,
                //                      SLOT(setLayerOverviewStatus(QString,bool)));

                // connect up any keypresses to be passed tot he layer (e.g. so esc can stop rendering)
#ifdef QGISDEBUG
  std::cout << " Connecting up maplayers keyPressed event to the QgisApp keyPress signal" << std::endl;
#endif
                QObject::connect(this,
                                 SIGNAL(keyPressed(QKeyEvent *)),
                                 layer,
                                 SLOT(keyPressed(QKeyEvent* )));
            //add hooks for letting layer know canvas needs to recalc the layer extents
            QObject::connect(layer,
                             SIGNAL(recalculateExtents()),
                             mMapCanvas,
                             SLOT(recalculateExtents()));

            QObject::connect(layer,
                             SIGNAL(recalculateExtents()),
                             mOverviewCanvas,
                             SLOT(recalculateExtents()));
            }
            else
            {
                QString msg = *it + " ";
                msg += tr("is not a valid or recognized data source");
                QMessageBox::critical(this, tr("Invalid Data Source"), msg);

                // since the layer is bad, stomp on it
                delete layer;

                // XXX should we return false here, or just grind through
                // XXX the remaining arguments?
            }

        }

        //qApp->processEvents();
        // update legend
        /*! \todo Need legend scrollview and legenditem classes */
        // draw the map

        // mMapLegend->update(); NOW UPDATED VIA SIGNAL/SLOTS
        qApp->processEvents();    // XXX why does this need to be called manually?
        mMapCanvas->freeze(false);
        mMapCanvas->render();
        QApplication::restoreOverrideCursor();
        statusBar()->message(mMapCanvas->extent().stringRep(2));

    }

    return true;

} // QgisApp::addLayer()


Generated by  Doxygen 1.6.0   Back to index