Skip to content
Permalink
Browse files

more edit widget fixes:

- handle editable state in drag&drop forms like in automatically generated
  forms
- allow to set minimum size of webview "edit" widgets.
  • Loading branch information
jef-n committed Jun 5, 2013
1 parent f23353c commit 18475b8ad76125bedf8ed997c5f96da669510ae9
@@ -523,6 +523,7 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT
break;

case QgsVectorLayer::Photo:
case QgsVectorLayer::WebView:
sbWidgetWidth->setValue( mWidgetSize.width() );
sbWidgetHeight->setValue( mWidgetSize.height() );
break;
@@ -537,7 +538,6 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT
case QgsVectorLayer::Hidden:
case QgsVectorLayer::TextEdit:
case QgsVectorLayer::UuidGenerator:
case QgsVectorLayer::WebView:
case QgsVectorLayer::Color:
break;
}
@@ -551,47 +551,64 @@ void QgsAttributeTypeDialog::setPage( int index )

void QgsAttributeTypeDialog::setStackPage( int index )
{
stackedWidget->setCurrentIndex( index );

bool okDisabled = false;
if ( index == 2 )
{
if ( mLayer->pendingFields()[mIndex].type() != QVariant::Double &&
mLayer->pendingFields()[mIndex].type() != QVariant::Int )
{
okDisabled = true;
}
else if ( mLayer->pendingFields()[mIndex].type() != QVariant::Double )
{
rangeStackedWidget->setCurrentIndex( 0 );
//load data
minimumSpinBox->setValue( mRangeData.mMin.toInt() );
maximumSpinBox->setValue( mRangeData.mMax.toInt() );
stepSpinBox->setValue( mRangeData.mStep.toInt() );
}
else
{
rangeStackedWidget->setCurrentIndex( 1 );
//load data
minimumDoubleSpinBox->setValue( mRangeData.mMin.toDouble() );
maximumDoubleSpinBox->setValue( mRangeData.mMax.toDouble() );
stepDoubleSpinBox->setValue( mRangeData.mStep.toDouble() );
}
}
else if ( index == 6 )

switch ( index )
{
QStringList list;
mLayer->dataProvider()->enumValues( mIndex, list );
if ( list.size() == 0 )
{
okDisabled = true;
enumerationWarningLabel->setText( tr( "Enumeration is not available for this attribute" ) );
}
else
case 2:
if ( mLayer->pendingFields()[mIndex].type() != QVariant::Double &&
mLayer->pendingFields()[mIndex].type() != QVariant::Int )
{
okDisabled = true;
}
else if ( mLayer->pendingFields()[mIndex].type() != QVariant::Double )
{
rangeStackedWidget->setCurrentIndex( 0 );
//load data
minimumSpinBox->setValue( mRangeData.mMin.toInt() );
maximumSpinBox->setValue( mRangeData.mMax.toInt() );
stepSpinBox->setValue( mRangeData.mStep.toInt() );
}
else
{
rangeStackedWidget->setCurrentIndex( 1 );
//load data
minimumDoubleSpinBox->setValue( mRangeData.mMin.toDouble() );
maximumDoubleSpinBox->setValue( mRangeData.mMax.toDouble() );
stepDoubleSpinBox->setValue( mRangeData.mStep.toDouble() );
}
stackedWidget->setCurrentIndex( 2 );
break;
case 6:
{
enumerationWarningLabel->setText( "" );
QStringList list;
mLayer->dataProvider()->enumValues( mIndex, list );
if ( list.size() == 0 )
{
okDisabled = true;
enumerationWarningLabel->setText( tr( "Enumeration is not available for this attribute" ) );
}
else
{
enumerationWarningLabel->setText( "" );
}
stackedWidget->setCurrentIndex( 6 );
}

break;
case 14:
pictureOrUrlLabel->setText( tr( "Field contains a filename for a picture" ) );
stackedWidget->setCurrentIndex( 14 );
break;
case 15:
pictureOrUrlLabel->setText( tr( "Field contains an URL" ) );
stackedWidget->setCurrentIndex( 14 );
break;
case 16:
stackedWidget->setCurrentIndex( 15 );
break;
default:
stackedWidget->setCurrentIndex( index );
break;
}

stackedWidget->currentWidget()->setDisabled( okDisabled );
@@ -713,6 +730,7 @@ void QgsAttributeTypeDialog::accept()
break;
case 15:
mEditType = QgsVectorLayer::WebView;
mWidgetSize = QSize( sbWidgetWidth->value(), sbWidgetHeight->value() );
break;
case 16:
mEditType = QgsVectorLayer::Color;
@@ -522,6 +522,7 @@ void QgsFieldsProperties::attributeTypeDialog()
cfg.mDateFormat = attributeTypeDialog.dateFormat();
break;
case QgsVectorLayer::Photo:
case QgsVectorLayer::WebView:
cfg.mWidgetSize = attributeTypeDialog.widgetSize();
break;
case QgsVectorLayer::LineEdit:
@@ -534,7 +535,6 @@ void QgsFieldsProperties::attributeTypeDialog()
case QgsVectorLayer::Immutable:
case QgsVectorLayer::Hidden:
case QgsVectorLayer::UuidGenerator:
case QgsVectorLayer::WebView:
case QgsVectorLayer::Color:
break;
}
@@ -875,6 +875,7 @@ void QgsFieldsProperties::apply()
break;

case QgsVectorLayer::Photo:
case QgsVectorLayer::WebView:
mLayer->widgetSize( idx ) = cfg.mWidgetSize;
break;

@@ -888,7 +889,6 @@ void QgsFieldsProperties::apply()
case QgsVectorLayer::Hidden:
case QgsVectorLayer::TextEdit:
case QgsVectorLayer::UuidGenerator:
case QgsVectorLayer::WebView:
case QgsVectorLayer::Color:
break;
}
@@ -1940,6 +1940,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
break;

case Photo:
case WebView:
mWidgetSize[ name ] = QSize( editTypeElement.attribute( "widgetWidth" ).toInt(), editTypeElement.attribute( "widgetHeight" ).toInt() );
break;

@@ -1953,7 +1954,6 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
case UniqueValues:
case UniqueValuesEditable:
case UuidGenerator:
case WebView:
case Color:
break;
}
@@ -2246,6 +2246,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
break;

case Photo:
case WebView:
editTypeElement.setAttribute( "widgetWidth", mWidgetSize[ it.key()].width() );
editTypeElement.setAttribute( "widgetHeight", mWidgetSize[ it.key()].height() );
break;
@@ -2260,7 +2261,6 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
case Enumeration:
case Immutable:
case UuidGenerator:
case WebView:
case Color:
break;
}
@@ -174,7 +174,6 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
{
//show attribute alias if available
QString myFieldName = vl->attributeDisplayName( fldIdx );
int myFieldType = theFields[fldIdx].type();

QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, 0, vl, fldIdx, myAttributes[fldIdx], mProxyWidgets );
if ( !myWidget )
@@ -730,6 +730,17 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
#ifdef QGISDEBUG
ww->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
#endif

QSize size( vl->widgetSize( idx ) );
if ( size.width() > 0 || size.height() > 0 )
{
if ( size.width() == 0 )
size.setWidth( 1 );
if ( size.height() == 0 )
size.setHeight( 1 );
ww->setMinimumSize( size );
}

myWidget = ww;
break;
}
@@ -811,6 +822,17 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
#ifdef QGISDEBUG
ww->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
#endif

QSize size( vl->widgetSize( idx ) );
if ( size.width() > 0 || size.height() > 0 )
{
if ( size.width() == 0 )
size.setWidth( 1 );
if ( size.height() == 0 )
size.setHeight( 1 );
ww->setMinimumSize( size );
}

layout->addWidget( ww, 0, 0, 1, 2 );
row++;
}
@@ -1324,11 +1346,38 @@ QWidget* QgsAttributeEditor::createWidgetFromDef( const QgsAttributeEditorElemen
case QgsAttributeEditorElement::AeTypeField:
{
const QgsAttributeEditorField* fieldDef = dynamic_cast<const QgsAttributeEditorField*>( widgetDef );
newWidget = createAttributeEditor( parent, 0, vl, fieldDef->idx(), attrs.value( fieldDef->idx(), QVariant() ), proxyWidgets );
int fldIdx = fieldDef->idx();
newWidget = createAttributeEditor( parent, 0, vl, fldIdx, attrs.value( fldIdx, QVariant() ), proxyWidgets );

if ( vl->editType( fieldDef->idx() ) != QgsVectorLayer::Immutable )
if ( vl->editType( fldIdx ) != QgsVectorLayer::Immutable )
{
newWidget->setEnabled( newWidget->isEnabled() && vl->isEditable() );
if ( newWidget->isEnabled() && vl->isEditable() && vl->fieldEditable( fldIdx ) )
{
newWidget->setEnabled( true );
}
else if ( vl->editType( fldIdx ) == QgsVectorLayer::Photo )
{
foreach ( QWidget *w, newWidget->findChildren<QWidget *>() )
{
w->setEnabled( qobject_cast<QLabel *>( w ) ? true : false );
}
}
else if ( vl->editType( fldIdx ) == QgsVectorLayer::WebView )
{
foreach ( QWidget *w, newWidget->findChildren<QWidget *>() )
{
if ( qobject_cast<QWebView *>( w ) )
w->setEnabled( true );
else if ( qobject_cast<QPushButton *>( w ) && w->objectName() == "openUrl" )
w->setEnabled( true );
else
w->setEnabled( false );
}
}
else
{
newWidget->setEnabled( false );
}
}

break;
@@ -132,7 +132,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>16</number>
<number>14</number>
</property>
<widget class="QWidget" name="lineEditPage">
<layout class="QVBoxLayout" name="verticalLayout_1">
@@ -786,7 +786,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page">
<widget class="QWidget" name="pictureOrUrlPage">
<layout class="QGridLayout" name="gridLayout_6">
<item row="2" column="0">
<widget class="QLabel" name="label_13">
@@ -836,39 +836,15 @@
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_11">
<widget class="QLabel" name="pictureOrUrlLabel">
<property name="text">
<string>Field contains a filename for a picture</string>
<string notr="true">Field contains a filename for a picture</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>Fields contains an URL</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_13">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_3">
<widget class="QWidget" name="colorPage">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QLabel" name="label_15">

0 comments on commit 18475b8

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