Skip to content

Commit

Permalink
[FEATURE] add widgets for photos and webpages
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Mar 31, 2013
1 parent 04d1611 commit b27b6a9
Show file tree
Hide file tree
Showing 9 changed files with 434 additions and 111 deletions.
32 changes: 32 additions & 0 deletions src/app/qgsattributetypedialog.cpp
Expand Up @@ -84,6 +84,11 @@ QString QgsAttributeTypeDialog::dateFormat()
return mDateFormat;
}

QSize QgsAttributeTypeDialog::widgetSize()
{
return mWidgetSize;
}

QMap<QString, QVariant> &QgsAttributeTypeDialog::valueMap()
{
return mValueMap;
Expand Down Expand Up @@ -325,6 +330,14 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy
case QgsVectorLayer::UuidGenerator:
setPage( 13 );
break;

case QgsVectorLayer::Photo:
setPage( 14 );
break;

case QgsVectorLayer::Webview:
setPage( 15 );
break;
}
}

Expand All @@ -348,6 +361,11 @@ void QgsAttributeTypeDialog::setDateFormat( QString dateFormat )
mDateFormat = dateFormat;
}

void QgsAttributeTypeDialog::setWidgetSize( QSize widgetSize )
{
mWidgetSize = widgetSize;
}

void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editType )
{
mIndex = index;
Expand Down Expand Up @@ -490,6 +508,11 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT
leDateFormat->setText( mDateFormat );
break;

case QgsVectorLayer::Photo:
sbWidgetWidth->setValue( mWidgetSize.width() );
sbWidgetHeight->setValue( mWidgetSize.height() );
break;

case QgsVectorLayer::LineEdit:
case QgsVectorLayer::UniqueValues:
case QgsVectorLayer::Classification:
Expand All @@ -500,6 +523,7 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT
case QgsVectorLayer::Hidden:
case QgsVectorLayer::TextEdit:
case QgsVectorLayer::UuidGenerator:
case QgsVectorLayer::Webview:
break;
}
}
Expand Down Expand Up @@ -554,6 +578,7 @@ void QgsAttributeTypeDialog::setStackPage( int index )
}

}

stackedWidget->currentWidget()->setDisabled( okDisabled );
buttonBox->button( QDialogButtonBox::Ok )->setDisabled( okDisabled );
}
Expand Down Expand Up @@ -667,6 +692,13 @@ void QgsAttributeTypeDialog::accept()
case 13:
mEditType = QgsVectorLayer::UuidGenerator;
break;
case 14:
mEditType = QgsVectorLayer::Photo;
mWidgetSize = QSize( sbWidgetWidth->value(), sbWidgetHeight->value() );
break;
case 15:
mEditType = QgsVectorLayer::Webview;
break;
}

QDialog::accept();
Expand Down
12 changes: 12 additions & 0 deletions src/app/qgsattributetypedialog.h
Expand Up @@ -88,6 +88,12 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
*/
void setDateFormat( QString dateFormat );

/**
* Setter to widget size
* @param widgetSize size of widget
*/
void setWidgetSize( QSize widgetSize );

/**
* Setter for checkbox for editable state of field
* @param bool editable
Expand Down Expand Up @@ -122,6 +128,11 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
*/
QString dateFormat();

/**
* Getter for widget size
*/
QSize widgetSize();

/**
* Getter for checkbox for editable state of field
*/
Expand Down Expand Up @@ -193,6 +204,7 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
QgsVectorLayer::ValueRelationData mValueRelationData;
QgsVectorLayer::EditType mEditType;
QString mDateFormat;
QSize mWidgetSize;
};

#endif
16 changes: 15 additions & 1 deletion src/app/qgsfieldsproperties.cpp
Expand Up @@ -488,7 +488,7 @@ void QgsFieldsProperties::attributeTypeDialog()
attributeTypeDialog.setCheckedState( checkStates.first, checkStates.second );

attributeTypeDialog.setDateFormat( mDateFormat.value( index, mLayer->dateFormat( index ) ) );

attributeTypeDialog.setWidgetSize( mWidgetSize.value( index, mLayer->widgetSize( index ) ) );
attributeTypeDialog.setFieldEditable( mFieldEditables.value( index, mLayer->fieldEditable( index ) ) );

attributeTypeDialog.setIndex( index, mEditTypeMap.value( index, mLayer->editType( index ) ) );
Expand Down Expand Up @@ -522,6 +522,9 @@ void QgsFieldsProperties::attributeTypeDialog()
case QgsVectorLayer::Calendar:
mDateFormat.insert( index, attributeTypeDialog.dateFormat() );
break;
case QgsVectorLayer::Photo:
mWidgetSize.insert( index, attributeTypeDialog.widgetSize() );
break;
case QgsVectorLayer::LineEdit:
case QgsVectorLayer::TextEdit:
case QgsVectorLayer::UniqueValues:
Expand All @@ -532,6 +535,7 @@ void QgsFieldsProperties::attributeTypeDialog()
case QgsVectorLayer::Immutable:
case QgsVectorLayer::Hidden:
case QgsVectorLayer::UuidGenerator:
case QgsVectorLayer::Webview:
break;
}

Expand Down Expand Up @@ -741,6 +745,8 @@ void QgsFieldsProperties::setupEditTypes()
editTypeMap.insert( QgsVectorLayer::Calendar, tr( "Calendar" ) );
editTypeMap.insert( QgsVectorLayer::ValueRelation, tr( "Value relation" ) );
editTypeMap.insert( QgsVectorLayer::UuidGenerator, tr( "UUID generator" ) );
editTypeMap.insert( QgsVectorLayer::Photo, tr( "Photo" ) );
editTypeMap.insert( QgsVectorLayer::Webview, tr( "Webview" ) );
}

QString QgsFieldsProperties::editTypeButtonText( QgsVectorLayer::EditType type )
Expand Down Expand Up @@ -868,6 +874,13 @@ void QgsFieldsProperties::apply()
}
break;

case QgsVectorLayer::Photo:
if ( mWidgetSize.contains( idx ) )
{
mLayer->widgetSize( idx ) = mWidgetSize[idx];
}
break;

case QgsVectorLayer::LineEdit:
case QgsVectorLayer::UniqueValues:
case QgsVectorLayer::UniqueValuesEditable:
Expand All @@ -878,6 +891,7 @@ void QgsFieldsProperties::apply()
case QgsVectorLayer::Hidden:
case QgsVectorLayer::TextEdit:
case QgsVectorLayer::UuidGenerator:
case QgsVectorLayer::Webview:
break;
}

Expand Down
1 change: 1 addition & 0 deletions src/app/qgsfieldsproperties.h
Expand Up @@ -131,6 +131,7 @@ class QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPropertiesBase
QMap<int, QgsVectorLayer::EditType> mEditTypeMap;
QMap<int, QPushButton*> mButtonMap;
QMap<int, QString> mDateFormat;
QMap<int, QSize> mWidgetSize;

enum attrColumns
{
Expand Down
23 changes: 23 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2409,6 +2409,10 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
mDateFormats[ name ] = editTypeElement.attribute( "dateFormat" );
break;

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

case Classification:
case FileName:
case Immutable:
Expand All @@ -2419,6 +2423,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
case UniqueValues:
case UniqueValuesEditable:
case UuidGenerator:
case Webview:
break;
}
}
Expand Down Expand Up @@ -2728,6 +2733,11 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
editTypeElement.setAttribute( "dateFormat", mDateFormats[ it.key()] );
break;

case Photo:
editTypeElement.setAttribute( "widgetWidth", mWidgetSize[ it.key()].width() );
editTypeElement.setAttribute( "widgetHeight", mWidgetSize[ it.key()].height() );
break;

case LineEdit:
case UniqueValues:
case UniqueValuesEditable:
Expand All @@ -2738,6 +2748,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
case Enumeration:
case Immutable:
case UuidGenerator:
case Webview:
break;
}

Expand Down Expand Up @@ -3666,6 +3677,18 @@ QString &QgsVectorLayer::dateFormat( int idx )
return mDateFormats[fieldName];
}

QSize &QgsVectorLayer::widgetSize( int idx )
{
const QgsFields &fields = pendingFields();

QString fieldName = fields[idx].name();

if ( !mWidgetSize.contains( fieldName ) )
mWidgetSize[fieldName] = QSize( 0, 0 );

return mWidgetSize[fieldName];
}

bool QgsVectorLayer::fieldEditable( int idx )
{
const QgsFields &fields = pendingFields();
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -176,6 +176,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
DialRange, /* dial range @added in 1.5 */
ValueRelation, /* value map from an table @added in 1.8 */
UuidGenerator, /* uuid generator - readonly and automatically intialized @added in 1.9 */
Photo, /* phote widget @added in 1.9 */
Webview, /* webview widget @added in 1.9 */
};

struct RangeData
Expand Down Expand Up @@ -759,6 +761,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
QString &dateFormat( int idx );

/**access widget size for photo and webview widget
* @note added in 1.9
*/
QSize &widgetSize( int idx );

/**is edit widget editable
* @note added in 1.9
**/
Expand Down Expand Up @@ -1066,6 +1073,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
QMap< QString, QPair<QString, QString> > mCheckedStates;
QMap< QString, ValueRelationData > mValueRelations;
QMap< QString, QString> mDateFormats;
QMap< QString, QSize> mWidgetSize;

/** Defines the default layout to use for the attribute editor (Drag and drop, UI File, Generated) */
EditorLayout mEditorLayout;
Expand Down

0 comments on commit b27b6a9

Please sign in to comment.