Logo Search packages:      
Sourcecode: qgis version File versions

bool QgisApp::addRasterLayer ( QStringList const &  theLayerQStringList,
bool  guiWarning = true 
)

overloaded vesion of the private addRasterLayer()

Method that takes a list of filenames instead of prompting user with a dialog.

Returns:
true if successfully added layer(s)
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.

Definition at line 3981 of file qgisapp.cpp.

References addRasterLayer(), QgsMapCanvas::extent(), QgsMapCanvas::freeze(), QgsRasterLayer::isValidRasterFileName(), mAddedLayersHidden, mMapCanvas, mOverviewCanvas, QgsMapLayer::setVisible(), and QgsRect::stringRep().

Referenced by QgisIface::addRasterLayer().

{
    if (theFileNameQStringList.empty())
    {
        // no files selected so bail out, but
        // allow mMapCanvas to handle events
        // first
        mMapCanvas->freeze(false);
        mOverviewCanvas->freeze(false);
        return false;
    }

    mMapCanvas->freeze(true);
    mOverviewCanvas->freeze(true);

    QApplication::setOverrideCursor(Qt::WaitCursor);
    // this is messy since some files in the list may be rasters and others may
    // be ogr layers. We'll set returnValue to false if one or more layers fail
    // to load.
    bool returnValue = true;
    for (QStringList::ConstIterator myIterator = theFileNameQStringList.begin();
            myIterator != theFileNameQStringList.end();
            ++myIterator)
    {
        if (QgsRasterLayer::isValidRasterFileName(*myIterator))
        {
            QFileInfo myFileInfo(*myIterator);
            // get the directory the .adf file was in
            QString myDirNameQString = myFileInfo.dirPath();
            QString myBaseNameQString = myFileInfo.baseName();
            //only allow one copy of a ai grid file to be loaded at a
            //time to prevent the user selecting all adfs in 1 dir which
            //actually represent 1 coverage,

            // create the layer
            QgsRasterLayer *layer = new QgsRasterLayer(*myIterator, myBaseNameQString);

            // set initial visibility based on user preference
            layer->setVisible(mAddedLayersHidden);

            addRasterLayer(layer);

            //only allow one copy of a ai grid file to be loaded at a
            //time to prevent the user selecting all adfs in 1 dir which
            //actually represent 1 coverate,

            if (myBaseNameQString.lower().endsWith(".adf"))
            {
                break;
            }
        }
        else
        {
            // Issue message box warning unless we are loading from cmd line since
            // non-rasters are passed to this function first and then sucessfully
            // loaded afterwards (see main.cpp)

            if(guiWarning)
            {
                QString msg(*myIterator + " is not a supported raster data source");
                QMessageBox::critical(this, "Unsupported Data Source", msg);
            }
            returnValue = false;
        }
    }

    statusBar()->message(mMapCanvas->extent().stringRep(2));
    mMapCanvas->freeze(false);
    mOverviewCanvas->freeze(false);
    QApplication::restoreOverrideCursor();

    return returnValue;

}// QgisApp::addRasterLayer()


Generated by  Doxygen 1.6.0   Back to index