Skip to content

Commit a80c30d

Browse files
author
mcoletti
committed
Includes now Qt4 happy. Once again the support vector file formats lives.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4287 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6323525 commit a80c30d

File tree

2 files changed

+190
-3
lines changed

2 files changed

+190
-3
lines changed

providers/ogr/qgsogrprovider.cpp

Lines changed: 175 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ email : sherman at mrcc.com
3535
#include <cpl_error.h>
3636
#include "ogr_api.h"//only for a test
3737

38-
#include <qfile.h>
39-
#include <qmessagebox.h>
40-
#include <qmap.h>
38+
#include <QtDebug>
39+
#include <QFile>
40+
#include <QMessageBox>
41+
#include <QMap>
42+
#include <QString>
4143

4244
//TODO Following ifndef can be removed once WIN32 GEOS support
4345
// is fixed
@@ -1271,6 +1273,176 @@ QString QgsOgrProvider::description() const
12711273

12721274

12731275

1276+
1277+
1278+
/**
1279+
1280+
Convenience function for readily creating file filters.
1281+
1282+
Given a long name for a file filter and a regular expression, return
1283+
a file filter string suitable for use in a QFileDialog::OpenFiles()
1284+
call. The regular express, glob, will have both all lower and upper
1285+
case versions added.
1286+
1287+
@note
1288+
1289+
Copied from qgisapp.cpp.
1290+
1291+
@todo XXX This should probably be generalized and moved to a standard
1292+
utility type thingy.
1293+
1294+
*/
1295+
static QString createFileFilter_(QString const &longName, QString const &glob)
1296+
{
1297+
return "[OGR] " +
1298+
longName + " (" + glob.lower() + " " + glob.upper() + ");;";
1299+
} // createFileFilter_
1300+
1301+
1302+
1303+
1304+
1305+
QGISEXTERN QString fileVectorFilters()
1306+
{
1307+
static QString myFileFilters;
1308+
1309+
// if we've already built the supported vector string, just return what
1310+
// we've already built
1311+
if ( ! ( myFileFilters.isEmpty() || myFileFilters.isNull() ) )
1312+
{
1313+
return myFileFilters;
1314+
}
1315+
1316+
// first get the GDAL driver manager
1317+
1318+
OGRSFDriverRegistrar *driverRegistrar = OGRSFDriverRegistrar::GetRegistrar();
1319+
1320+
if (!driverRegistrar)
1321+
{
1322+
QMessageBox::warning(0,"OGR Driver Manager","unable to get OGRDriverManager");
1323+
return ""; // XXX good place to throw exception if we
1324+
} // XXX decide to do exceptions
1325+
1326+
// then iterate through all of the supported drivers, adding the
1327+
// corresponding file filter
1328+
1329+
OGRSFDriver *driver; // current driver
1330+
1331+
QString driverName; // current driver name
1332+
1333+
// Grind through all the drivers and their respective metadata.
1334+
// We'll add a file filter for those drivers that have a file
1335+
// extension defined for them; the others, welll, even though
1336+
// theoreticaly we can open those files because there exists a
1337+
// driver for them, the user will have to use the "All Files" to
1338+
// open datasets with no explicitly defined file name extension.
1339+
#ifdef QGISDEBUG
1340+
1341+
std::cerr << "Driver count: " << driverRegistrar->GetDriverCount() << std::endl;
1342+
#endif
1343+
1344+
for (int i = 0; i < driverRegistrar->GetDriverCount(); ++i)
1345+
{
1346+
driver = driverRegistrar->GetDriver(i);
1347+
1348+
Q_CHECK_PTR(driver);
1349+
1350+
if (!driver)
1351+
{
1352+
qWarning("unable to get driver %d", i);
1353+
continue;
1354+
}
1355+
1356+
driverName = driver->GetName();
1357+
1358+
1359+
if (driverName.startsWith("ESRI"))
1360+
{
1361+
myFileFilters += createFileFilter_("ESRI Shapefiles", "*.shp");
1362+
}
1363+
else if (driverName.startsWith("UK"))
1364+
{
1365+
// XXX needs file filter extension
1366+
}
1367+
else if (driverName.startsWith("SDTS"))
1368+
{
1369+
myFileFilters += createFileFilter_( "Spatial Data Transfer Standard",
1370+
"*catd.ddf" );
1371+
}
1372+
else if (driverName.startsWith("TIGER"))
1373+
{
1374+
// XXX needs file filter extension
1375+
}
1376+
else if (driverName.startsWith("S57"))
1377+
{
1378+
// XXX needs file filter extension
1379+
}
1380+
else if (driverName.startsWith("MapInfo"))
1381+
{
1382+
myFileFilters += createFileFilter_("MapInfo", "*.mif *.tab");
1383+
// XXX needs file filter extension
1384+
}
1385+
else if (driverName.startsWith("DGN"))
1386+
{
1387+
// XXX needs file filter extension
1388+
}
1389+
else if (driverName.startsWith("VRT"))
1390+
{
1391+
// XXX needs file filter extension
1392+
}
1393+
else if (driverName.startsWith("AVCBin"))
1394+
{
1395+
// XXX needs file filter extension
1396+
}
1397+
else if (driverName.startsWith("REC"))
1398+
{
1399+
// XXX needs file filter extension
1400+
}
1401+
else if (driverName.startsWith("Memory"))
1402+
{
1403+
// XXX needs file filter extension
1404+
}
1405+
else if (driverName.startsWith("Jis"))
1406+
{
1407+
// XXX needs file filter extension
1408+
}
1409+
else if (driverName.startsWith("GML"))
1410+
{
1411+
// XXX not yet supported; post 0.1 release task
1412+
myFileFilters += createFileFilter_( "Geography Markup Language",
1413+
"*.gml" );
1414+
}
1415+
else
1416+
{
1417+
// NOP, we don't know anything about the current driver
1418+
// with regards to a proper file filter string
1419+
qDebug( "%s:%d unknown driver %s", __FILE__, __LINE__, (const char *)driverName.local8Bit() );
1420+
}
1421+
1422+
} // each loaded GDAL driver
1423+
1424+
// can't forget the default case
1425+
1426+
myFileFilters += "All files (*.*)";
1427+
1428+
qDebug() << myFileFilters;
1429+
1430+
return myFileFilters;
1431+
1432+
} // fileVectorFilters() const
1433+
1434+
1435+
1436+
QString QgsOgrProvider::fileVectorFilters() const
1437+
{
1438+
return fileVectorFilters();
1439+
} // QgsOgrProvider::fileVectorFilters() const
1440+
1441+
1442+
1443+
1444+
1445+
12741446
/**
12751447
* Class factory to return a pointer to a newly created
12761448
* QgsOgrProvider object

providers/ogr/qgsogrprovider.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ class QgsOgrProvider:public QgsVectorDataProvider
172172

173173
void setEncoding(const QString& e);
174174

175+
176+
/** return vector file filter string
177+
178+
Returns a string suitable for a QFileDialog of vector file formats
179+
supported by the data provider. Naturally this will be an empty string
180+
for those data providers that do not deal with plain files, such as
181+
databases and servers.
182+
183+
@note
184+
185+
It'd be nice to eventually be raster/vector neutral.
186+
*/
187+
/* virtual */ QString fileVectorFilters() const;
188+
189+
175190
protected:
176191
/** loads fields from input file to member attributeFields */
177192
void loadFields();

0 commit comments

Comments
 (0)