Skip to content

Commit

Permalink
more edit widget fixes:
Browse files Browse the repository at this point in the history
- 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 18475b8
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 75 deletions.
94 changes: 56 additions & 38 deletions src/app/qgsattributetypedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsfieldsproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -534,7 +535,6 @@ void QgsFieldsProperties::attributeTypeDialog()
case QgsVectorLayer::Immutable:
case QgsVectorLayer::Hidden:
case QgsVectorLayer::UuidGenerator:
case QgsVectorLayer::WebView:
case QgsVectorLayer::Color:
break;
}
Expand Down Expand Up @@ -875,6 +875,7 @@ void QgsFieldsProperties::apply()
break;

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

Expand All @@ -888,7 +889,6 @@ void QgsFieldsProperties::apply()
case QgsVectorLayer::Hidden:
case QgsVectorLayer::TextEdit:
case QgsVectorLayer::UuidGenerator:
case QgsVectorLayer::WebView:
case QgsVectorLayer::Color:
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -1953,7 +1954,6 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
case UniqueValues:
case UniqueValuesEditable:
case UuidGenerator:
case WebView:
case Color:
break;
}
Expand Down Expand Up @@ -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;
Expand All @@ -2260,7 +2261,6 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
case Enumeration:
case Immutable:
case UuidGenerator:
case WebView:
case Color:
break;
}
Expand Down
1 change: 0 additions & 1 deletion src/gui/qgsattributedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
55 changes: 52 additions & 3 deletions src/gui/qgsattributeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 5 additions & 29 deletions src/ui/qgsattributetypeedit.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down

0 comments on commit 18475b8

Please sign in to comment.