Skip to content
Permalink
Browse files

Change widget selection list to combobox

  • Loading branch information
m-kuhn committed Sep 28, 2017
1 parent 630b567 commit 431250499ff0945f6a78ec2dd0a02eb4df27844e
@@ -60,7 +60,6 @@ void QgsAttributesFormProperties::init()

void QgsAttributesFormProperties::loadAttributeTypeDialog()
{

FieldConfig cfg;

int index = mDragTree->mIndexedWidgets.indexOf( mDragTree->currentItem() );
@@ -118,7 +117,6 @@ void QgsAttributesFormProperties::loadAttributeTypeDialog()

void QgsAttributesFormProperties::storeAttributeTypeDialog()
{

FieldConfig cfg;

cfg.mEditable = mAttributeTypeDialog->fieldEditable();
@@ -48,22 +48,18 @@ QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl, int fieldIdx
setWindowTitle( tr( "Edit Widget Properties - %1 (%2)" ).arg( vl->fields().at( fieldIdx ).name(), vl->name() ) );

QMapIterator<QString, QgsEditorWidgetFactory *> it( QgsGui::editorWidgetRegistry()->factories() );
QStandardItemModel *widgetTypeModel = qobject_cast<QStandardItemModel *>( mWidgetTypeComboBox->model() );
while ( it.hasNext() )
{
it.next();
QListWidgetItem *item = new QListWidgetItem( selectionListWidget );
item->setText( it.value()->name() );
item->setData( Qt::UserRole, it.key() );
mWidgetTypeComboBox->addItem( it.value()->name(), it.key() );
QStandardItem *item = widgetTypeModel->item( mWidgetTypeComboBox->count() - 1 );
item->setData( it.key(), Qt::UserRole );
if ( !it.value()->supportsField( vl, fieldIdx ) )
item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
selectionListWidget->addItem( item );
}

// Set required list width based on content + twice the border width
selectionListWidget->setMinimumWidth( selectionListWidget->sizeHintForColumn( 0 )
+ 2 );
selectionListWidget->setMaximumWidth( selectionListWidget->sizeHintForColumn( 0 )
+ 2 );
connect( mWidgetTypeComboBox, static_cast< void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAttributeTypeDialog::onCurrentWidgetChanged );

if ( vl->fields().fieldOrigin( fieldIdx ) == QgsFields::OriginJoin ||
vl->fields().fieldOrigin( fieldIdx ) == QgsFields::OriginExpression )
@@ -105,7 +101,7 @@ QgsAttributeTypeDialog::~QgsAttributeTypeDialog()

const QString QgsAttributeTypeDialog::editorWidgetType()
{
QListWidgetItem *item = selectionListWidget->currentItem();
QStandardItem *item = currentItem();
if ( item )
{
return item->data( Qt::UserRole ).toString();
@@ -118,7 +114,7 @@ const QString QgsAttributeTypeDialog::editorWidgetType()

const QString QgsAttributeTypeDialog::editorWidgetText()
{
QListWidgetItem *item = selectionListWidget->currentItem();
QStandardItem *item = currentItem();
if ( item )
{
return item->text();
@@ -131,7 +127,7 @@ const QString QgsAttributeTypeDialog::editorWidgetText()

const QVariantMap QgsAttributeTypeDialog::editorWidgetConfig()
{
QListWidgetItem *item = selectionListWidget->currentItem();
QStandardItem *item = currentItem();
if ( item )
{
QString widgetType = item->data( Qt::UserRole ).toString();
@@ -147,15 +143,7 @@ const QVariantMap QgsAttributeTypeDialog::editorWidgetConfig()

void QgsAttributeTypeDialog::setEditorWidgetType( const QString &type )
{
for ( int i = 0; i < selectionListWidget->count(); i++ )
{
QListWidgetItem *item = selectionListWidget->item( i );
if ( item->data( Qt::UserRole ).toString() == type )
{
selectionListWidget->setCurrentItem( item );
break;
}
}
mWidgetTypeComboBox->setCurrentIndex( mWidgetTypeComboBox->findData( type ) );

if ( mEditorConfigWidgets.contains( type ) )
{
@@ -313,6 +301,14 @@ QgsExpressionContext QgsAttributeTypeDialog::createExpressionContext() const
return context;
}

void QgsAttributeTypeDialog::onCurrentWidgetChanged( int index )
{
QStandardItem *item = currentItem();
const QString editType = item ? item->data( Qt::UserRole ).toString() : QString();

setEditorWidgetType( editType );
}

QString QgsAttributeTypeDialog::constraintExpression() const
{
return constraintExpressionWidget->asExpression();
@@ -328,13 +324,6 @@ void QgsAttributeTypeDialog::setLabelOnTop( bool onTop )
labelOnTopCheckBox->setChecked( onTop );
}

void QgsAttributeTypeDialog::on_selectionListWidget_currentRowChanged( int index )
{
const QString editType = selectionListWidget->item( index )->data( Qt::UserRole ).toString();

setEditorWidgetType( editType );
}

void QgsAttributeTypeDialog::defaultExpressionChanged()
{
QString expression = mExpressionWidget->expression();
@@ -377,3 +366,9 @@ void QgsAttributeTypeDialog::defaultExpressionChanged()

mDefaultPreviewLabel->setText( "<i>" + previewText + "</i>" );
}

QStandardItem *QgsAttributeTypeDialog::currentItem() const
{
QStandardItemModel *widgetTypeModel = qobject_cast<QStandardItemModel *>( mWidgetTypeComboBox->model() );
return widgetTypeModel->item( mWidgetTypeComboBox->currentIndex() );
}
@@ -25,6 +25,7 @@
#include "qgis_app.h"

class QWidget;
class QStandardItem;

class APP_EXPORT QgsAttributeTypeDialog: public QWidget, private Ui::QgsAttributeTypeDialog, QgsExpressionContextGenerator
{
@@ -176,7 +177,7 @@ class APP_EXPORT QgsAttributeTypeDialog: public QWidget, private Ui::QgsAttribut
* Slot to handle change of index in combobox to select correct page
* \param index index of value in combobox
*/
void on_selectionListWidget_currentRowChanged( int index );
void onCurrentWidgetChanged( int index );

void defaultExpressionChanged();

@@ -189,6 +190,8 @@ class APP_EXPORT QgsAttributeTypeDialog: public QWidget, private Ui::QgsAttribut
//! Cached configuration dialog (lazy loaded)
QMap< QString, QgsEditorConfigWidget * > mEditorConfigWidgets;

QStandardItem *currentItem() const;

QgsFeature mPreviewFeature;
};

@@ -14,6 +14,67 @@
<string>Edit Widget Properties</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QCheckBox" name="isFieldEditableCheckBox">
<property name="text">
<string>Editable</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="labelOnTopCheckBox">
<property name="text">
<string>Label on top</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Defaults</string>
</property>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,1">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Default value</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Preview</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsExpressionLineEdit" name="mExpressionWidget" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="mDefaultPreviewLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QgsCollapsibleGroupBox" name="groupBox">
<property name="focusPolicy">
@@ -104,89 +165,18 @@
</layout>
</widget>
</item>
<item row="6" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QCheckBox" name="isFieldEditableCheckBox">
<property name="text">
<string>Editable</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="labelOnTopCheckBox">
<property name="text">
<string>Label on top</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Defaults</string>
</property>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,1">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Default value</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Preview</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsExpressionLineEdit" name="mExpressionWidget" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="mDefaultPreviewLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Widget Type</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="selectionListWidget"/>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_5">
<item row="1" column="1">
<widget class="QStackedWidget" name="stackedWidget"/>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mWidgetTypeComboBox"/>
</item>
</layout>
</widget>
</item>
@@ -213,7 +203,6 @@
</customwidget>
</customwidgets>
<tabstops>
<tabstop>selectionListWidget</tabstop>
<tabstop>isFieldEditableCheckBox</tabstop>
<tabstop>labelOnTopCheckBox</tabstop>
<tabstop>mExpressionWidget</tabstop>
@@ -227,38 +216,5 @@
<tabstop>mCheckBoxEnforceExpression</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QgsAttributeTypeDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>520</x>
<y>435</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsAttributeTypeDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>588</x>
<y>435</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>

0 comments on commit 4312504

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