Patch by Didge to load files on application startup by specifying a space separated list of filenames. Vectors supported now, rasters will come tomorrow.

git-svn-id: http://svn.osgeo.org/qgis/trunk@697 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
timlinux 2004-02-05 01:41:04 +00:00
parent 3d259ba65b
commit 0b9c2debd9
3 changed files with 127 additions and 51 deletions

View File

@ -17,6 +17,7 @@
/* $Id$ */
#include <qapplication.h>
#include <qfont.h>
#include <qfile.h>
#include <qstring.h>
#include <qtextcodec.h>
#include <qtranslator.h>
@ -27,7 +28,10 @@
int main(int argc, char *argv[])
{
QString myArgString;
QFile myQFile;
QStringList myVectorFileStringList, myRasterFileStringList;
bool myFileExistsFlag;
QApplication a(argc, argv);
// a.setFont(QFont("helvetica", 11));
@ -35,13 +39,13 @@ int main(int argc, char *argv[])
// set the location where your .qm files are in load() below as the last parameter instead of "."
// for development, use "/" to use the english original as
// .qm files are stored in the base project directory.
if(argc == 2){
QString translation = "qgis_" + QString(argv[1]);
tor.load(translation,".");
}else{
tor.load(QString("qgis_") + QTextCodec::locale(), ".");
}
//tor.load("qgis_go", "." );
if(argc == 2){
QString translation = "qgis_" + QString(argv[1]);
tor.load(translation,".");
}else{
tor.load(QString("qgis_") + QTextCodec::locale(), ".");
}
//tor.load("qgis_go", "." );
a.installTranslator(&tor);
/* uncomment the following line, if you want a Windows 95 look */
//a.setStyle("Windows");
@ -50,6 +54,61 @@ int main(int argc, char *argv[])
a.setMainWidget(qgis);
qgis->show();
//
// autoload any filenames that were passed in on the command line
//
for(int myIteratorInt = 1; myIteratorInt < argc; myIteratorInt++) {
#ifdef DEBUG
printf("%d: %s\n", myIteratorInt, argv[myIteratorInt]);
#endif
myQFile.setName(argv[myIteratorInt]);
myFileExistsFlag = myQFile.open(IO_ReadOnly);
myQFile.close();
if(myFileExistsFlag) {
#ifdef DEBUG
printf("OK\n");
#endif
myArgString = argv[myIteratorInt];
if(myArgString.endsWith(".shp", FALSE)) {
myVectorFileStringList.append(myArgString);
#ifdef DEBUG
printf("Vector count: %d\n",myVectorFileStringList.count());
#endif
} else if (myArgString.endsWith(".adf", FALSE) ||
myArgString.endsWith(".asc", FALSE) ||
myArgString.endsWith(".grd", FALSE) ||
myArgString.endsWith(".img", FALSE) ||
myArgString.endsWith(".tif", FALSE) ||
myArgString.endsWith(".png", FALSE) ||
myArgString.endsWith(".jpg", FALSE) ||
myArgString.endsWith(".dem", FALSE) ||
myArgString.endsWith(".ddf", FALSE)) {
myRasterFileStringList.append(myArgString);
#ifdef DEBUG
printf("Raster count: %d\n",myRasterFileStringList.count());
#endif
}
}
}
#ifdef DEBUG
printf("vCount: %d\n",myVectorFileStringList.count());
printf("rCount: %d\n",myRasterFileStringList.count());
#endif
if(!myVectorFileStringList.isEmpty()) {
#ifdef DEBUG
printf("Loading vector files...\n");
#endif
qgis->addLayer(myVectorFileStringList);
}
if(!myRasterFileStringList.isEmpty()) {
#ifdef DEBUG
printf("Load raster files...\n");
#endif
//todo implement this in qgsrasterlayer.cpp
//qgis->addRasterLayer(myRasterFileStringList);
}
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
//

View File

@ -334,56 +334,67 @@ void QgisApp::about()
}
/** \brief This method prompts the user for a list of vector filenames with a dialog. */
void QgisApp::addLayer()
{
QString pOgr = providerRegistry->library("ogr");
if(pOgr.length() > 0){
mapCanvas->freeze();
QStringList files = QFileDialog::getOpenFileNames(tr("Shapefiles (*.shp);;All files (*.*)"), 0, this, "open files dialog",
tr("Select one or more layers to add"));
addLayer(files);
}
}
/** \brief overloaded vesion of the above method that takes a list of
* filenames instead of prompting user with a dialog. */
void QgisApp::addLayer(QStringList theLayerQStringList)
{
// check to see if we have an ogr provider available
QString pOgr = providerRegistry->library("ogr");
if(pOgr.length() > 0){
mapCanvas->freeze();
QStringList files = QFileDialog::getOpenFileNames(tr("Shapefiles (*.shp);;All files (*.*)"), 0, this, "open files dialog",
tr("Select one or more layers to add"));
QApplication::setOverrideCursor(Qt::WaitCursor);
QStringList::Iterator it = files.begin();
while (it != files.end()) {
mapCanvas->freeze();
QApplication::setOverrideCursor(Qt::WaitCursor);
QStringList::Iterator it = theLayerQStringList.begin();
while (it != theLayerQStringList.end()) {
QFileInfo fi(*it);
QString base = fi.baseName();
QFileInfo fi(*it);
QString base = fi.baseName();
// create the layer
// create the layer
//dp QgsShapeFileLayer *lyr = new QgsShapeFileLayer(*it, base);
QgsVectorLayer *lyr = new QgsVectorLayer(*it, base, "ogr");
//dp QgsShapeFileLayer *lyr = new QgsShapeFileLayer(*it, base);
QgsVectorLayer *lyr = new QgsVectorLayer(*it, base, "ogr");
if (lyr->isValid()) {
// init the context menu so it can connect to slots in main app
lyr->initContextMenu(this);
//add single symbol renderer as default
QgsSingleSymRenderer* renderer=new QgsSingleSymRenderer();
lyr->setRenderer(renderer);
renderer->initializeSymbology(lyr);
mapCanvas->addLayer(lyr);
if (lyr->isValid()) {
// init the context menu so it can connect to slots in main app
lyr->initContextMenu(this);
//add single symbol renderer as default
QgsSingleSymRenderer* renderer=new QgsSingleSymRenderer();
lyr->setRenderer(renderer);
renderer->initializeSymbology(lyr);
mapCanvas->addLayer(lyr);
projectIsDirty = true;
} else {
QString msg = *it + " ";
msg += tr("is not a valid or recognized data source");
QMessageBox::critical(this, tr("Invalid Data Source"), msg);
}
} else {
QString msg = *it + " ";
msg += tr("is not a valid or recognized data source");
QMessageBox::critical(this, tr("Invalid Data Source"), msg);
}
++it;
}
//qApp->processEvents();
// update legend
/*! \todo Need legend scrollview and legenditem classes */
// draw the map
++it;
}
//qApp->processEvents();
// update legend
/*! \todo Need legend scrollview and legenditem classes */
// draw the map
mapLegend->update();
qApp->processEvents();
mapCanvas->freeze(false);
mapCanvas->render2();
QApplication::restoreOverrideCursor();
statusBar()->message(mapCanvas->extent().stringRep());
mapLegend->update();
qApp->processEvents();
mapCanvas->freeze(false);
mapCanvas->render2();
QApplication::restoreOverrideCursor();
statusBar()->message(mapCanvas->extent().stringRep());
}else{
QMessageBox::critical(this, tr("No OGR Provider"),tr("No OGR data provider was found in the QGIS lib directory"));
@ -392,10 +403,9 @@ void QgisApp::addLayer()
}
void
QgisApp::addRasterLayer()
void QgisApp::addRasterLayer()
{
// insure that the map canvas temporarily suspends event processing
// ensure that the map canvas temporarily suspends event processing
// until we've loaded the raster
mapCanvas->freeze();

View File

@ -47,14 +47,21 @@ class QgisApp:public QgisAppBase
QgisApp(QWidget * parent = 0, const char *name = 0, WFlags fl = WType_TopLevel);
~QgisApp();
public:
public:
QgisIface *getInterface();
int getInt();
void addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey);
private:
void addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey);
/** \brief overloaded vesion of the privat addLayer method that takes a list of
* filenames instead of prompting user with a dialog. */
void addLayer(QStringList theLayerQStringList);
/** \brief overloaded vesion of the privat addLRasterayer method that takes a list of
* filenames instead of prompting user with a dialog. */
void addRasterLayer(QStringList theLayerQStringList);
private:
//private:
//public slots:
//! Add a layer to the map
//! Add a vector layer to the map
void addLayer();
//! Add a raster layer to the map
void addRasterLayer();