30 changes: 29 additions & 1 deletion qgis/src/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class QPushButton;
#include "splashscreen.h"
#include "qgsconfig.h"
#include "qgsvectordataprovider.h"
#include "qgsclipboard.h"

#include <map>

Expand Down Expand Up @@ -126,6 +127,13 @@ class QgisApp : public QgisAppBase
*/
bool addRasterLayer(QStringList const & theLayerQStringList, bool guiWarning=true);


/** Open a raster layer using the Raster Data Provider.
* Note this is included to support WMS layers only at this stage,
* GDAL layer support via a Provider is not yet implemented.
*/
void addRasterLayer(QString rasterLayerPath, QString baseName, QString providerKey, QStringList layers);


/** open a raster layer for the given file
Expand Down Expand Up @@ -167,14 +175,17 @@ class QgisApp : public QgisAppBase
void setTheme(QString themeName="default");
//! Setup the toolbar popup menus for a given theme
void setupToolbarPopups(QString themeName);

//! Returns a pointer to the internal clipboard
QgsClipboard * clipboard();

private:

//! Add a vector layer to the map
void addLayer();
//! Add a raster layer to the map (will prompt user for filename using dlg
void addRasterLayer();
//! Add a raster layer to the map (passed in as a ptr). It waont force a refresh unless you explicitly
//! Add a raster layer to the map (passed in as a ptr). It won't force a refresh unless you explicitly
//use the force redraw flag.
//
bool addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRedrawFlag=false);
Expand All @@ -188,6 +199,9 @@ class QgisApp : public QgisAppBase
void addDatabaseLayer();
#endif

//! Add a WMS layer to the map
void addWmsLayer();

//! Exit Qgis
void fileExit();

Expand Down Expand Up @@ -235,6 +249,16 @@ class QgisApp : public QgisAppBase
void capturePolygon();
//! activates the selection tool
void select();
//! activates the add node tool
void addVertex();
//! activates the move node tool
void moveVertex();
//! cuts selected features on the active layer to the clipboard
void editCut();
//! copies selected features on the active layer to the clipboard
void editCopy();
//! copies features on the clipboard to the active layer
void editPaste();
//! check to see if file is dirty and if so, prompt the user th save it
int saveDirty();

Expand Down Expand Up @@ -497,6 +521,10 @@ public slots:
bool mMousePrecisionAutomatic;
//! The number of decimal places to use if not automatic
unsigned int mMousePrecisionDecimalPlaces;

/** QGIS-internal vector feature clipboard */
QgsClipboard mInternalClipboard;

//! Flag to indicate how the project properties dialog was summoned
bool mShowProjectionTab;

Expand Down
101 changes: 101 additions & 0 deletions qgis/src/qgsproviderregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,104 @@ QString QgsProviderRegistry::libDirectory()
{
return libDir;
}

// typedef for the QgsDataProvider class factory
typedef QgsDataProvider * create_it(const char * uri);



/** Copied from QgsVectorLayer::setDataProvider
* TODO: Make it work in the generic environment
*
* TODO: Is this class really the best place to put a data provider loader?
* It seems more sensible to provide the code in one place rather than
* in qgsrasterlayer, qgsvectorlayer, serversourceselect, etc.
*/
QgsDataProvider* QgsProviderRegistry::getProvider( QString const & providerKey,
QString const & dataSource )
{
// XXX should I check for and possibly delete any pre-existing providers?
// XXX How often will that scenario occur?

// load the plugin
QString lib = library(providerKey);

#ifdef TESTPROVIDERLIB
const char *cLib = (const char *) lib;

// test code to help debug provider loading problems
// void *handle = dlopen(cLib, RTLD_LAZY);
void *handle = dlopen(cOgrLib, RTLD_LAZY | RTLD_GLOBAL);
if (!handle)
{
std::cout << "Error in dlopen: " << dlerror() << std::endl;

}
else
{
std::cout << "dlopen suceeded" << std::endl;
dlclose(handle);
}

#endif

// load the data provider
QLibrary* myLib = new QLibrary((const char *) lib);
#ifdef QGISDEBUG
std::cout << "QgsProviderRegistry::getRasterProvider: Library name is " << myLib->library() << std::endl;
#endif
bool loaded = myLib->load();

if (loaded)
{
#ifdef QGISDEBUG
std::cout << "QgsProviderRegistry::getProvider: Loaded data provider library" << std::endl;
std::cout << "QgsProviderRegistry::getProvider: Attempting to resolve the classFactory function" << std::endl;
#endif
create_it * classFactory = (create_it *) myLib->resolve("classFactory");

if (classFactory)
{
#ifdef QGISDEBUG
std::cout << "QgsProviderRegistry::getProvider: Getting pointer to a dataProvider object from the library\n";
#endif
//XXX - This was a dynamic cast but that kills the Windows
// version big-time with an abnormal termination error
QgsDataProvider* dataProvider = (QgsDataProvider*)
(classFactory((const char*)(dataSource.utf8())));

if (dataProvider)
{
#ifdef QGISDEBUG
std::cout << "QgsProviderRegistry::getProvider: Instantiated the data provider plugin\n";
#endif
if (dataProvider->isValid())
{
return dataProvider;
}
}
else
{
#ifdef QGISDEBUG
std::cout << "QgsProviderRegistry::getProvider: Unable to instantiate the data provider plugin\n";
#endif
return 0;
}
}
}
else
{
return 0;
#ifdef QGISDEBUG
std::cout << "QgsProviderRegistry::getProvider: Failed to load " << "../providers/libproviders.so" << "\n";
#endif

}

#ifdef QGISDEBUG
std::cout << "QgsProviderRegistry::getProvider: exiting." << "\n";
#endif



} // QgsProviderRegistry::setDataProvider
8 changes: 8 additions & 0 deletions qgis/src/qgsproviderregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

#ifndef QGSPROVIDERREGISTRY_H
#define QGSPROVIDERREGISTRY_H

#include <map>

#include "qgsdataprovider.h"

class QgsProviderMetadata;
class QString;

Expand All @@ -31,6 +35,10 @@ class QgsProviderRegistry
QString pluginList(bool asHtml=false);
QString libDirectory();
void setLibDirectory(QString path);

QgsDataProvider* getProvider( QString const & providerKey,
QString const & dataSource );

protected:
QgsProviderRegistry(const char *pluginPath);
private:
Expand Down