Skip to content
Permalink
Browse files

Integrate into layer dialogs, save in layer's properties

  • Loading branch information
wonder-sk committed Jun 2, 2016
1 parent c780949 commit 75e5da3796146707cf36b0eac0a4361db8dc0227
@@ -237,9 +237,6 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
duplicateLayersAction->setEnabled( false );
}

QAction* embeddedAction = menu->addAction( tr( "Embedded widgets..."), this, SLOT( editEmbeddedWidgets() ) );
embeddedAction->setProperty( "layerId", layer->id() );

addCustomLayerActions( menu, layer );

if ( layer && QgsProject::instance()->layerIsEmbedded( layer->id() ).isEmpty() )
@@ -558,26 +555,3 @@ void QgsAppLayerTreeViewMenuProvider::setSymbolLegendNodeColor( const QColor &co
newSymbol->setColor( color );
node->setSymbol( newSymbol );
}

#include "qgslayertreeembeddedconfigwidget.h"
void QgsAppLayerTreeViewMenuProvider::editEmbeddedWidgets()
{
QAction* action = qobject_cast< QAction*>( sender() );
if ( !action )
return;

QString layerId = action->property( "layerId" ).toString();
QgsLayerTreeLayer* nodeLayer = QgsProject::instance()->layerTreeRoot()->findLayer( layerId );
if ( !nodeLayer )
return;

QDialog d;
QgsLayerTreeEmbeddedConfigWidget* widget = new QgsLayerTreeEmbeddedConfigWidget(nodeLayer, &d);

QLayout* l = new QVBoxLayout(&d);
l->addWidget(widget);
d.setLayout(l);
d.exec();

mView->layerTreeModel()->refreshLayerLegend( nodeLayer );
}
@@ -69,7 +69,6 @@ class QgsAppLayerTreeViewMenuProvider : public QObject, public QgsLayerTreeViewM
void setVectorSymbolColor( const QColor &color );
void editSymbolLegendNodeSymbol();
void setSymbolLegendNodeColor( const QColor &color );
void editEmbeddedWidgets();
};

#endif // QGSAPPLAYERTREEVIEWMENUPROVIDER_H
@@ -797,6 +797,12 @@ void QgsRasterLayerProperties::sync()

mLayerLegendUrlLineEdit->setText( mRasterLayer->legendUrl() );
mLayerLegendUrlFormatComboBox->setCurrentIndex( mLayerLegendUrlFormatComboBox->findText( mRasterLayer->legendUrlFormat() ) );

/*
* Legend Tab
*/
mLegendConfigEmbeddedWidget->setLayer( mRasterLayer );

} // QgsRasterLayerProperties::sync()

/*
@@ -806,6 +812,11 @@ void QgsRasterLayerProperties::sync()
*/
void QgsRasterLayerProperties::apply()
{
/*
* Legend Tab
*/
mLegendConfigEmbeddedWidget->applyToLayer();

QgsDebugMsg( "apply processing symbology tab" );
/*
* Symbology Tab
@@ -251,6 +251,9 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
diagLayout->addWidget( diagramPropertiesDialog );
mDiagramFrame->setLayout( diagLayout );

// Legend tab
mLegendConfigEmbeddedWidget->setLayer( mLayer );

// WMS Name as layer short name
mLayerShortNameLineEdit->setText( mLayer->shortName() );
// WMS Name validator
@@ -535,6 +538,9 @@ void QgsVectorLayerProperties::apply()
labelingDialog->writeSettingsToLayer();
}

// apply legend settings
mLegendConfigEmbeddedWidget->applyToLayer();

//
// Set up sql subset query if applicable
//
@@ -1186,7 +1186,7 @@ void QgsLayerTreeModel::addLegendToLayer( QgsLayerTreeLayer* nodeL )

if ( testFlag( UseEmbeddedWidgets ) )
{
int widgetsCount = nodeL->customProperty( "embeddedWidgets/count", 0 ).toInt();
int widgetsCount = ml->customProperty( "embeddedWidgets/count", 0 ).toInt();
while ( widgetsCount > 0 )
{
lstNew.insert( 0, new EmbeddedWidgetLegendNode( nodeL ) );
@@ -58,7 +58,6 @@ class QDomElement;
* - "embedded_project" - path to the external project (embedded root node only)
* - "legend/..." - properties for legend appearance customization
* - "expandedLegendNodes" - list of layer's legend nodes' rules in expanded state
* - "embeddedWidgets/..." - properties for embedded widgets (layer node only)
*
* @see also QgsLayerTree, QgsLayerTreeLayer, QgsLayerTreeGroup
* @note added in 2.4
@@ -1,16 +1,21 @@
#include "qgslayertreeembeddedconfigwidget.h"

#include "qgslayertree.h"
#include "qgsmaplayer.h"
#include "qgslayertreeembeddedwidgetregistry.h"

#include <QStringListModel>
#include <QStandardItemModel>

QgsLayerTreeEmbeddedConfigWidget::QgsLayerTreeEmbeddedConfigWidget( QgsLayerTreeLayer* nodeLayer, QWidget* parent )
QgsLayerTreeEmbeddedConfigWidget::QgsLayerTreeEmbeddedConfigWidget( QWidget* parent )
: QWidget( parent )
, mNodeLayer( nodeLayer )
, mLayer( nullptr )
{
setupUi( this );
}

void QgsLayerTreeEmbeddedConfigWidget::setLayer( QgsMapLayer* layer )
{
mLayer = layer;

connect( mBtnAdd, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) );
connect( mBtnRemove, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) );
@@ -23,19 +28,21 @@ QgsLayerTreeEmbeddedConfigWidget::QgsLayerTreeEmbeddedConfigWidget( QgsLayerTree
{
QgsLayerTreeEmbeddedWidgetProvider* provider = QgsLayerTreeEmbeddedWidgetRegistry::instance()->provider( providerId );
QStandardItem* item = new QStandardItem( provider->name() );
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
item->setData( provider->id(), Qt::UserRole + 1 );
modelAvailable->appendRow( item );
}
mListAvailable->setModel( modelAvailable );

// populate used
int widgetsCount = nodeLayer->customProperty( "embeddedWidgets/count", 0 ).toInt();
int widgetsCount = layer->customProperty( "embeddedWidgets/count", 0 ).toInt();
for ( int i = 0; i < widgetsCount; ++i )
{
QString providerId = nodeLayer->customProperty( QString( "embeddedWidgets/%1/id" ).arg( i ) ).toString();
QString providerId = layer->customProperty( QString( "embeddedWidgets/%1/id" ).arg( i ) ).toString();
if ( QgsLayerTreeEmbeddedWidgetProvider* provider = QgsLayerTreeEmbeddedWidgetRegistry::instance()->provider( providerId ) )
{
QStandardItem* item = new QStandardItem( provider->name() );
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
item->setData( provider->id(), Qt::UserRole + 1 );
modelUsed->appendRow( item );
}
@@ -56,11 +63,10 @@ void QgsLayerTreeEmbeddedConfigWidget::onAddClicked()
if ( QStandardItemModel* model = qobject_cast<QStandardItemModel*>( mListUsed->model() ) )
{
QStandardItem* item = new QStandardItem( provider->name() );
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
item->setData( provider->id(), Qt::UserRole + 1 );
model->appendRow( item );
}

updateCustomProperties();
}

void QgsLayerTreeEmbeddedConfigWidget::onRemoveClicked()
@@ -70,25 +76,26 @@ void QgsLayerTreeEmbeddedConfigWidget::onRemoveClicked()

int row = mListUsed->currentIndex().row();
mListUsed->model()->removeRow( row );

updateCustomProperties();
}

void QgsLayerTreeEmbeddedConfigWidget::updateCustomProperties()
void QgsLayerTreeEmbeddedConfigWidget::applyToLayer()
{
if ( !mLayer )
return;

// clear old properties
int widgetsCount = mNodeLayer->customProperty( "embeddedWidgets/count", 0 ).toInt();
int widgetsCount = mLayer->customProperty( "embeddedWidgets/count", 0 ).toInt();
for ( int i = 0; i < widgetsCount; ++i )
{
mNodeLayer->removeCustomProperty( QString( "embeddedWidgets/%1/id" ).arg( i ) );
mLayer->removeCustomProperty( QString( "embeddedWidgets/%1/id" ).arg( i ) );
}

// setup new properties
int newCount = mListUsed->model()->rowCount();
mNodeLayer->setCustomProperty( "embeddedWidgets/count", newCount );
mLayer->setCustomProperty( "embeddedWidgets/count", newCount );
for ( int i = 0; i < newCount; ++i )
{
QString providerId = mListUsed->model()->data( mListUsed->model()->index( i, 0 ), Qt::UserRole + 1 ).toString();
mNodeLayer->setCustomProperty( QString( "embeddedWidgets/%1/id" ).arg( i ), providerId );
mLayer->setCustomProperty( QString( "embeddedWidgets/%1/id" ).arg( i ), providerId );
}
}
@@ -3,23 +3,24 @@

#include "ui_qgslayertreeembeddedconfigwidget.h"

class QgsLayerTreeLayer;
class QgsMapLayer;

class GUI_EXPORT QgsLayerTreeEmbeddedConfigWidget : public QWidget, protected Ui::QgsLayerTreeEmbeddedConfigWidget
{
Q_OBJECT
public:
QgsLayerTreeEmbeddedConfigWidget( QgsLayerTreeLayer* nodeLayer, QWidget* parent = nullptr );
QgsLayerTreeEmbeddedConfigWidget( QWidget* parent = nullptr );

void setLayer( QgsMapLayer* layer );

void applyToLayer();

private slots:
void onAddClicked();
void onRemoveClicked();

private:
void updateCustomProperties();

private:
QgsLayerTreeLayer* mNodeLayer;
QgsMapLayer* mLayer;
};

#endif // QGSLAYERTREEEMBEDDEDCONFIGWIDGET_H
@@ -137,12 +137,12 @@ void QgsLayerTreeView::modelRowsInserted( const QModelIndex& index, int start, i
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( parentNode );
if ( QgsMapLayer* layer = nodeLayer->layer() )
{
int widgetsCount = nodeLayer->customProperty( "embeddedWidgets/count", 0 ).toInt();
int widgetsCount = layer->customProperty( "embeddedWidgets/count", 0 ).toInt();
QList<QgsLayerTreeModelLegendNode*> legendNodes = layerTreeModel()->layerLegendNodes( nodeLayer );
for ( int i = 0; i < widgetsCount; ++i )
{
// TODO: check that the legend nodes are actually the placeholders for embedded widgets
QString providerId = nodeLayer->customProperty( QString( "embeddedWidgets/%1/id" ).arg( i ) ).toString();
QString providerId = layer->customProperty( QString( "embeddedWidgets/%1/id" ).arg( i ) ).toString();
if ( QgsLayerTreeEmbeddedWidgetProvider* provider = QgsLayerTreeEmbeddedWidgetRegistry::instance()->provider( providerId ) )
{
QModelIndex index = layerTreeModel()->legendNode2index( legendNodes[i] );
@@ -51,13 +51,21 @@
<property name="text">
<string>-&gt;</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionArrowRight.png</normaloff>:/images/themes/default/mActionArrowRight.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mBtnRemove">
<property name="text">
<string>&lt;-</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionArrowLeft.png</normaloff>:/images/themes/default/mActionArrowLeft.png</iconset>
</property>
</widget>
</item>
<item>
@@ -80,6 +88,8 @@
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../../images/images.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit 75e5da3

Please sign in to comment.
You can’t perform that action at this time.