mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Merge branch 'master' of github.com:qgis/Quantum-GIS
This commit is contained in:
commit
feaa671e27
@ -269,7 +269,7 @@ void QgsBrowserDockWidget::refreshModel( const QModelIndex& index )
|
||||
for ( int i = 0 ; i < mModel->rowCount( index ); i++ )
|
||||
{
|
||||
QModelIndex idx = mModel->index( i, 0, index );
|
||||
if ( mBrowserView->isExpanded( idx ) )
|
||||
if ( mBrowserView->isExpanded( idx ) || !mModel->hasChildren( idx ) )
|
||||
{
|
||||
refreshModel( idx );
|
||||
}
|
||||
|
@ -531,7 +531,7 @@ void QgsBrowser::refresh( const QModelIndex& index )
|
||||
for ( int i = 0 ; i < mModel->rowCount( index ); i++ )
|
||||
{
|
||||
QModelIndex idx = mModel->index( i, 0, index );
|
||||
if ( treeView->isExpanded( idx ) )
|
||||
if ( treeView->isExpanded( idx ) || !mModel->hasChildren( idx ) )
|
||||
{
|
||||
refresh( idx );
|
||||
}
|
||||
|
@ -565,3 +565,16 @@ void QgsDirectoryParamWidget::showHideColumn()
|
||||
}
|
||||
settings.setValue( "/dataitem/directoryHiddenColumns", lst );
|
||||
}
|
||||
|
||||
|
||||
QgsErrorItem::QgsErrorItem( QgsDataItem* parent, QString error, QString path )
|
||||
: QgsDataItem( QgsDataItem::Error, parent, error, path )
|
||||
{
|
||||
mIcon = QIcon( getThemePixmap( "/mIconDelete.png" ) );
|
||||
|
||||
mPopulated = true; // no more children
|
||||
}
|
||||
|
||||
QgsErrorItem::~QgsErrorItem()
|
||||
{
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ class CORE_EXPORT QgsDataItem : public QObject
|
||||
Collection,
|
||||
Directory,
|
||||
Layer,
|
||||
Error,
|
||||
};
|
||||
|
||||
QgsDataItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path );
|
||||
@ -225,6 +226,24 @@ class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
|
||||
static QVector<QLibrary*> mLibraries;
|
||||
};
|
||||
|
||||
/**
|
||||
Data item that can be used to report problems (e.g. network error)
|
||||
*/
|
||||
class CORE_EXPORT QgsErrorItem : public QgsDataItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
QgsErrorItem( QgsDataItem* parent, QString error, QString path );
|
||||
~QgsErrorItem();
|
||||
|
||||
//QVector<QgsDataItem*> createChildren();
|
||||
//virtual bool equal( const QgsDataItem *other );
|
||||
};
|
||||
|
||||
|
||||
// ---------
|
||||
|
||||
class QgsDirectoryParamWidget : public QTreeWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -762,9 +762,15 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
|
||||
case QgsVectorLayer::FileName:
|
||||
case QgsVectorLayer::Calendar:
|
||||
{
|
||||
QLineEdit *le = editor->findChild<QLineEdit *>();
|
||||
if ( le == NULL )
|
||||
QLineEdit* le = qobject_cast<QLineEdit*>( editor );
|
||||
if( !le )
|
||||
{
|
||||
le = editor->findChild<QLineEdit *>();
|
||||
}
|
||||
if ( !le )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
le->setText( value.toString() );
|
||||
}
|
||||
break;
|
||||
|
@ -42,6 +42,25 @@ QgsConfigParser::~QgsConfigParser()
|
||||
{
|
||||
delete it.value();
|
||||
}
|
||||
|
||||
//remove the temporary files
|
||||
for ( QList<QTemporaryFile*>::const_iterator it = mFilesToRemove.constBegin(); it != mFilesToRemove.constEnd(); ++it )
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
|
||||
//and also those the temporary file paths
|
||||
for ( QList<QString>::const_iterator it = mFilePathsToRemove.constBegin(); it != mFilePathsToRemove.constEnd(); ++it )
|
||||
{
|
||||
QFile::remove( *it );
|
||||
}
|
||||
|
||||
//delete the layers in the list
|
||||
QList<QgsMapLayer*>::iterator layer_it = mLayersToRemove.begin();
|
||||
for ( ; layer_it != mLayersToRemove.end(); ++layer_it )
|
||||
{
|
||||
delete *layer_it;
|
||||
}
|
||||
}
|
||||
|
||||
void QgsConfigParser::setDefaultLegendSettings()
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <QFont>
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
class QgsComposition;
|
||||
class QgsComposerLabel;
|
||||
@ -41,8 +42,9 @@ class QgsConfigParser
|
||||
virtual void layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const = 0;
|
||||
|
||||
/**Returns one or possibly several maplayers for a given layer name and style. If there are several layers, the layers should be drawn in inverse list order.
|
||||
If no layers/style are found, an empty list is returned*/
|
||||
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool allowCaching = true ) const = 0;
|
||||
If no layers/style are found, an empty list is returned
|
||||
@param allowCache true if layer can be read from / written to cache*/
|
||||
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool useCache = true ) const = 0;
|
||||
|
||||
/**Returns number of layers in configuration*/
|
||||
virtual int numberOfLayers() const = 0;
|
||||
@ -124,6 +126,17 @@ class QgsConfigParser
|
||||
/**List of GML datasets passed outside SLD (e.g. in a SOAP request). Key of the map is the layer name*/
|
||||
QMap<QString, QDomDocument*> mExternalGMLDatasets;
|
||||
|
||||
//todo: leave this to the layer cash?
|
||||
/**Stores pointers to layers that have to be removed in the destructor of QgsSLDParser*/
|
||||
mutable QList<QgsMapLayer*> mLayersToRemove;
|
||||
|
||||
/**Stores the temporary file objects. The class takes ownership of the objects and deletes them in the destructor*/
|
||||
mutable QList<QTemporaryFile*> mFilesToRemove;
|
||||
|
||||
/**Stores paths of files that need to be removed after each request (necessary because of contours shapefiles that \
|
||||
cannot be handles with QTemporaryFile*/
|
||||
mutable QList<QString> mFilePathsToRemove;
|
||||
|
||||
/**Layer font for GetLegendGraphics*/
|
||||
QFont mLegendLayerFont;
|
||||
/**Item font for GetLegendGraphics*/
|
||||
|
@ -44,6 +44,35 @@ QgsProjectParser::QgsProjectParser( QDomDocument* xmlDoc, const QString& filePat
|
||||
mOutputUnits = QgsMapRenderer::Millimeters;
|
||||
setLegendParametersFromProject();
|
||||
setSelectionColor();
|
||||
|
||||
//accelerate search for layers and groups
|
||||
if ( mXMLDoc )
|
||||
{
|
||||
QDomNodeList layerNodeList = mXMLDoc->elementsByTagName( "maplayer" );
|
||||
QDomElement currentElement;
|
||||
int nNodes = layerNodeList.size();
|
||||
for ( int i = 0; i < nNodes; ++i )
|
||||
{
|
||||
currentElement = layerNodeList.at( i ).toElement();
|
||||
mProjectLayerElements.push_back( currentElement );
|
||||
mProjectLayerElementsByName.insert( layerName( currentElement ), currentElement );
|
||||
mProjectLayerElementsById.insert( layerId( currentElement ), currentElement );
|
||||
}
|
||||
|
||||
QDomElement legendElement = mXMLDoc->documentElement().firstChildElement( "legend" );
|
||||
if ( !legendElement.isNull() )
|
||||
{
|
||||
QDomNodeList groupNodeList = legendElement.elementsByTagName( "legendgroup" );
|
||||
for ( int i = 0; i < groupNodeList.size(); ++i )
|
||||
{
|
||||
mLegendGroupElements.push_back( groupNodeList.at( i ).toElement() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QgsProjectParser::QgsProjectParser(): mXMLDoc( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
QgsProjectParser::~QgsProjectParser()
|
||||
@ -53,25 +82,22 @@ QgsProjectParser::~QgsProjectParser()
|
||||
|
||||
int QgsProjectParser::numberOfLayers() const
|
||||
{
|
||||
QList<QDomElement> layerElems = projectLayerElements();
|
||||
return layerElems.size();
|
||||
return mProjectLayerElements.size();
|
||||
}
|
||||
|
||||
void QgsProjectParser::layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
|
||||
{
|
||||
QList<QDomElement> layerElems = projectLayerElements();
|
||||
|
||||
QStringList nonIdentifiableLayers = identifyDisabledLayers();
|
||||
|
||||
if ( layerElems.size() < 1 )
|
||||
if ( mProjectLayerElements.size() < 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QMap<QString, QgsMapLayer *> layerMap;
|
||||
|
||||
QList<QDomElement>::const_iterator layerIt = layerElems.constBegin();
|
||||
for ( ; layerIt != layerElems.constEnd(); ++layerIt )
|
||||
QList<QDomElement>::const_iterator layerIt = mProjectLayerElements.constBegin();
|
||||
for ( ; layerIt != mProjectLayerElements.constEnd(); ++layerIt )
|
||||
{
|
||||
QgsMapLayer *layer = createLayerFromElement( *layerIt );
|
||||
if ( layer )
|
||||
@ -151,9 +177,8 @@ void QgsProjectParser::addLayers( QDomDocument &doc,
|
||||
QStringList pIdDisabled = p->identifyDisabledLayers();
|
||||
|
||||
QDomElement embeddedGroupElem;
|
||||
QList<QDomElement> pLegendElems = p->legendGroupElements();
|
||||
QList<QDomElement>::const_iterator pLegendIt = pLegendElems.constBegin();
|
||||
for ( ; pLegendIt != pLegendElems.constEnd(); ++pLegendIt )
|
||||
QList<QDomElement>::const_iterator pLegendIt = mLegendGroupElements.constBegin();
|
||||
for ( ; pLegendIt != mLegendGroupElements.constEnd(); ++pLegendIt )
|
||||
{
|
||||
if ( pLegendIt->attribute( "name" ) == embeddedGroupName )
|
||||
{
|
||||
@ -162,10 +187,9 @@ void QgsProjectParser::addLayers( QDomDocument &doc,
|
||||
}
|
||||
}
|
||||
|
||||
QList<QDomElement> pLayerElems = p->projectLayerElements();
|
||||
QMap<QString, QgsMapLayer *> pLayerMap;
|
||||
QList<QDomElement>::const_iterator pLayerIt = pLayerElems.constBegin();
|
||||
for ( ; pLayerIt != pLayerElems.constEnd(); ++pLayerIt )
|
||||
QList<QDomElement>::const_iterator pLayerIt = mProjectLayerElements.constBegin();
|
||||
for ( ; pLayerIt != mProjectLayerElements.constEnd(); ++pLayerIt )
|
||||
{
|
||||
pLayerMap.insert( layerId( *pLayerIt ), p->createLayerFromElement( *pLayerIt ) );
|
||||
}
|
||||
@ -299,18 +323,28 @@ void QgsProjectParser::combineExtentAndCrsOfGroupChildren( QDomElement& groupEle
|
||||
appendLayerBoundingBoxes( groupElem, doc, combinedBBox, groupCRS );
|
||||
}
|
||||
|
||||
QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, const QString& styleName, bool allowCaching ) const
|
||||
QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, const QString& styleName, bool useCache ) const
|
||||
{
|
||||
Q_UNUSED( styleName );
|
||||
Q_UNUSED( allowCaching );
|
||||
Q_UNUSED( useCache );
|
||||
QList<QgsMapLayer*> layerList;
|
||||
|
||||
//first assume lName refers to a leaf layer
|
||||
QMap< QString, QDomElement > layerElemMap = projectLayerElementsByName();
|
||||
QMap< QString, QDomElement >::const_iterator layerElemIt = layerElemMap.find( lName );
|
||||
if ( layerElemIt != layerElemMap.constEnd() )
|
||||
//Check if layer name refers to the top level group for the project.
|
||||
if ( lName == projectTitle() )
|
||||
{
|
||||
QgsMapLayer* layer = createLayerFromElement( layerElemIt.value() );
|
||||
QList<QDomElement>::const_iterator layerElemIt = mProjectLayerElements.constBegin();
|
||||
for ( ; layerElemIt != mProjectLayerElements.constEnd(); ++layerElemIt )
|
||||
{
|
||||
layerList.push_back( createLayerFromElement( *layerElemIt, useCache ) );
|
||||
}
|
||||
return layerList;
|
||||
}
|
||||
|
||||
//does lName refer to a leaf layer
|
||||
QHash< QString, QDomElement >::const_iterator layerElemIt = mProjectLayerElementsByName.find( lName );
|
||||
if ( layerElemIt != mProjectLayerElementsByName.constEnd() )
|
||||
{
|
||||
QgsMapLayer* layer = createLayerFromElement( layerElemIt.value(), useCache );
|
||||
if ( layer )
|
||||
{
|
||||
layerList.push_back( layer );
|
||||
@ -318,24 +352,9 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
|
||||
}
|
||||
}
|
||||
|
||||
//Check if layer name refers to the top level group for the project.
|
||||
if ( lName == projectTitle() )
|
||||
{
|
||||
QList<QDomElement> layerElemList = projectLayerElements();
|
||||
QList<QDomElement>::const_iterator layerElemIt = layerElemList.constBegin();
|
||||
for ( ; layerElemIt != layerElemList.constEnd(); ++layerElemIt )
|
||||
{
|
||||
layerList.push_back( createLayerFromElement( *layerElemIt ) );
|
||||
}
|
||||
return layerList;
|
||||
}
|
||||
|
||||
//maybe the layer is a goup. Check if lName is contained in the group list
|
||||
QMap< QString, QDomElement > idLayerMap = projectLayerElementsById();
|
||||
|
||||
QList<QDomElement> legendGroups = legendGroupElements();
|
||||
QList<QDomElement>::const_iterator groupIt = legendGroups.constBegin();
|
||||
for ( ; groupIt != legendGroups.constEnd(); ++groupIt )
|
||||
QList<QDomElement>::const_iterator groupIt = mLegendGroupElements.constBegin();
|
||||
for ( ; groupIt != mLegendGroupElements.constEnd(); ++groupIt )
|
||||
{
|
||||
if ( groupIt->attribute( "name" ) == lName )
|
||||
{
|
||||
@ -346,11 +365,10 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
|
||||
QgsProjectParser* p = dynamic_cast<QgsProjectParser*>( QgsConfigCache::instance()->searchConfiguration( project ) );
|
||||
if ( p )
|
||||
{
|
||||
QList<QDomElement> pGroupElems = p->legendGroupElements();
|
||||
QList<QDomElement>::const_iterator pGroupIt = pGroupElems.constBegin();
|
||||
QList<QDomElement>::const_iterator pGroupIt = mLegendGroupElements.constBegin();
|
||||
QDomElement embeddedGroupElem;
|
||||
|
||||
for ( ; pGroupIt != pGroupElems.constEnd(); ++pGroupIt )
|
||||
for ( ; pGroupIt != mLegendGroupElements.constEnd(); ++pGroupIt )
|
||||
{
|
||||
if ( pGroupIt->attribute( "name" ) == lName )
|
||||
{
|
||||
@ -362,12 +380,11 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
|
||||
if ( !embeddedGroupElem.isNull() )
|
||||
{
|
||||
//add all the layers under the group
|
||||
QMap< QString, QDomElement > pLayerElems = p->projectLayerElementsById();
|
||||
QDomNodeList pLayerNodes = embeddedGroupElem.elementsByTagName( "legendlayer" );
|
||||
for ( int i = 0; i < pLayerNodes.size(); ++i )
|
||||
{
|
||||
QString pLayerId = pLayerNodes.at( i ).toElement().firstChildElement( "filegroup" ).firstChildElement( "legendlayerfile" ).attribute( "layerid" );
|
||||
QgsMapLayer* pLayer = p->createLayerFromElement( pLayerElems[pLayerId] );
|
||||
QgsMapLayer* pLayer = p->createLayerFromElement( mProjectLayerElementsById[pLayerId], useCache );
|
||||
if ( pLayer )
|
||||
{
|
||||
layerList.push_back( pLayer );
|
||||
@ -381,10 +398,10 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
|
||||
QDomNodeList layerFileList = groupIt->elementsByTagName( "legendlayerfile" );
|
||||
for ( int i = 0; i < layerFileList.size(); ++i )
|
||||
{
|
||||
QMap< QString, QDomElement >::const_iterator layerEntry = idLayerMap.find( layerFileList.at( i ).toElement().attribute( "layerid" ) );
|
||||
if ( layerEntry != idLayerMap.constEnd() )
|
||||
QHash< QString, QDomElement >::const_iterator layerEntry = mProjectLayerElementsById.find( layerFileList.at( i ).toElement().attribute( "layerid" ) );
|
||||
if ( layerEntry != mProjectLayerElementsById.constEnd() )
|
||||
{
|
||||
layerList.push_back( createLayerFromElement( layerEntry.value() ) );
|
||||
layerList.push_back( createLayerFromElement( layerEntry.value(), useCache ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -393,8 +410,8 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
|
||||
}
|
||||
|
||||
//maybe the layer is embedded from another project
|
||||
QMap< QString, QDomElement >::const_iterator layerIt = idLayerMap.constBegin();
|
||||
for ( ; layerIt != idLayerMap.constEnd(); ++layerIt )
|
||||
QHash< QString, QDomElement >::const_iterator layerIt = mProjectLayerElementsById.constBegin();
|
||||
for ( ; layerIt != mProjectLayerElementsById.constEnd(); ++layerIt )
|
||||
{
|
||||
if ( layerIt.value().attribute( "embedded" ) == "1" )
|
||||
{
|
||||
@ -407,13 +424,12 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
|
||||
if ( otherParser )
|
||||
{
|
||||
//get element by id
|
||||
QMap< QString, QDomElement > otherLayerElems = otherParser->projectLayerElementsById();
|
||||
QMap< QString, QDomElement >::const_iterator otherLayerIt = otherLayerElems.find( id );
|
||||
if ( otherLayerIt != otherLayerElems.constEnd() )
|
||||
QHash< QString, QDomElement >::const_iterator otherLayerIt = otherParser->mProjectLayerElementsById.find( id );
|
||||
if ( otherLayerIt != otherParser->mProjectLayerElementsById.constEnd() )
|
||||
{
|
||||
if ( otherLayerIt.value().firstChildElement( "layername" ).text() == lName )
|
||||
{
|
||||
layerList.push_back( otherParser->createLayerFromElement( otherLayerIt.value() ) );
|
||||
layerList.push_back( otherParser->createLayerFromElement( otherLayerIt.value(), useCache ) );
|
||||
return layerList;
|
||||
}
|
||||
}
|
||||
@ -422,8 +438,8 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
|
||||
}
|
||||
|
||||
//layer still not found. Check if it is a single layer contained in a embedded layer group
|
||||
groupIt = legendGroups.constBegin();
|
||||
for ( ; groupIt != legendGroups.constEnd(); ++groupIt )
|
||||
groupIt = mLegendGroupElements.constBegin();
|
||||
for ( ; groupIt != mLegendGroupElements.constEnd(); ++groupIt )
|
||||
{
|
||||
if ( groupIt->attribute( "embedded" ) == "1" )
|
||||
{
|
||||
@ -432,9 +448,8 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
|
||||
QgsProjectParser* p = dynamic_cast<QgsProjectParser*>( QgsConfigCache::instance()->searchConfiguration( project ) );
|
||||
if ( p )
|
||||
{
|
||||
QMap< QString, QDomElement > pLayers = p->projectLayerElementsByName();
|
||||
QMap< QString, QDomElement >::const_iterator pLayerIt = pLayers.find( lName );
|
||||
if ( pLayerIt != pLayers.constEnd() )
|
||||
QHash< QString, QDomElement >::const_iterator pLayerIt = mProjectLayerElementsByName.find( lName );
|
||||
if ( pLayerIt != mProjectLayerElementsByName.constEnd() )
|
||||
{
|
||||
QgsMapLayer* layer = p->createLayerFromElement( pLayerIt.value() );
|
||||
if ( layer )
|
||||
@ -456,12 +471,11 @@ int QgsProjectParser::layersAndStyles( QStringList& layers, QStringList& styles
|
||||
layers.clear();
|
||||
styles.clear();
|
||||
|
||||
QList<QDomElement> layerElemList = projectLayerElements();
|
||||
QList<QDomElement>::const_iterator elemIt = layerElemList.constBegin();
|
||||
QList<QDomElement>::const_iterator elemIt = mProjectLayerElements.constBegin();
|
||||
|
||||
QString currentLayerName;
|
||||
|
||||
for ( ; elemIt != layerElemList.constEnd(); ++elemIt )
|
||||
for ( ; elemIt != mProjectLayerElements.constEnd(); ++elemIt )
|
||||
{
|
||||
currentLayerName = layerName( *elemIt );
|
||||
if ( !currentLayerName.isNull() )
|
||||
@ -600,9 +614,8 @@ QMap< QString, QMap< int, QString > > QgsProjectParser::layerAliasInfo() const
|
||||
{
|
||||
QMap< QString, QMap< int, QString > > resultMap;
|
||||
|
||||
QList<QDomElement> layerElems = projectLayerElements();
|
||||
QList<QDomElement>::const_iterator layerIt = layerElems.constBegin();
|
||||
for ( ; layerIt != layerElems.constEnd(); ++layerIt )
|
||||
QList<QDomElement>::const_iterator layerIt = mProjectLayerElements.constBegin();
|
||||
for ( ; layerIt != mProjectLayerElements.constEnd(); ++layerIt )
|
||||
{
|
||||
QDomNodeList aNodeList = layerIt->elementsByTagName( "aliases" );
|
||||
if ( aNodeList.size() > 0 )
|
||||
@ -624,9 +637,8 @@ QMap< QString, QMap< int, QString > > QgsProjectParser::layerAliasInfo() const
|
||||
QMap< QString, QSet<QString> > QgsProjectParser::hiddenAttributes() const
|
||||
{
|
||||
QMap< QString, QSet<QString> > resultMap;
|
||||
QList<QDomElement> layerElems = projectLayerElements();
|
||||
QList<QDomElement>::const_iterator layerIt = layerElems.constBegin();
|
||||
for ( ; layerIt != layerElems.constEnd(); ++layerIt )
|
||||
QList<QDomElement>::const_iterator layerIt = mProjectLayerElements.constBegin();
|
||||
for ( ; layerIt != mProjectLayerElements.constEnd(); ++layerIt )
|
||||
{
|
||||
QDomNodeList editTypesList = layerIt->elementsByTagName( "edittypes" );
|
||||
if ( editTypesList.size() > 0 )
|
||||
@ -754,85 +766,7 @@ QString QgsProjectParser::projectTitle() const
|
||||
return projectFileInfo.baseName();
|
||||
}
|
||||
|
||||
QList<QDomElement> QgsProjectParser::projectLayerElements() const
|
||||
{
|
||||
QList<QDomElement> layerElemList;
|
||||
if ( !mXMLDoc )
|
||||
{
|
||||
return layerElemList;
|
||||
}
|
||||
|
||||
QDomNodeList layerNodeList = mXMLDoc->elementsByTagName( "maplayer" );
|
||||
int nNodes = layerNodeList.size();
|
||||
for ( int i = 0; i < nNodes; ++i )
|
||||
{
|
||||
layerElemList.push_back( layerNodeList.at( i ).toElement() );
|
||||
}
|
||||
return layerElemList;
|
||||
}
|
||||
|
||||
QList<QDomElement> QgsProjectParser::legendGroupElements() const
|
||||
{
|
||||
QList<QDomElement> groupList;
|
||||
if ( !mXMLDoc )
|
||||
{
|
||||
return groupList;
|
||||
}
|
||||
|
||||
QDomElement legendElement = mXMLDoc->documentElement().firstChildElement( "legend" );
|
||||
if ( legendElement.isNull() )
|
||||
{
|
||||
return groupList;
|
||||
}
|
||||
|
||||
QDomNodeList groupNodeList = legendElement.elementsByTagName( "legendgroup" );
|
||||
for ( int i = 0; i < groupNodeList.size(); ++i )
|
||||
{
|
||||
groupList.push_back( groupNodeList.at( i ).toElement() );
|
||||
}
|
||||
|
||||
return groupList;
|
||||
}
|
||||
|
||||
QMap< QString, QDomElement > QgsProjectParser::projectLayerElementsById() const
|
||||
{
|
||||
QMap< QString, QDomElement > layerMap;
|
||||
if ( !mXMLDoc )
|
||||
{
|
||||
return layerMap;
|
||||
}
|
||||
|
||||
QDomNodeList layerNodeList = mXMLDoc->elementsByTagName( "maplayer" );
|
||||
QDomElement currentElement;
|
||||
int nNodes = layerNodeList.size();
|
||||
for ( int i = 0; i < nNodes; ++i )
|
||||
{
|
||||
currentElement = layerNodeList.at( i ).toElement();
|
||||
layerMap.insert( layerId( currentElement ), currentElement );
|
||||
}
|
||||
return layerMap;
|
||||
}
|
||||
|
||||
QMap< QString, QDomElement > QgsProjectParser::projectLayerElementsByName() const
|
||||
{
|
||||
QMap< QString, QDomElement > layerMap;
|
||||
if ( !mXMLDoc )
|
||||
{
|
||||
return layerMap;
|
||||
}
|
||||
|
||||
QDomNodeList layerNodeList = mXMLDoc->elementsByTagName( "maplayer" );
|
||||
QDomElement currentElement;
|
||||
int nNodes = layerNodeList.size();
|
||||
for ( int i = 0; i < nNodes; ++i )
|
||||
{
|
||||
currentElement = layerNodeList.at( i ).toElement();
|
||||
layerMap.insert( layerName( currentElement ), currentElement );
|
||||
}
|
||||
return layerMap;
|
||||
}
|
||||
|
||||
QgsMapLayer* QgsProjectParser::createLayerFromElement( const QDomElement& elem ) const
|
||||
QgsMapLayer* QgsProjectParser::createLayerFromElement( const QDomElement& elem, bool useCache ) const
|
||||
{
|
||||
if ( elem.isNull() || !mXMLDoc )
|
||||
{
|
||||
@ -855,12 +789,14 @@ QgsMapLayer* QgsProjectParser::createLayerFromElement( const QDomElement& elem )
|
||||
}
|
||||
|
||||
QString id = layerId( elem );
|
||||
QgsMapLayer* layer = QgsMSLayerCache::instance()->searchLayer( absoluteUri, id );
|
||||
QgsMapLayer* layer = 0;
|
||||
if ( useCache )
|
||||
{
|
||||
layer = QgsMSLayerCache::instance()->searchLayer( absoluteUri, id );
|
||||
}
|
||||
|
||||
if ( layer )
|
||||
{
|
||||
//reading symbology every time is necessary because it could have been changed by a user SLD based request
|
||||
QString error;
|
||||
layer->readSymbology( elem, error );
|
||||
return layer;
|
||||
}
|
||||
|
||||
@ -883,9 +819,8 @@ QgsMapLayer* QgsProjectParser::createLayerFromElement( const QDomElement& elem )
|
||||
return 0;
|
||||
}
|
||||
|
||||
QMap< QString, QDomElement > layerMap = otherConfig->projectLayerElementsById();
|
||||
QMap< QString, QDomElement >::const_iterator layerIt = layerMap.find( elem.attribute( "id" ) );
|
||||
if ( layerIt == layerMap.constEnd() )
|
||||
QHash< QString, QDomElement >::const_iterator layerIt = otherConfig->mProjectLayerElementsById.find( elem.attribute( "id" ) );
|
||||
if ( layerIt == otherConfig->mProjectLayerElementsById.constEnd() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -896,7 +831,14 @@ QgsMapLayer* QgsProjectParser::createLayerFromElement( const QDomElement& elem )
|
||||
{
|
||||
layer->readXML( const_cast<QDomElement&>( elem ) ); //should be changed to const in QgsMapLayer
|
||||
layer->setLayerName( layerName( elem ) );
|
||||
QgsMSLayerCache::instance()->insertLayer( absoluteUri, id, layer );
|
||||
if ( useCache )
|
||||
{
|
||||
QgsMSLayerCache::instance()->insertLayer( absoluteUri, id, layer );
|
||||
}
|
||||
else
|
||||
{
|
||||
mLayersToRemove.push_back( layer );
|
||||
}
|
||||
}
|
||||
return layer;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class QgsProjectParser: public QgsConfigParser
|
||||
int numberOfLayers() const;
|
||||
|
||||
/**Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned*/
|
||||
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& lName, const QString& styleName, bool allowCaching = true ) const;
|
||||
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& lName, const QString& styleName, bool useCache = true ) const;
|
||||
|
||||
/**Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success*/
|
||||
virtual int layersAndStyles( QStringList& layers, QStringList& styles ) const;
|
||||
@ -102,23 +102,28 @@ class QgsProjectParser: public QgsConfigParser
|
||||
void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
|
||||
|
||||
private:
|
||||
|
||||
//forbidden
|
||||
QgsProjectParser();
|
||||
|
||||
/**Content of project file*/
|
||||
QDomDocument* mXMLDoc;
|
||||
|
||||
/**Absolute project file path (including file name)*/
|
||||
QString mProjectPath;
|
||||
|
||||
/**Get all layers of the project (ordered same as in the project file)*/
|
||||
QList<QDomElement> projectLayerElements() const;
|
||||
/**Returns all legend group elements*/
|
||||
QList<QDomElement> legendGroupElements() const;
|
||||
/**Get all layers of the project, accessible by layer id*/
|
||||
QMap< QString, QDomElement > projectLayerElementsById() const;
|
||||
/**Get all layers of the project, accessible by layer name*/
|
||||
QMap< QString, QDomElement > projectLayerElementsByName() const;
|
||||
/**List of project layer (ordered same as in the project file)*/
|
||||
QList<QDomElement> mProjectLayerElements;
|
||||
/**List of all legend group elements*/
|
||||
QList<QDomElement> mLegendGroupElements;
|
||||
/**Project layer elements, accessible by layer id*/
|
||||
QHash< QString, QDomElement > mProjectLayerElementsById;
|
||||
/**Project layer elements, accessible by layer name*/
|
||||
QHash< QString, QDomElement > mProjectLayerElementsByName;
|
||||
|
||||
/**Creates a maplayer object from <maplayer> element. The layer cash owns the maplayer, so don't delete it
|
||||
@return the maplayer or 0 in case of error*/
|
||||
QgsMapLayer* createLayerFromElement( const QDomElement& elem ) const;
|
||||
QgsMapLayer* createLayerFromElement( const QDomElement& elem, bool useCache = true ) const;
|
||||
/**Returns the text of the <id> element for a layer element
|
||||
@return id or a null string in case of error*/
|
||||
QString layerId( const QDomElement& layerElem ) const;
|
||||
|
@ -121,25 +121,6 @@ QgsSLDParser::QgsSLDParser(): mXMLDoc( 0 )
|
||||
|
||||
QgsSLDParser::~QgsSLDParser()
|
||||
{
|
||||
//remove the temporary files
|
||||
for ( QList<QTemporaryFile*>::const_iterator it = mFilesToRemove.constBegin(); it != mFilesToRemove.constEnd(); ++it )
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
|
||||
//and also those the temporary file paths
|
||||
for ( QList<QString>::const_iterator it = mFilePathsToRemove.constBegin(); it != mFilePathsToRemove.constEnd(); ++it )
|
||||
{
|
||||
QFile::remove( *it );
|
||||
}
|
||||
|
||||
//delete the layers in the list
|
||||
QList<QgsMapLayer*>::iterator layer_it = mLayersToRemove.begin();
|
||||
for ( ; layer_it != mLayersToRemove.end(); ++layer_it )
|
||||
{
|
||||
delete *layer_it;
|
||||
}
|
||||
|
||||
delete mXMLDoc;
|
||||
}
|
||||
|
||||
@ -275,7 +256,7 @@ void QgsSLDParser::layersAndStylesCapabilities( QDomElement& parentElement, QDom
|
||||
}
|
||||
}
|
||||
|
||||
QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, const QString& styleName, bool allowCaching ) const
|
||||
QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, const QString& styleName, bool useCache ) const
|
||||
{
|
||||
QList<QgsMapLayer*> fallbackLayerList;
|
||||
QList<QgsMapLayer*> resultList;
|
||||
@ -287,7 +268,7 @@ QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, c
|
||||
QDomElement userStyleElement = findUserStyleElement( namedLayerElemList[i], styleName );
|
||||
if ( !userStyleElement.isNull() )
|
||||
{
|
||||
fallbackLayerList = mFallbackParser->mapLayerFromStyle( layerName, "", allowCaching );
|
||||
fallbackLayerList = mFallbackParser->mapLayerFromStyle( layerName, "", false );
|
||||
if ( fallbackLayerList.size() > 0 )
|
||||
{
|
||||
QgsVectorLayer* v = dynamic_cast<QgsVectorLayer*>( fallbackLayerList.at( 0 ) );
|
||||
@ -335,7 +316,7 @@ QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, c
|
||||
//maybe named layer and named style is defined in the fallback SLD?
|
||||
if ( mFallbackParser )
|
||||
{
|
||||
resultList = mFallbackParser->mapLayerFromStyle( layerName, styleName, allowCaching );
|
||||
resultList = mFallbackParser->mapLayerFromStyle( layerName, styleName, useCache );
|
||||
}
|
||||
|
||||
QList<QgsMapLayer*>::iterator it = resultList.begin();
|
||||
@ -349,7 +330,7 @@ QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, c
|
||||
|
||||
QDomElement userStyleElement = findUserStyleElement( userLayerElement, styleName );
|
||||
|
||||
QgsMapLayer* theMapLayer = mapLayerFromUserLayer( userLayerElement, layerName, allowCaching );
|
||||
QgsMapLayer* theMapLayer = mapLayerFromUserLayer( userLayerElement, layerName, useCache );
|
||||
if ( !theMapLayer )
|
||||
{
|
||||
return resultList;
|
||||
|
@ -34,7 +34,6 @@ class QgsRenderer;
|
||||
#include <map>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
#ifdef DIAGRAMSERVER
|
||||
#include "qgsdiagramcategory.h"
|
||||
@ -61,7 +60,7 @@ class QgsSLDParser: public QgsConfigParser
|
||||
int numberOfLayers() const;
|
||||
|
||||
/**Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned*/
|
||||
QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool allowCaching = true ) const;
|
||||
QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool useCache = true ) const;
|
||||
|
||||
/**Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success*/
|
||||
int layersAndStyles( QStringList& layers, QStringList& styles ) const;
|
||||
@ -144,25 +143,12 @@ class QgsSLDParser: public QgsConfigParser
|
||||
double scaleFactorFromScaleTag( const QDomElement& scaleElem ) const;
|
||||
#endif //DIAGRAMSERVER
|
||||
|
||||
|
||||
|
||||
/**SLD as dom document*/
|
||||
QDomDocument* mXMLDoc;
|
||||
|
||||
/**Map containing the WMS parameters of the request*/
|
||||
std::map<QString, QString> mParameterMap;
|
||||
|
||||
//todo: leave this to the layer cash?
|
||||
/**Stores pointers to layers that have to be removed in the destructor of QgsSLDParser*/
|
||||
mutable QList<QgsMapLayer*> mLayersToRemove;
|
||||
|
||||
|
||||
/**Stores the temporary file objects. The class takes ownership of the objects and deletes them in the destructor*/
|
||||
mutable QList<QTemporaryFile*> mFilesToRemove;
|
||||
/**Stores paths of files that need to be removed after each request (necessary because of contours shapefiles that \
|
||||
cannot be handles with QTemporaryFile*/
|
||||
mutable QList<QString> mFilePathsToRemove;
|
||||
|
||||
QString mSLDNamespace;
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,10 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
|
||||
QgsDebugMsg( "mConnInfo = " + mConnInfo );
|
||||
|
||||
if ( !pgProvider->supportedLayers( mLayerProperties, true, false, false ) )
|
||||
{
|
||||
children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
|
||||
return children;
|
||||
}
|
||||
|
||||
QMap<QString, QVector<QgsPostgresLayerProperty> > schemasMap;
|
||||
foreach( QgsPostgresLayerProperty layerProperty, mLayerProperties )
|
||||
|
@ -57,7 +57,7 @@ QVector<QgsDataItem*> QgsWFSConnectionItem::createChildren()
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: return an "error" item
|
||||
layers.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
|
||||
}
|
||||
|
||||
mConn->deleteLater();
|
||||
|
@ -3,11 +3,13 @@ SET (WMS_SRCS
|
||||
qgswmsprovider.cpp
|
||||
qgswmssourceselect.cpp
|
||||
qgswmsconnection.cpp
|
||||
qgswmsdataitems.cpp
|
||||
)
|
||||
SET (WMS_MOC_HDRS
|
||||
qgswmsprovider.h
|
||||
qgswmssourceselect.h
|
||||
qgswmsconnection.h
|
||||
qgswmsdataitems.h
|
||||
)
|
||||
|
||||
QT4_WRAP_CPP (WMS_MOC_SRCS ${WMS_MOC_HDRS})
|
||||
|
256
src/providers/wms/qgswmsdataitems.cpp
Normal file
256
src/providers/wms/qgswmsdataitems.cpp
Normal file
@ -0,0 +1,256 @@
|
||||
#include "qgswmsdataitems.h"
|
||||
|
||||
#include "qgslogger.h"
|
||||
|
||||
#include "qgswmsconnection.h"
|
||||
#include "qgswmssourceselect.h"
|
||||
|
||||
#include "qgsnewhttpconnection.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
QgsWMSConnectionItem::QgsWMSConnectionItem( QgsDataItem* parent, QString name, QString path )
|
||||
: QgsDataCollectionItem( parent, name, path )
|
||||
{
|
||||
}
|
||||
|
||||
QgsWMSConnectionItem::~QgsWMSConnectionItem()
|
||||
{
|
||||
}
|
||||
|
||||
QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren()
|
||||
{
|
||||
QgsDebugMsg( "Entered" );
|
||||
QVector<QgsDataItem*> children;
|
||||
QgsWMSConnection connection( mName );
|
||||
QgsWmsProvider *wmsProvider = connection.provider( );
|
||||
if ( !wmsProvider )
|
||||
return children;
|
||||
|
||||
QString mConnInfo = connection.connectionInfo();
|
||||
QgsDebugMsg( "mConnInfo = " + mConnInfo );
|
||||
|
||||
// Attention: supportedLayers() gives tree leafes, not top level
|
||||
if ( !wmsProvider->supportedLayers( mLayerProperties ) )
|
||||
{
|
||||
children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
|
||||
return children;
|
||||
}
|
||||
|
||||
QgsWmsCapabilitiesProperty mCapabilitiesProperty = wmsProvider->capabilitiesProperty();
|
||||
QgsWmsCapabilityProperty capabilityProperty = mCapabilitiesProperty.capability;
|
||||
|
||||
// Top level layer is present max once
|
||||
// <element name="Capability">
|
||||
// <element ref="wms:Layer" minOccurs="0"/> - default maxOccurs=1
|
||||
QgsWmsLayerProperty topLayerProperty = capabilityProperty.layer;
|
||||
foreach( QgsWmsLayerProperty layerProperty, topLayerProperty.layer )
|
||||
{
|
||||
// Attention, the name may be empty
|
||||
QgsDebugMsg( QString::number( layerProperty.orderId ) + " " + layerProperty.name + " " + layerProperty.title );
|
||||
QString pathName = layerProperty.name.isEmpty() ? QString::number( layerProperty.orderId ) : layerProperty.name;
|
||||
|
||||
QgsWMSLayerItem * layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + "/" + pathName, mCapabilitiesProperty, mConnInfo, layerProperty );
|
||||
|
||||
children.append( layer );
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
bool QgsWMSConnectionItem::equal( const QgsDataItem *other )
|
||||
{
|
||||
if ( type() != other->type() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const QgsWMSConnectionItem *o = dynamic_cast<const QgsWMSConnectionItem *>( other );
|
||||
return ( mPath == o->mPath && mName == o->mName && mConnInfo == o->mConnInfo );
|
||||
}
|
||||
|
||||
QList<QAction*> QgsWMSConnectionItem::actions()
|
||||
{
|
||||
QList<QAction*> lst;
|
||||
|
||||
QAction* actionEdit = new QAction( tr( "Edit..." ), this );
|
||||
connect( actionEdit, SIGNAL( triggered() ), this, SLOT( editConnection() ) );
|
||||
lst.append( actionEdit );
|
||||
|
||||
QAction* actionDelete = new QAction( tr( "Delete" ), this );
|
||||
connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteConnection() ) );
|
||||
lst.append( actionDelete );
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
void QgsWMSConnectionItem::editConnection()
|
||||
{
|
||||
QgsNewHttpConnection nc( 0, "/Qgis/connections-wms/", mName );
|
||||
|
||||
if ( nc.exec() )
|
||||
{
|
||||
// the parent should be updated
|
||||
mParent->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsWMSConnectionItem::deleteConnection()
|
||||
{
|
||||
QgsWMSConnection::deleteConnection( mName );
|
||||
// the parent should be updated
|
||||
mParent->refresh();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path, QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperty )
|
||||
: QgsLayerItem( parent, name, path, QString(), QgsLayerItem::Raster, "wms" ),
|
||||
mCapabilitiesProperty( capabilitiesProperty ),
|
||||
mConnInfo( connInfo ),
|
||||
mLayerProperty( layerProperty )
|
||||
//mProviderKey ("wms"),
|
||||
//mLayerType ( QgsLayerItem::Raster )
|
||||
{
|
||||
mUri = createUri();
|
||||
// Populate everything, it costs nothing, all info about layers is collected
|
||||
foreach( QgsWmsLayerProperty layerProperty, mLayerProperty.layer )
|
||||
{
|
||||
// Attention, the name may be empty
|
||||
QgsDebugMsg( QString::number( layerProperty.orderId ) + " " + layerProperty.name + " " + layerProperty.title );
|
||||
QString pathName = layerProperty.name.isEmpty() ? QString::number( layerProperty.orderId ) : layerProperty.name;
|
||||
QgsWMSLayerItem * layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + "/" + pathName, mCapabilitiesProperty, mConnInfo, layerProperty );
|
||||
mChildren.append( layer );
|
||||
}
|
||||
|
||||
if ( mChildren.size() == 0 )
|
||||
{
|
||||
mIcon = QIcon( getThemePixmap( "mIconWmsLayer.png" ) );
|
||||
}
|
||||
mPopulated = true;
|
||||
}
|
||||
|
||||
QgsWMSLayerItem::~QgsWMSLayerItem()
|
||||
{
|
||||
}
|
||||
|
||||
QString QgsWMSLayerItem::createUri()
|
||||
{
|
||||
QString uri;
|
||||
if ( mLayerProperty.name.isEmpty() )
|
||||
return uri; // layer collection
|
||||
|
||||
QString rasterLayerPath = mConnInfo;
|
||||
QString baseName = mLayerProperty.name;
|
||||
|
||||
// Number of styles must match number of layers
|
||||
QStringList layers;
|
||||
layers << mLayerProperty.name;
|
||||
QStringList styles;
|
||||
if ( mLayerProperty.style.size() > 0 )
|
||||
{
|
||||
styles.append( mLayerProperty.style[0].name );
|
||||
}
|
||||
else
|
||||
{
|
||||
styles << ""; // TODO: use loadDefaultStyleFlag
|
||||
}
|
||||
|
||||
QString format;
|
||||
// get first supporte by qt and server
|
||||
QVector<QgsWmsSupportedFormat> formats = QgsWmsProvider::supportedFormats();
|
||||
foreach( QgsWmsSupportedFormat f, formats )
|
||||
{
|
||||
if ( mCapabilitiesProperty.capability.request.getMap.format.indexOf( f.format ) >= 0 )
|
||||
{
|
||||
format = f.format;
|
||||
break;
|
||||
}
|
||||
}
|
||||
QString crs;
|
||||
// get first known if possible
|
||||
QgsCoordinateReferenceSystem testCrs;
|
||||
foreach( QString c, mLayerProperty.crs )
|
||||
{
|
||||
testCrs.createFromOgcWmsCrs( c );
|
||||
if ( testCrs.isValid() )
|
||||
{
|
||||
crs = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( crs.isEmpty() && mLayerProperty.crs.size() > 0 )
|
||||
{
|
||||
crs = mLayerProperty.crs[0];
|
||||
}
|
||||
uri = rasterLayerPath + "|layers=" + layers.join( "," ) + "|styles=" + styles.join( "," ) + "|format=" + format + "|crs=" + crs;
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
QgsWMSRootItem::QgsWMSRootItem( QgsDataItem* parent, QString name, QString path )
|
||||
: QgsDataCollectionItem( parent, name, path )
|
||||
{
|
||||
mIcon = QIcon( getThemePixmap( "mIconWms.png" ) );
|
||||
|
||||
populate();
|
||||
}
|
||||
|
||||
QgsWMSRootItem::~QgsWMSRootItem()
|
||||
{
|
||||
}
|
||||
|
||||
QVector<QgsDataItem*>QgsWMSRootItem::createChildren()
|
||||
{
|
||||
QVector<QgsDataItem*> connections;
|
||||
|
||||
foreach( QString connName, QgsWMSConnection::connectionList() )
|
||||
{
|
||||
QgsDataItem * conn = new QgsWMSConnectionItem( this, connName, mPath + "/" + connName );
|
||||
connections.append( conn );
|
||||
}
|
||||
return connections;
|
||||
}
|
||||
|
||||
QList<QAction*> QgsWMSRootItem::actions()
|
||||
{
|
||||
QList<QAction*> lst;
|
||||
|
||||
QAction* actionNew = new QAction( tr( "New..." ), this );
|
||||
connect( actionNew, SIGNAL( triggered() ), this, SLOT( newConnection() ) );
|
||||
lst.append( actionNew );
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
|
||||
QWidget * QgsWMSRootItem::paramWidget()
|
||||
{
|
||||
QgsWMSSourceSelect *select = new QgsWMSSourceSelect( 0, 0, true, true );
|
||||
connect( select, SIGNAL( connectionsChanged() ), this, SLOT( connectionsChanged() ) );
|
||||
return select;
|
||||
}
|
||||
void QgsWMSRootItem::connectionsChanged()
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
|
||||
void QgsWMSRootItem::newConnection()
|
||||
{
|
||||
QgsNewHttpConnection nc( 0 );
|
||||
|
||||
if ( nc.exec() )
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
|
||||
{
|
||||
Q_UNUSED( thePath );
|
||||
|
||||
return new QgsWMSRootItem( parentItem, "WMS", "wms:" );
|
||||
}
|
||||
|
63
src/providers/wms/qgswmsdataitems.h
Normal file
63
src/providers/wms/qgswmsdataitems.h
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef QGSWMSDATAITEMS_H
|
||||
#define QGSWMSDATAITEMS_H
|
||||
|
||||
#include "qgswmsprovider.h"
|
||||
|
||||
class QgsWMSConnectionItem : public QgsDataCollectionItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QgsWMSConnectionItem( QgsDataItem* parent, QString name, QString path );
|
||||
~QgsWMSConnectionItem();
|
||||
|
||||
QVector<QgsDataItem*> createChildren();
|
||||
virtual bool equal( const QgsDataItem *other );
|
||||
|
||||
virtual QList<QAction*> actions();
|
||||
|
||||
QgsWmsCapabilitiesProperty mCapabilitiesProperty;
|
||||
QString mConnInfo;
|
||||
QVector<QgsWmsLayerProperty> mLayerProperties;
|
||||
|
||||
public slots:
|
||||
void editConnection();
|
||||
void deleteConnection();
|
||||
};
|
||||
|
||||
// WMS Layers may be nested, so that they may be both QgsDataCollectionItem and QgsLayerItem
|
||||
// We have to use QgsDataCollectionItem and support layer methods if necessary
|
||||
class QgsWMSLayerItem : public QgsLayerItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path,
|
||||
QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperties );
|
||||
~QgsWMSLayerItem();
|
||||
|
||||
QString createUri();
|
||||
|
||||
QgsWmsCapabilitiesProperty mCapabilitiesProperty;
|
||||
QString mConnInfo;
|
||||
QgsWmsLayerProperty mLayerProperty;
|
||||
};
|
||||
|
||||
class QgsWMSRootItem : public QgsDataCollectionItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QgsWMSRootItem( QgsDataItem* parent, QString name, QString path );
|
||||
~QgsWMSRootItem();
|
||||
|
||||
QVector<QgsDataItem*> createChildren();
|
||||
|
||||
virtual QList<QAction*> actions();
|
||||
|
||||
virtual QWidget * paramWidget();
|
||||
|
||||
public slots:
|
||||
void connectionsChanged();
|
||||
|
||||
void newConnection();
|
||||
};
|
||||
|
||||
#endif // QGSWMSDATAITEMS_H
|
@ -3165,188 +3165,3 @@ QGISEXTERN int dataCapabilities()
|
||||
{
|
||||
return QgsDataProvider::Net;
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
QgsWMSConnectionItem::QgsWMSConnectionItem( QgsDataItem* parent, QString name, QString path )
|
||||
: QgsDataCollectionItem( parent, name, path )
|
||||
{
|
||||
}
|
||||
|
||||
QgsWMSConnectionItem::~QgsWMSConnectionItem()
|
||||
{
|
||||
}
|
||||
|
||||
QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren()
|
||||
{
|
||||
QgsDebugMsg( "Entered" );
|
||||
QVector<QgsDataItem*> children;
|
||||
QgsWMSConnection connection( mName );
|
||||
QgsWmsProvider *wmsProvider = connection.provider( );
|
||||
if ( !wmsProvider )
|
||||
return children;
|
||||
|
||||
QString mConnInfo = connection.connectionInfo();
|
||||
QgsDebugMsg( "mConnInfo = " + mConnInfo );
|
||||
|
||||
// Attention: supportedLayers() gives tree leafes, not top level
|
||||
if ( !wmsProvider->supportedLayers( mLayerProperties ) )
|
||||
return children;
|
||||
|
||||
QgsWmsCapabilitiesProperty mCapabilitiesProperty = wmsProvider->capabilitiesProperty();
|
||||
QgsWmsCapabilityProperty capabilityProperty = mCapabilitiesProperty.capability;
|
||||
|
||||
// Top level layer is present max once
|
||||
// <element name="Capability">
|
||||
// <element ref="wms:Layer" minOccurs="0"/> - default maxOccurs=1
|
||||
QgsWmsLayerProperty topLayerProperty = capabilityProperty.layer;
|
||||
foreach( QgsWmsLayerProperty layerProperty, topLayerProperty.layer )
|
||||
{
|
||||
// Attention, the name may be empty
|
||||
QgsDebugMsg( QString::number( layerProperty.orderId ) + " " + layerProperty.name + " " + layerProperty.title );
|
||||
QString pathName = layerProperty.name.isEmpty() ? QString::number( layerProperty.orderId ) : layerProperty.name;
|
||||
|
||||
QgsWMSLayerItem * layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + "/" + pathName, mCapabilitiesProperty, mConnInfo, layerProperty );
|
||||
|
||||
children.append( layer );
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
bool QgsWMSConnectionItem::equal( const QgsDataItem *other )
|
||||
{
|
||||
if ( type() != other->type() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const QgsWMSConnectionItem *o = dynamic_cast<const QgsWMSConnectionItem *>( other );
|
||||
return ( mPath == o->mPath && mName == o->mName && mConnInfo == o->mConnInfo );
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path, QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperty )
|
||||
: QgsLayerItem( parent, name, path, QString(), QgsLayerItem::Raster, "wms" ),
|
||||
mCapabilitiesProperty( capabilitiesProperty ),
|
||||
mConnInfo( connInfo ),
|
||||
mLayerProperty( layerProperty )
|
||||
//mProviderKey ("wms"),
|
||||
//mLayerType ( QgsLayerItem::Raster )
|
||||
{
|
||||
mUri = createUri();
|
||||
// Populate everything, it costs nothing, all info about layers is collected
|
||||
foreach( QgsWmsLayerProperty layerProperty, mLayerProperty.layer )
|
||||
{
|
||||
// Attention, the name may be empty
|
||||
QgsDebugMsg( QString::number( layerProperty.orderId ) + " " + layerProperty.name + " " + layerProperty.title );
|
||||
QString pathName = layerProperty.name.isEmpty() ? QString::number( layerProperty.orderId ) : layerProperty.name;
|
||||
QgsWMSLayerItem * layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + "/" + pathName, mCapabilitiesProperty, mConnInfo, layerProperty );
|
||||
mChildren.append( layer );
|
||||
}
|
||||
|
||||
if ( mChildren.size() == 0 )
|
||||
{
|
||||
mIcon = QIcon( getThemePixmap( "mIconWmsLayer.png" ) );
|
||||
}
|
||||
mPopulated = true;
|
||||
}
|
||||
|
||||
QgsWMSLayerItem::~QgsWMSLayerItem()
|
||||
{
|
||||
}
|
||||
|
||||
QString QgsWMSLayerItem::createUri()
|
||||
{
|
||||
QString uri;
|
||||
if ( mLayerProperty.name.isEmpty() )
|
||||
return uri; // layer collection
|
||||
|
||||
QString rasterLayerPath = mConnInfo;
|
||||
QString baseName = mLayerProperty.name;
|
||||
|
||||
// Number of styles must match number of layers
|
||||
QStringList layers;
|
||||
layers << mLayerProperty.name;
|
||||
QStringList styles;
|
||||
if ( mLayerProperty.style.size() > 0 )
|
||||
{
|
||||
styles.append( mLayerProperty.style[0].name );
|
||||
}
|
||||
else
|
||||
{
|
||||
styles << ""; // TODO: use loadDefaultStyleFlag
|
||||
}
|
||||
|
||||
QString format;
|
||||
// get first supporte by qt and server
|
||||
QVector<QgsWmsSupportedFormat> formats = QgsWmsProvider::supportedFormats();
|
||||
foreach( QgsWmsSupportedFormat f, formats )
|
||||
{
|
||||
if ( mCapabilitiesProperty.capability.request.getMap.format.indexOf( f.format ) >= 0 )
|
||||
{
|
||||
format = f.format;
|
||||
break;
|
||||
}
|
||||
}
|
||||
QString crs;
|
||||
// get first known if possible
|
||||
QgsCoordinateReferenceSystem testCrs;
|
||||
foreach( QString c, mLayerProperty.crs )
|
||||
{
|
||||
testCrs.createFromOgcWmsCrs( c );
|
||||
if ( testCrs.isValid() )
|
||||
{
|
||||
crs = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( crs.isEmpty() && mLayerProperty.crs.size() > 0 )
|
||||
{
|
||||
crs = mLayerProperty.crs[0];
|
||||
}
|
||||
uri = rasterLayerPath + "|layers=" + layers.join( "," ) + "|styles=" + styles.join( "," ) + "|format=" + format + "|crs=" + crs;
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
QgsWMSRootItem::QgsWMSRootItem( QgsDataItem* parent, QString name, QString path )
|
||||
: QgsDataCollectionItem( parent, name, path )
|
||||
{
|
||||
mIcon = QIcon( getThemePixmap( "mIconWms.png" ) );
|
||||
|
||||
populate();
|
||||
}
|
||||
|
||||
QgsWMSRootItem::~QgsWMSRootItem()
|
||||
{
|
||||
}
|
||||
|
||||
QVector<QgsDataItem*>QgsWMSRootItem::createChildren()
|
||||
{
|
||||
QVector<QgsDataItem*> connections;
|
||||
|
||||
foreach( QString connName, QgsWMSConnection::connectionList() )
|
||||
{
|
||||
QgsDataItem * conn = new QgsWMSConnectionItem( this, connName, mPath + "/" + connName );
|
||||
connections.append( conn );
|
||||
}
|
||||
return connections;
|
||||
}
|
||||
|
||||
QWidget * QgsWMSRootItem::paramWidget()
|
||||
{
|
||||
QgsWMSSourceSelect *select = new QgsWMSSourceSelect( 0, 0, true, true );
|
||||
connect( select, SIGNAL( connectionsChanged() ), this, SLOT( connectionsChanged() ) );
|
||||
return select;
|
||||
}
|
||||
void QgsWMSRootItem::connectionsChanged()
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
|
||||
{
|
||||
Q_UNUSED( thePath );
|
||||
|
||||
return new QgsWMSRootItem( parentItem, "WMS", "wms:" );
|
||||
}
|
||||
|
||||
|
@ -968,51 +968,6 @@ class QgsWmsProvider : public QgsRasterDataProvider
|
||||
QStringList mSupportedGetFeatureFormats;
|
||||
};
|
||||
|
||||
class QgsWMSConnectionItem : public QgsDataCollectionItem
|
||||
{
|
||||
public:
|
||||
QgsWMSConnectionItem( QgsDataItem* parent, QString name, QString path );
|
||||
~QgsWMSConnectionItem();
|
||||
|
||||
QVector<QgsDataItem*> createChildren();
|
||||
virtual bool equal( const QgsDataItem *other );
|
||||
|
||||
QgsWmsCapabilitiesProperty mCapabilitiesProperty;
|
||||
QString mConnInfo;
|
||||
QVector<QgsWmsLayerProperty> mLayerProperties;
|
||||
};
|
||||
|
||||
// WMS Layers may be nested, so that they may be both QgsDataCollectionItem and QgsLayerItem
|
||||
// We have to use QgsDataCollectionItem and support layer methods if necessary
|
||||
class QgsWMSLayerItem : public QgsLayerItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path,
|
||||
QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperties );
|
||||
~QgsWMSLayerItem();
|
||||
|
||||
QString createUri();
|
||||
|
||||
QgsWmsCapabilitiesProperty mCapabilitiesProperty;
|
||||
QString mConnInfo;
|
||||
QgsWmsLayerProperty mLayerProperty;
|
||||
};
|
||||
|
||||
class QgsWMSRootItem : public QgsDataCollectionItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QgsWMSRootItem( QgsDataItem* parent, QString name, QString path );
|
||||
~QgsWMSRootItem();
|
||||
|
||||
QVector<QgsDataItem*> createChildren();
|
||||
|
||||
virtual QWidget * paramWidget();
|
||||
|
||||
public slots:
|
||||
void connectionsChanged();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user