QgsMapLayerModel::QgsMapLayerModel( QObject *parent ) : QAbstractItemModel( parent ) { connect( QgsProject::instance(), &QgsProject::layersAdded, this, &QgsMapLayerModel::addLayers ); connect( QgsProject::instance(), static_cast < void ( QgsProject::* )( const QStringList & ) >( &QgsProject::layersWillBeRemoved ), this, &QgsMapLayerModel::removeLayers ); addLayers( QgsProject::instance()->mapLayers().values() ); }
QgsMapLayerModel::QgsMapLayerModel( QList<QgsMapLayer *> layers, QObject *parent ) : QAbstractItemModel( parent ) , mLayersChecked( QMap<QString, Qt::CheckState>() ) , mItemCheckable( false ) { connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) ); addLayers( layers ); }
void QgsProjectParser::layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const { QList<QDomElement> layerElems = projectLayerElements(); QStringList nonIdentifiableLayers = identifyDisabledLayers(); if ( layerElems.size() < 1 ) { return; } QMap<QString, QgsMapLayer *> layerMap; QList<QDomElement>::const_iterator layerIt = layerElems.constBegin(); for ( ; layerIt != layerElems.constEnd(); ++layerIt ) { QgsMapLayer *layer = createLayerFromElement( *layerIt ); if ( layer ) { QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) ); layerMap.insert( layer->id(), layer ); } #if QGSMSDEBUG else { QString buf; QTextStream s( &buf ); layerIt->save( s, 0 ); QgsDebugMsg( QString( "layer %1 not found" ).arg( buf ) ); } #endif } //According to the WMS spec, there can be only one toplevel layer. //So we create an artificial one here to be in accordance with the schema QString projTitle = projectTitle(); QDomElement layerParentElem = doc.createElement( "Layer" ); layerParentElem.setAttribute( "queryable", "1" ); QDomElement layerParentNameElem = doc.createElement( "Name" ); QDomText layerParentNameText = doc.createTextNode( projTitle ); layerParentNameElem.appendChild( layerParentNameText ); layerParentElem.appendChild( layerParentNameElem ); QDomElement layerParentTitleElem = doc.createElement( "Title" ); QDomText layerParentTitleText = doc.createTextNode( projTitle ); layerParentTitleElem.appendChild( layerParentTitleText ); layerParentElem.appendChild( layerParentTitleElem ); QDomElement legendElem = mXMLDoc->documentElement().firstChildElement( "legend" ); addLayers( doc, layerParentElem, legendElem, layerMap, nonIdentifiableLayers ); parentElement.appendChild( layerParentElem ); combineExtentAndCrsOfGroupChildren( layerParentElem, doc ); }
bool GameScene::init() { if (!Layer::init()) { return false; } originPoint = Director::getInstance()->getVisibleOrigin(); visibleSize = Director::getInstance()->getVisibleSize(); addLayers(); return true; }
bool SFLayer::initWithDictionary(CCDictionary * pDict) { if (!CNLayer::initWithDictionary(pDict)) { CNLog("error"); return false; } // load textures // WARNING: For simplify reason, I hope you should never use it! CCArray * pTextures = CNDictionary::arrayForKey("Textures", pDict); setTextures(SFScene::loadTextures(pTextures)); // add sub layers // WARNING: For simplify reason, I hope you should never use it! CCArray * pLayers = CNDictionary::arrayForKey("Layers", pDict); addLayers(pLayers); // add sub sprites CCArray * pSprites = CNDictionary::arrayForKey("Sprites", pDict); addSprites(pSprites); return true; }
void QgsProjectParser::addLayers( QDomDocument &doc, QDomElement &parentElem, const QDomElement &legendElem, const QMap<QString, QgsMapLayer *> &layerMap, const QStringList &nonIdentifiableLayers ) const { QDomNodeList legendChildren = legendElem.childNodes(); for ( int i = 0; i < legendChildren.size(); ++i ) { QDomElement currentChildElem = legendChildren.at( i ).toElement(); QDomElement layerElem = doc.createElement( "Layer" ); if ( currentChildElem.tagName() == "legendgroup" ) { layerElem.setAttribute( "queryable", "1" ); QString name = currentChildElem.attribute( "name" ); QDomElement nameElem = doc.createElement( "Name" ); QDomText nameText = doc.createTextNode( name ); nameElem.appendChild( nameText ); layerElem.appendChild( nameElem ); QDomElement titleElem = doc.createElement( "Title" ); QDomText titleText = doc.createTextNode( name ); titleElem.appendChild( titleText ); layerElem.appendChild( titleElem ); if ( currentChildElem.attribute( "embedded" ) == "1" ) { //add layers from other project files and embed into this group QString project = convertToAbsolutePath( currentChildElem.attribute( "project" ) ); QgsDebugMsg( QString( "Project path: %1" ).arg( project ) ); QString embeddedGroupName = currentChildElem.attribute( "name" ); QgsProjectParser* p = dynamic_cast<QgsProjectParser*>( QgsConfigCache::instance()->searchConfiguration( project ) ); if ( p ) { QStringList pIdDisabled = p->identifyDisabledLayers(); QDomElement embeddedGroupElem; QList<QDomElement> pLegendElems = p->legendGroupElements(); QList<QDomElement>::const_iterator pLegendIt = pLegendElems.constBegin(); for ( ; pLegendIt != pLegendElems.constEnd(); ++pLegendIt ) { if ( pLegendIt->attribute( "name" ) == embeddedGroupName ) { embeddedGroupElem = *pLegendIt; break; } } QList<QDomElement> pLayerElems = p->projectLayerElements(); QMap<QString, QgsMapLayer *> pLayerMap; QList<QDomElement>::const_iterator pLayerIt = pLayerElems.constBegin(); for ( ; pLayerIt != pLayerElems.constEnd(); ++pLayerIt ) { pLayerMap.insert( layerId( *pLayerIt ), p->createLayerFromElement( *pLayerIt ) ); } p->addLayers( doc, layerElem, embeddedGroupElem, pLayerMap, pIdDisabled ); } } else //normal (not embedded) legend group { addLayers( doc, layerElem, currentChildElem, layerMap, nonIdentifiableLayers ); } // combine bounding boxes of children (groups/layers) combineExtentAndCrsOfGroupChildren( layerElem, doc ); } else if ( currentChildElem.tagName() == "legendlayer" ) { QString id = layerIdFromLegendLayer( currentChildElem ); if ( !layerMap.contains( id ) ) { QgsDebugMsg( QString( "layer %1 not found in map - layer cache to small?" ).arg( id ) ); continue; } QgsMapLayer *currentLayer = layerMap[ id ]; if ( !currentLayer ) { QgsDebugMsg( QString( "layer %1 not found" ).arg( id ) ); continue; } if ( nonIdentifiableLayers.contains( currentLayer->id() ) ) { layerElem.setAttribute( "queryable", "0" ); } else { layerElem.setAttribute( "queryable", "1" ); } QDomElement nameElem = doc.createElement( "Name" ); //We use the layer name even though it might not be unique. //Because the id sometimes contains user/pw information and the name is more descriptive QDomText nameText = doc.createTextNode( currentLayer->name() ); nameElem.appendChild( nameText ); layerElem.appendChild( nameElem ); QDomElement titleElem = doc.createElement( "Title" ); QDomText titleText = doc.createTextNode( currentLayer->name() ); titleElem.appendChild( titleText ); layerElem.appendChild( titleElem ); //CRS QStringList crsList = createCRSListForLayer( currentLayer ); appendCRSElementsToLayer( layerElem, doc, crsList ); //Ex_GeographicBoundingBox appendLayerBoundingBoxes( layerElem, doc, currentLayer->extent(), currentLayer->crs() ); //only one default style in project file mode QDomElement styleElem = doc.createElement( "Style" ); QDomElement styleNameElem = doc.createElement( "Name" ); QDomText styleNameText = doc.createTextNode( "default" ); styleNameElem.appendChild( styleNameText ); QDomElement styleTitleElem = doc.createElement( "Title" ); QDomText styleTitleText = doc.createTextNode( "default" ); styleTitleElem.appendChild( styleTitleText ); styleElem.appendChild( styleNameElem ); styleElem.appendChild( styleTitleElem ); layerElem.appendChild( styleElem ); } else { QgsDebugMsg( "unexpected child element" ); continue; } parentElem.appendChild( layerElem ); } }
QgsSnappingDialog::QgsSnappingDialog( QWidget* parent, QgsMapCanvas* canvas ) : QDialog( parent ) , mMapCanvas( canvas ) , mDock( 0 ) { setupUi( this ); QSettings myQsettings; bool myDockFlag = myQsettings.value( "/qgis/dockSnapping", false ).toBool(); if ( myDockFlag ) { mDock = new QgsSnappingDock( tr( "Snapping and Digitizing Options" ), QgisApp::instance() ); mDock->setAllowedAreas( Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea ); mDock->setWidget( this ); connect( this, SIGNAL( destroyed() ), mDock, SLOT( close() ) ); QgisApp::instance()->addDockWidget( Qt::BottomDockWidgetArea, mDock ); mButtonBox->setVisible( false ); } else { connect( mButtonBox, SIGNAL( accepted() ), this, SLOT( apply() ) ); connect( mButtonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) ); } connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer * > ) ), this, SLOT( addLayers( QList<QgsMapLayer * > ) ) ); connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersWillBeRemoved( QStringList ) ) ); connect( cbxEnableTopologicalEditingCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( on_cbxEnableTopologicalEditingCheckBox_stateChanged( int ) ) ); connect( cbxEnableIntersectionSnappingCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( on_cbxEnableIntersectionSnappingCheckBox_stateChanged( int ) ) ); reload(); QMap< QString, QgsMapLayer *> mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); QMap< QString, QgsMapLayer *>::iterator it; for ( it = mapLayers.begin(); it != mapLayers.end() ; ++it ) { addLayer( it.value() ); } mLayerTreeWidget->setHeaderLabels( QStringList() << "" ); mLayerTreeWidget->setSortingEnabled( true ); connect( QgsProject::instance(), SIGNAL( snapSettingsChanged() ), this, SLOT( reload() ) ); }
QgsMapLayerModel::QgsMapLayerModel( const QList<QgsMapLayer *> &layers, QObject *parent ) : QAbstractItemModel( parent ) { connect( QgsProject::instance(), static_cast < void ( QgsProject::* )( const QStringList & ) >( &QgsProject::layersWillBeRemoved ), this, &QgsMapLayerModel::removeLayers ); addLayers( layers ); }
KisImportExportFilter::ConversionStatus KisXCFImport::loadFromDevice(QIODevice* device, KisDocument* doc) { dbgFile << "Start decoding file"; // Read the file into memory device->open(QIODevice::ReadOnly); QByteArray data = device->readAll(); xcf_file = (uint8_t*)data.data(); xcf_length = data.size(); device->close(); // Decode the data getBasicXcfInfo() ; initColormap(); dbgFile << XCF.version << "width = " << XCF.width << "height = " << XCF.height << "layers = " << XCF.numLayers; // Create the image KisImageSP image = new KisImage(doc->createUndoStore(), XCF.width, XCF.height, KoColorSpaceRegistry::instance()->rgb8(), "built image"); QVector<Layer> layers; uint maxDepth = 0; // Read layers for (int i = 0; i < XCF.numLayers; ++i) { Layer layer; xcfLayer& xcflayer = XCF.layers[i]; dbgFile << i << " name = " << xcflayer.name << " opacity = " << xcflayer.opacity << "group:" << xcflayer.isGroup << xcflayer.pathLength; dbgFile << ppVar(xcflayer.dim.width) << ppVar(xcflayer.dim.height) << ppVar(xcflayer.dim.tilesx) << ppVar(xcflayer.dim.tilesy) << ppVar(xcflayer.dim.ntiles) << ppVar(xcflayer.dim.c.t) << ppVar(xcflayer.dim.c.l) << ppVar(xcflayer.dim.c.r) << ppVar(xcflayer.dim.c.b); maxDepth = qMax(maxDepth, xcflayer.pathLength); bool isRgbA = false; // Select the color space const KoColorSpace* colorSpace = 0; switch (xcflayer.type) { case GIMP_INDEXED_IMAGE: case GIMP_INDEXEDA_IMAGE: case GIMP_RGB_IMAGE: case GIMP_RGBA_IMAGE: colorSpace = KoColorSpaceRegistry::instance()->rgb8(); isRgbA = true; break; case GIMP_GRAY_IMAGE: case GIMP_GRAYA_IMAGE: colorSpace = KoColorSpaceRegistry::instance()->colorSpace(GrayAColorModelID.id(), Integer8BitsColorDepthID.id(), ""); isRgbA = false; break; } // Create the layer KisLayerSP kisLayer; if (xcflayer.isGroup) { kisLayer = new KisGroupLayer(image, QString::fromUtf8(xcflayer.name), xcflayer.opacity); } else { kisLayer = new KisPaintLayer(image, QString::fromUtf8(xcflayer.name), xcflayer.opacity, colorSpace); } // Set some properties kisLayer->setCompositeOpId(layerModeG2K(xcflayer.mode)); kisLayer->setVisible(xcflayer.isVisible); kisLayer->disableAlphaChannel(xcflayer.mode != GIMP_NORMAL_MODE); layer.layer = kisLayer; layer.depth = xcflayer.pathLength; // Copy the data in the image initLayer(&xcflayer); int left = xcflayer.dim.c.l; int top = xcflayer.dim.c.t; if (!xcflayer.isGroup) { // Copy the data; for (unsigned int x = 0; x < xcflayer.dim.width; x += TILE_WIDTH) { for (unsigned int y = 0; y < xcflayer.dim.height; y += TILE_HEIGHT) { rect want; want.l = x + left; want.t = y + top; want.b = want.t + TILE_HEIGHT; want.r = want.l + TILE_WIDTH; Tile* tile = getMaskOrLayerTile(&xcflayer.dim, &xcflayer.pixels, want); KisHLineIteratorSP it = kisLayer->paintDevice()->createHLineIteratorNG(x, y, TILE_WIDTH); rgba* data = tile->pixels; for (int v = 0; v < TILE_HEIGHT; ++v) { if (isRgbA) { // RGB image do { KoBgrTraits<quint8>::setRed(it->rawData(), GET_RED(*data)); KoBgrTraits<quint8>::setGreen(it->rawData(), GET_GREEN(*data)); KoBgrTraits<quint8>::setBlue(it->rawData(), GET_BLUE(*data)); KoBgrTraits<quint8>::setOpacity(it->rawData(), quint8(GET_ALPHA(*data)), 1); ++data; } while (it->nextPixel()); } else { // Grayscale image do { it->rawData()[0] = GET_RED(*data); it->rawData()[1] = GET_ALPHA(*data); ++data; } while (it->nextPixel()); } it->nextRow(); } } } // Move the layer to its position kisLayer->paintDevice()->setX(left); kisLayer->paintDevice()->setY(top); } // Create the mask if (xcflayer.hasMask) { KisTransparencyMaskSP mask = new KisTransparencyMask(); layer.mask = mask; mask->initSelection(kisLayer); for (unsigned int x = 0; x < xcflayer.dim.width; x += TILE_WIDTH) { for (unsigned int y = 0; y < xcflayer.dim.height; y += TILE_HEIGHT) { rect want; want.l = x + left; want.t = y + top; want.b = want.t + TILE_HEIGHT; want.r = want.l + TILE_WIDTH; Tile* tile = getMaskOrLayerTile(&xcflayer.dim, &xcflayer.mask, want); KisHLineIteratorSP it = mask->paintDevice()->createHLineIteratorNG(x, y, TILE_WIDTH); rgba* data = tile->pixels; for (int v = 0; v < TILE_HEIGHT; ++v) { do { it->rawData()[0] = GET_ALPHA(*data); ++data; } while (it->nextPixel()); it->nextRow(); } } } mask->paintDevice()->setX(left); mask->paintDevice()->setY(top); image->addNode(mask, kisLayer); } dbgFile << xcflayer.pixels.tileptrs; layers.append(layer); } for (int i = 0; i <= maxDepth; ++i) { addLayers(layers, image, i); } doc->setCurrentImage(image); return KisImportExportFilter::OK; }