void QgsComposerGroupItem::readXML( const QDomElement& itemElem, bool xServerAvailable ) { if ( itemElem.isNull() ) { return; } // text is always user text but for backward compatibility we read also text QString userText = itemElem.attribute( "userText", "" ); if ( userText.isEmpty() ) { userText = itemElem.attribute( "text", "" ); } setText( userText ); setUserText( userText ); setStyle( QgsComposerLegendStyle::styleFromName( itemElem.attribute( "style", "group" ) ) ); //now call readXML for all the child items QDomNodeList childList = itemElem.childNodes(); QDomNode currentNode; QDomElement currentElem; QgsComposerLegendItem* currentChildItem = 0; int nChildItems = childList.count(); for ( int i = 0; i < nChildItems; ++i ) { currentNode = childList.at( i ); if ( !currentNode.isElement() ) { continue; } currentElem = currentNode.toElement(); QString elemTag = currentElem.tagName(); if ( elemTag == "GroupItem" ) { currentChildItem = new QgsComposerGroupItem(); } else if ( elemTag == "LayerItem" ) { currentChildItem = new QgsComposerLayerItem(); } else { continue; //unsupported child item type } currentChildItem->readXML( currentElem, xServerAvailable ); QList<QStandardItem *> itemsList; itemsList << currentChildItem << new QgsComposerStyleItem( currentChildItem ); appendRow( itemsList ); } }
void QgsComposerLayerItem::readXML( const QDomElement& itemElem, bool xServerAvailable ) { if ( itemElem.isNull() ) { return; } setText( itemElem.attribute( "text", "" ) ); setUserText( itemElem.attribute( "userText", "" ) ); setLayerID( itemElem.attribute( "layerId", "" ) ); setShowFeatureCount( itemElem.attribute( "showFeatureCount", "" ) == "1" ? true : false ); setStyle( QgsComposerLegendStyle::styleFromName( itemElem.attribute( "style", "subgroup" ) ) ); //now call readXML for all the child items QDomNodeList childList = itemElem.childNodes(); QDomNode currentNode; QDomElement currentElem; QgsComposerLegendItem* currentChildItem = 0; int nChildItems = childList.count(); for ( int i = 0; i < nChildItems; ++i ) { currentNode = childList.at( i ); if ( !currentNode.isElement() ) { continue; } currentElem = currentNode.toElement(); QString elemTag = currentElem.tagName(); if ( elemTag == "VectorClassificationItem" ) { continue; // legacy - unsupported } else if ( elemTag == "VectorClassificationItemNg" ) { currentChildItem = new QgsComposerSymbolV2Item(); } else if ( elemTag == "RasterClassificationItem" ) { currentChildItem = new QgsComposerRasterSymbolItem(); } else { continue; //unsupported child type } currentChildItem->readXML( currentElem, xServerAvailable ); appendRow( currentChildItem ); } }
void QgsComposerLayerItem::readXML( const QDomElement& itemElem ) { if ( itemElem.isNull() ) { return; } setText( itemElem.attribute( "text", "" ) ); setLayerID( itemElem.attribute( "layerId", "" ) ); //now call readXML for all the child items QDomNodeList childList = itemElem.childNodes(); QDomNode currentNode; QDomElement currentElem; QgsComposerLegendItem* currentChildItem = 0; int nChildItems = childList.count(); for ( int i = 0; i < nChildItems; ++i ) { currentNode = childList.at( i ); if ( !currentNode.isElement() ) { continue; } currentElem = currentNode.toElement(); QString elemTag = currentElem.tagName(); if ( elemTag == "VectorClassificationItem" ) { currentChildItem = new QgsComposerSymbolItem(); } else if ( elemTag == "VectorClassificationItemNg" ) { currentChildItem = new QgsComposerSymbolV2Item(); } else if ( elemTag == "RasterClassificationItem" ) { currentChildItem = new QgsComposerRasterSymbolItem(); } else { continue; //unsupported child type } currentChildItem->readXML( currentElem ); appendRow( currentChildItem ); } }
bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocument& doc ) { Q_UNUSED( doc ); if ( legendModelElem.isNull() ) { return false; } clear(); QDomNodeList topLevelItemList = legendModelElem.childNodes(); QDomElement currentElem; QgsComposerLegendItem* currentItem = 0; int nTopLevelItems = topLevelItemList.size(); for ( int i = 0; i < nTopLevelItems; ++i ) { currentElem = topLevelItemList.at( i ).toElement(); if ( currentElem.isNull() ) { continue; } //toplevel items can be groups or layers if ( currentElem.tagName() == "LayerItem" ) { currentItem = new QgsComposerLayerItem(); } else if ( currentElem.tagName() == "GroupItem" ) { currentItem = new QgsComposerGroupItem(); } currentItem->readXML( currentElem, mHasTopLevelWindow ); QList<QStandardItem *> itemsList; itemsList << currentItem << new QgsComposerStyleItem( currentItem ); appendRow( itemsList ); } setAutoUpdate( legendModelElem.attribute( "autoUpdate", "1" ).toInt() ); return true; }
bool QgsLegendModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) { Q_UNUSED( action ); Q_UNUSED( column ); if ( !data->hasFormat( "text/xml" ) ) { return false; } QStandardItem* dropIntoItem = 0; if ( parent.isValid() ) { dropIntoItem = itemFromIndex( parent ); } else { dropIntoItem = invisibleRootItem(); } //get XML doc QByteArray encodedData = data->data( "text/xml" ); QDomDocument xmlDoc; xmlDoc.setContent( encodedData ); QDomElement dragDataElem = xmlDoc.documentElement(); if ( dragDataElem.tagName() != "LegendModelDragData" ) { return false; } QDomNodeList nodeList = dragDataElem.childNodes(); int nChildNodes = nodeList.size(); QDomElement currentElem; QString currentTagName; QgsComposerLegendItem* currentItem = 0; for ( int i = 0; i < nChildNodes; ++i ) { currentElem = nodeList.at( i ).toElement(); if ( currentElem.isNull() ) { continue; } currentTagName = currentElem.tagName(); if ( currentTagName == "LayerItem" ) { currentItem = new QgsComposerLayerItem(); } else if ( currentTagName == "GroupItem" ) { currentItem = new QgsComposerGroupItem(); } else { continue; } currentItem->readXML( currentElem ); if ( row < 0 ) { dropIntoItem->insertRow( dropIntoItem->rowCount(), currentItem ); } else { dropIntoItem->insertRow( row + i, currentItem ); } } emit layersChanged(); return true; }