Skip to content

Commit

Permalink
[composer] Use QgsMapLayerComboBox for attribute table layer selection
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 14, 2014
1 parent 114d46c commit 85b6b0b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 72 deletions.
71 changes: 20 additions & 51 deletions src/app/composer/qgscomposertablewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,8 @@ QgsComposerTableWidget::QgsComposerTableWidget( QgsComposerAttributeTable* table
mainLayout->addWidget( itemPropertiesWidget );

blockAllSignals( true );

//insert vector layers into combo
QMap<QString, QgsMapLayer*> layerMap = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*>::const_iterator mapIt = layerMap.constBegin();

for ( ; mapIt != layerMap.constEnd(); ++mapIt )
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( mapIt.value() );
if ( vl )
{
mLayerComboBox->addItem( vl->name(), mapIt.key() );
}
}
mLayerComboBox->setFilters( QgsMapLayerProxyModel::HasGeometry );
connect( mLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( changeLayer( QgsMapLayer* ) ) );

refreshMapComboBox();

Expand Down Expand Up @@ -105,35 +94,6 @@ void QgsComposerTableWidget::refreshMapComboBox()
}
}

void QgsComposerTableWidget::on_mLayerComboBox_currentIndexChanged( int index )
{
if ( !mComposerTable )
{
return;
}

//set new layer to table item
QVariant itemData = mLayerComboBox->itemData( index );
if ( itemData.type() == QVariant::Invalid )
{
return;
}

QString layerId = itemData.toString();
QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
if ( ml )
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( ml );
if ( vl )
{
mComposerTable->beginCommand( tr( "Table layer changed" ) );
mComposerTable->setVectorLayer( vl );
mComposerTable->update();
mComposerTable->endCommand();
}
}
}

void QgsComposerTableWidget::on_mAttributesPushButton_clicked()
{
if ( !mComposerTable )
Expand Down Expand Up @@ -303,15 +263,7 @@ void QgsComposerTableWidget::updateGuiElements()
blockAllSignals( true );

//layer combo box
const QgsVectorLayer* vl = mComposerTable->vectorLayer();
if ( vl )
{
int layerIndex = mLayerComboBox->findText( vl->name() );
if ( layerIndex != -1 )
{
mLayerComboBox->setCurrentIndex( layerIndex );
}
}
mLayerComboBox->setLayer( mComposerTable->vectorLayer() );

//map combo box
const QgsComposerMap* cm = mComposerTable->composerMap();
Expand Down Expand Up @@ -447,3 +399,20 @@ void QgsComposerTableWidget::on_mFeatureFilterButton_clicked()
}
}
}

void QgsComposerTableWidget::changeLayer( QgsMapLayer *layer )
{
if ( !mComposerTable )
{
return;
}

QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer );
if ( vl )
{
mComposerTable->beginCommand( tr( "Table layer changed" ) );
mComposerTable->setVectorLayer( vl );
mComposerTable->update();
mComposerTable->endCommand();
}
}
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposertablewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class QgsComposerTableWidget: public QWidget, private Ui::QgsComposerTableWidget
void refreshMapComboBox();

private slots:
void on_mLayerComboBox_currentIndexChanged( int index );
void on_mAttributesPushButton_clicked();
void on_mComposerMapComboBox_activated( int index );
void on_mMaximumColumnsSpinBox_valueChanged( int i );
Expand All @@ -54,6 +53,7 @@ class QgsComposerTableWidget: public QWidget, private Ui::QgsComposerTableWidget
void on_mFeatureFilterCheckBox_stateChanged( int state );
void on_mFeatureFilterEdit_editingFinished();
void on_mFeatureFilterButton_clicked();
void changeLayer( QgsMapLayer* layer );

/**Inserts a new maximum number of features into the spin box (without the spinbox emitting a signal)*/
void setMaximumNumberOfFeatures( int n );
Expand Down
49 changes: 29 additions & 20 deletions src/ui/qgscomposertablewidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,16 @@
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="buddy">
<cstring>mLayerComboBox</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mLayerComboBox"/>
</item>
<item row="2" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="mShowOnlyVisibleFeaturesCheckBox">
<property name="text">
<string>Show only visible features</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="10" column="0">
<widget class="QLabel" name="mComposerMapLabel">
<property name="text">
<string>Composer map</string>
Expand All @@ -99,17 +93,17 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="10" column="1">
<widget class="QComboBox" name="mComposerMapComboBox"/>
</item>
<item row="4" column="0">
<item row="12" column="0">
<widget class="QCheckBox" name="mFeatureFilterCheckBox">
<property name="text">
<string>Filter with</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="12" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="mFeatureFilterEdit"/>
Expand All @@ -127,7 +121,7 @@
</item>
</layout>
</item>
<item row="5" column="0">
<item row="14" column="0">
<widget class="QLabel" name="mMaxNumFeaturesLabel">
<property name="text">
<string>Maximum rows</string>
Expand All @@ -140,10 +134,10 @@
</property>
</widget>
</item>
<item row="5" column="1">
<item row="14" column="1">
<widget class="QSpinBox" name="mMaximumColumnsSpinBox"/>
</item>
<item row="6" column="0">
<item row="16" column="0">
<widget class="QLabel" name="mMarginLabel">
<property name="text">
<string>Margin</string>
Expand All @@ -156,10 +150,20 @@
</property>
</widget>
</item>
<item row="6" column="1">
<item row="16" column="1">
<widget class="QDoubleSpinBox" name="mMarginSpinBox"/>
</item>
<item row="1" column="0" colspan="2">
<item row="0" column="1">
<widget class="QgsMapLayerComboBox" name="mLayerComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="mAttributesPushButton">
<property name="text">
<string>Attributes...</string>
Expand Down Expand Up @@ -259,16 +263,21 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButton</class>
<extends>QPushButton</extends>
<header>qgscolorbutton.h</header>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBoxBasic</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<header location="global">qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QPushButton</extends>
<header>qgscolorbutton.h</header>
<class>QgsMapLayerComboBox</class>
<extends>QComboBox</extends>
<header location="global">qgsmaplayercombobox.h</header>
</customwidget>
</customwidgets>
<resources>
Expand Down

0 comments on commit 85b6b0b

Please sign in to comment.