Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add icon to layer and fields comboboxes in "map value" widget's Load … #59166

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 18 additions & 56 deletions src/gui/qgsattributetypeloaddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "qgsvectordataprovider.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsgui.h"
#include "qgshelp.h"

#include <QTableWidgetItem>
#include <QLineEdit>
Expand All @@ -39,16 +41,22 @@ QgsAttributeTypeLoadDialog::QgsAttributeTypeLoadDialog( QgsVectorLayer *vl )
: mLayer( vl )
{
setupUi( this );
QgsGui::enableAutoGeometryRestore( this );

connect( layerComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAttributeTypeLoadDialog::fillComboBoxes );
layerComboBox->setFilters( Qgis::LayerFilter::VectorLayer );
layerComboBox->setCurrentIndex( -1 );

connect( layerComboBox, &QgsMapLayerComboBox::layerChanged, keyComboBox, &QgsFieldComboBox::setLayer );
connect( layerComboBox, &QgsMapLayerComboBox::layerChanged, valueComboBox, &QgsFieldComboBox::setLayer );
connect( keyComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]( int index ) { createPreview( index ); } );
connect( valueComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]( int index ) { createPreview( index ); } );
connect( previewButton, &QAbstractButton::pressed, this, &QgsAttributeTypeLoadDialog::previewButtonPushed );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, [ = ]
{
QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#edit-widgets" ) );
} );

fillLayerList();

keyComboBox->setDisabled( true );
valueComboBox->setDisabled( true );
}

void QgsAttributeTypeLoadDialog::setVectorLayer( QgsVectorLayer *layer )
Expand All @@ -61,52 +69,6 @@ void QgsAttributeTypeLoadDialog::previewButtonPushed()
createPreview( valueComboBox->currentIndex(), true );
}

void QgsAttributeTypeLoadDialog::fillLayerList()
{
layerComboBox->blockSignals( true );
layerComboBox->clear();
const auto constMapLayers = QgsProject::instance()->mapLayers();
for ( QgsMapLayer *l : constMapLayers )
{
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer * >( l );
if ( vl )
layerComboBox->addItem( vl->name(), vl->id() );
}
layerComboBox->setCurrentIndex( -1 );
layerComboBox->blockSignals( false );
}

void QgsAttributeTypeLoadDialog::fillComboBoxes( int layerIndex )
{
keyComboBox->blockSignals( true );
valueComboBox->blockSignals( true );

//clear comboboxes first
keyComboBox->clear();
valueComboBox->clear();

QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layerIndex < 0 ? nullptr : QgsProject::instance()->mapLayer( layerComboBox->itemData( layerIndex ).toString() ) );
if ( vLayer )
{
QMap<QString, int> fieldMap = vLayer->dataProvider()->fieldNameMap();
QMap<QString, int>::iterator it = fieldMap.begin();
for ( ; it != fieldMap.end(); ++it )
{
keyComboBox->addItem( it.key(), it.value() );
valueComboBox->addItem( it.key(), it.value() );
}
}

keyComboBox->setEnabled( nullptr != vLayer );
valueComboBox->setEnabled( nullptr != vLayer );

keyComboBox->setCurrentIndex( -1 );
valueComboBox->setCurrentIndex( -1 );

keyComboBox->blockSignals( false );
valueComboBox->blockSignals( false );
}

void QgsAttributeTypeLoadDialog::createPreview( int fieldIndex, bool full )
{
previewTableWidget->clearContents();
Expand All @@ -120,9 +82,9 @@ void QgsAttributeTypeLoadDialog::createPreview( int fieldIndex, bool full )
//when nothing is selected there is no reason for preview
return;
}
const int idx = keyComboBox->currentData().toInt();
const int idx2 = valueComboBox->currentData().toInt();
QgsMapLayer *dataLayer = QgsProject::instance()->mapLayer( layerComboBox->currentData().toString() );
const int idx = keyComboBox->currentIndex();
const int idx2 = valueComboBox->currentIndex();
QgsMapLayer *dataLayer = layerComboBox->currentLayer();
QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
if ( !vLayer )
return;
Expand Down Expand Up @@ -169,9 +131,9 @@ bool QgsAttributeTypeLoadDialog::insertNull()
void QgsAttributeTypeLoadDialog::loadDataToValueMap()
{
mValueMap.clear();
const int idx = keyComboBox->currentData().toInt();
const int idx2 = valueComboBox->currentData().toInt();
QgsMapLayer *dataLayer = QgsProject::instance()->mapLayer( layerComboBox->currentData().toString() );
const int idx = keyComboBox->currentIndex();
const int idx2 = valueComboBox->currentIndex();
QgsMapLayer *dataLayer = layerComboBox->currentLayer();
QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
if ( !vLayer )
return;
Expand Down
11 changes: 0 additions & 11 deletions src/gui/qgsattributetypeloaddialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ class GUI_EXPORT QgsAttributeTypeLoadDialog: public QDialog, private Ui::QgsAttr

private slots:

/**
* Slot which reacts to change of selected layer to fill other two comboboxes with correct data
* \param layerIndex index of layer which was selected
*/
void fillComboBoxes( int layerIndex );

/**
* Slot to react to button push or change of selected column for display of preview
* \param fieldIndex indexOfChangedField
Expand All @@ -88,11 +82,6 @@ class GUI_EXPORT QgsAttributeTypeLoadDialog: public QDialog, private Ui::QgsAttr

private:

/**
* Internal function to fill the list of layers
*/
void fillLayerList();

/**
* Function to transfer data from layer to value map used in editing
*/
Expand Down
20 changes: 16 additions & 4 deletions src/ui/qgsattributeloadfrommap.ui
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="layerComboBox"/>
<widget class="QgsMapLayerComboBox" name="layerComboBox"/>
</item>
<item row="5" column="0" colspan="3">
<widget class="QTableWidget" name="previewTableWidget">
Expand Down Expand Up @@ -62,7 +62,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="valueComboBox"/>
<widget class="QgsFieldComboBox" name="valueComboBox"/>
</item>
<item row="2" column="2" rowspan="2">
<widget class="QPushButton" name="previewButton">
Expand All @@ -72,7 +72,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="keyComboBox"/>
<widget class="QgsFieldComboBox" name="keyComboBox"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="nullCheckBox">
Expand All @@ -89,12 +89,24 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsFieldComboBox</class>
<extends>QComboBox</extends>
<header>qgsfieldcombobox.h</header>
</customwidget>
<customwidget>
<class>QgsMapLayerComboBox</class>
<extends>QComboBox</extends>
<header>qgsmaplayercombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>layerComboBox</tabstop>
<tabstop>valueComboBox</tabstop>
Expand Down