Skip to content

Commit

Permalink
[FEATURE] new edit type: date/time edit
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored and m-kuhn committed May 22, 2014
1 parent ea91b6f commit 431b065
Show file tree
Hide file tree
Showing 16 changed files with 805 additions and 571 deletions.
2 changes: 2 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -285,6 +285,7 @@
#include "qgswebviewwidgetfactory.h"
#include "qgscolorwidgetfactory.h"
#include "qgsrelationreferencefactory.h"
#include "qgsdatetimeeditfactory.h"

//
// Conditional Includes
Expand Down Expand Up @@ -682,6 +683,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
editorWidgetRegistry->registerWidget( "WebView", new QgsWebViewWidgetFactory( tr( "Web View" ) ) );
editorWidgetRegistry->registerWidget( "Color", new QgsColorWidgetFactory( tr( "Color" ) ) );
editorWidgetRegistry->registerWidget( "RelationReference", new QgsRelationReferenceFactory( context, tr( "Relation Reference" ) ) );
editorWidgetRegistry->registerWidget( "DateTime", new QgsDateTimeEditFactory( tr( "Date/Time" ) ) );

mInternalClipboard = new QgsClipboard; // create clipboard
connect( mInternalClipboard, SIGNAL( changed() ), this, SLOT( clipboardChanged() ) );
Expand Down
7 changes: 4 additions & 3 deletions src/core/qgslegacyhelpers.cpp
Expand Up @@ -102,8 +102,9 @@ const QString QgsLegacyHelpers::convertEditType( QgsVectorLayer::EditType editTy

case QgsVectorLayer::Calendar:
{
widgetType = "Calendar";
cfg.insert( "DateFormat", editTypeElement.attribute( "dateFormat" ) );
widgetType = "DateTime";
cfg.insert( "display_format", editTypeElement.attribute( "dateFormat" ) );
cfg.insert( "field_format", "yyyy-mm-dd" );
break;
}

Expand Down Expand Up @@ -278,7 +279,7 @@ QgsVectorLayer::EditType QgsLegacyHelpers::convertEditType( const QString& editT
return QgsVectorLayer::CheckBox;
}

if ( editType == "Calendar" )
if ( editType == "DateTime" )
{
return QgsVectorLayer::Calendar;
}
Expand Down
250 changes: 86 additions & 164 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1860,192 +1860,114 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
editTypeElement.setAttribute( "editable", mFieldEditables[field.name()] ? 1 : 0 );
editTypeElement.setAttribute( "labelontop", mLabelOnTop[field.name()] ? 1 : 0 );

#if 0
switch (( EditType ) it.value() )
{
case ValueMap:
if ( mValueMaps.contains( it.key() ) )
{
const QMap<QString, QVariant> &map = mValueMaps[ it.key()];

for ( QMap<QString, QVariant>::const_iterator vmit = map.begin(); vmit != map.end(); ++vmit )
{
QDomElement value = doc.createElement( "valuepair" );
value.setAttribute( "key", vmit.key() );
value.setAttribute( "value", vmit.value().toString() );
editTypeElement.appendChild( value );
}
}
break;

case EditRange:
case SliderRange:
case DialRange:
if ( mRanges.contains( it.key() ) )
{
editTypeElement.setAttribute( "min", mRanges[ it.key()].mMin.toString() );
editTypeElement.setAttribute( "max", mRanges[ it.key()].mMax.toString() );
editTypeElement.setAttribute( "step", mRanges[ it.key()].mStep.toString() );
}
break;

case CheckBox:
if ( mCheckedStates.contains( it.key() ) )
{
editTypeElement.setAttribute( "checked", mCheckedStates[ it.key()].first );
editTypeElement.setAttribute( "unchecked", mCheckedStates[ it.key()].second );
}
break;

case ValueRelation:
if ( mValueRelations.contains( it.key() ) )
{
const ValueRelationData &data = mValueRelations[ it.key()];
editTypeElement.setAttribute( "layer", data.mLayer );
editTypeElement.setAttribute( "key", data.mKey );
editTypeElement.setAttribute( "value", data.mValue );
editTypeElement.setAttribute( "allowNull", data.mAllowNull ? "true" : "false" );
editTypeElement.setAttribute( "orderByValue", data.mOrderByValue ? "true" : "false" );
editTypeElement.setAttribute( "allowMulti", data.mAllowMulti ? "true" : "false" );
if ( !data.mFilterExpression.isNull() )
editTypeElement.setAttribute( "filterExpression", data.mFilterExpression );
}
break;

case Calendar:
editTypeElement.setAttribute( "dateFormat", mDateFormats[ it.key()] );
break;

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

case LineEdit:
case UniqueValues:
case UniqueValuesEditable:
case Classification:
case FileName:
case Hidden:
case TextEdit:
case Enumeration:
case Immutable:
case UuidGenerator:
case Color:
case EditorWidgetV2: // Will get a signal and save there
break;
}
editTypesElement.appendChild( editTypeElement );
}
#endif

editTypesElement.appendChild( editTypeElement );
}

node.appendChild( editTypesElement );
node.appendChild( editTypesElement );

QDomElement efField = doc.createElement( "editform" );
QDomText efText = doc.createTextNode( QgsProject::instance()->writePath( mEditForm ) );
efField.appendChild( efText );
node.appendChild( efField );
QDomElement efField = doc.createElement( "editform" );
QDomText efText = doc.createTextNode( QgsProject::instance()->writePath( mEditForm ) );
efField.appendChild( efText );
node.appendChild( efField );

QDomElement efiField = doc.createElement( "editforminit" );
QDomText efiText = doc.createTextNode( mEditFormInit );
efiField.appendChild( efiText );
node.appendChild( efiField );
QDomElement efiField = doc.createElement( "editforminit" );
QDomText efiText = doc.createTextNode( mEditFormInit );
efiField.appendChild( efiText );
node.appendChild( efiField );

QDomElement fFSuppElem = doc.createElement( "featformsuppress" );
QDomText fFSuppText = doc.createTextNode( QString::number( featureFormSuppress() ) );
fFSuppElem.appendChild( fFSuppText );
node.appendChild( fFSuppElem );
QDomElement fFSuppElem = doc.createElement( "featformsuppress" );
QDomText fFSuppText = doc.createTextNode( QString::number( featureFormSuppress() ) );
fFSuppElem.appendChild( fFSuppText );
node.appendChild( fFSuppElem );

QDomElement afField = doc.createElement( "annotationform" );
QDomText afText = doc.createTextNode( QgsProject::instance()->writePath( mAnnotationForm ) );
afField.appendChild( afText );
node.appendChild( afField );
QDomElement afField = doc.createElement( "annotationform" );
QDomText afText = doc.createTextNode( QgsProject::instance()->writePath( mAnnotationForm ) );
afField.appendChild( afText );
node.appendChild( afField );

// tab display
QDomElement editorLayoutElem = doc.createElement( "editorlayout" );
switch ( mEditorLayout )
{
case UiFileLayout:
editorLayoutElem.appendChild( doc.createTextNode( "uifilelayout" ) );
break;
// tab display
QDomElement editorLayoutElem = doc.createElement( "editorlayout" );
switch ( mEditorLayout )
{
case UiFileLayout:
editorLayoutElem.appendChild( doc.createTextNode( "uifilelayout" ) );
break;

case TabLayout:
editorLayoutElem.appendChild( doc.createTextNode( "tablayout" ) );
break;
case TabLayout:
editorLayoutElem.appendChild( doc.createTextNode( "tablayout" ) );
break;

case GeneratedLayout:
default:
editorLayoutElem.appendChild( doc.createTextNode( "generatedlayout" ) );
break;
}
case GeneratedLayout:
default:
editorLayoutElem.appendChild( doc.createTextNode( "generatedlayout" ) );
break;
}

node.appendChild( editorLayoutElem );
node.appendChild( editorLayoutElem );

//attribute aliases
if ( mAttributeAliasMap.size() > 0 )
{
QDomElement aliasElem = doc.createElement( "aliases" );
QMap<QString, QString>::const_iterator a_it = mAttributeAliasMap.constBegin();
for ( ; a_it != mAttributeAliasMap.constEnd(); ++a_it )
//attribute aliases
if ( mAttributeAliasMap.size() > 0 )
{
int idx = fieldNameIndex( a_it.key() );
if ( idx < 0 )
continue;
QDomElement aliasElem = doc.createElement( "aliases" );
QMap<QString, QString>::const_iterator a_it = mAttributeAliasMap.constBegin();
for ( ; a_it != mAttributeAliasMap.constEnd(); ++a_it )
{
int idx = fieldNameIndex( a_it.key() );
if ( idx < 0 )
continue;

QDomElement aliasEntryElem = doc.createElement( "alias" );
aliasEntryElem.setAttribute( "field", a_it.key() );
aliasEntryElem.setAttribute( "index", idx );
aliasEntryElem.setAttribute( "name", a_it.value() );
aliasElem.appendChild( aliasEntryElem );
QDomElement aliasEntryElem = doc.createElement( "alias" );
aliasEntryElem.setAttribute( "field", a_it.key() );
aliasEntryElem.setAttribute( "index", idx );
aliasEntryElem.setAttribute( "name", a_it.value() );
aliasElem.appendChild( aliasEntryElem );
}
node.appendChild( aliasElem );
}
node.appendChild( aliasElem );
}

//exclude attributes WMS
QDomElement excludeWMSElem = doc.createElement( "excludeAttributesWMS" );
QSet<QString>::const_iterator attWMSIt = mExcludeAttributesWMS.constBegin();
for ( ; attWMSIt != mExcludeAttributesWMS.constEnd(); ++attWMSIt )
{
QDomElement attrElem = doc.createElement( "attribute" );
QDomText attrText = doc.createTextNode( *attWMSIt );
attrElem.appendChild( attrText );
excludeWMSElem.appendChild( attrElem );
}
node.appendChild( excludeWMSElem );

//exclude attributes WFS
QDomElement excludeWFSElem = doc.createElement( "excludeAttributesWFS" );
QSet<QString>::const_iterator attWFSIt = mExcludeAttributesWFS.constBegin();
for ( ; attWFSIt != mExcludeAttributesWFS.constEnd(); ++attWFSIt )
{
QDomElement attrElem = doc.createElement( "attribute" );
QDomText attrText = doc.createTextNode( *attWFSIt );
attrElem.appendChild( attrText );
excludeWFSElem.appendChild( attrElem );
}
node.appendChild( excludeWFSElem );

// tabs and groups of edit form
if ( mAttributeEditorElements.size() > 0 )
{
QDomElement tabsElem = doc.createElement( "attributeEditorForm" );
//exclude attributes WMS
QDomElement excludeWMSElem = doc.createElement( "excludeAttributesWMS" );
QSet<QString>::const_iterator attWMSIt = mExcludeAttributesWMS.constBegin();
for ( ; attWMSIt != mExcludeAttributesWMS.constEnd(); ++attWMSIt )
{
QDomElement attrElem = doc.createElement( "attribute" );
QDomText attrText = doc.createTextNode( *attWMSIt );
attrElem.appendChild( attrText );
excludeWMSElem.appendChild( attrElem );
}
node.appendChild( excludeWMSElem );

for ( QList< QgsAttributeEditorElement* >::const_iterator it = mAttributeEditorElements.begin(); it != mAttributeEditorElements.end(); ++it )
//exclude attributes WFS
QDomElement excludeWFSElem = doc.createElement( "excludeAttributesWFS" );
QSet<QString>::const_iterator attWFSIt = mExcludeAttributesWFS.constBegin();
for ( ; attWFSIt != mExcludeAttributesWFS.constEnd(); ++attWFSIt )
{
QDomElement attributeEditorWidgetElem = ( *it )->toDomElement( doc );
tabsElem.appendChild( attributeEditorWidgetElem );
QDomElement attrElem = doc.createElement( "attribute" );
QDomText attrText = doc.createTextNode( *attWFSIt );
attrElem.appendChild( attrText );
excludeWFSElem.appendChild( attrElem );
}
node.appendChild( excludeWFSElem );

node.appendChild( tabsElem );
}
// tabs and groups of edit form
if ( mAttributeEditorElements.size() > 0 )
{
QDomElement tabsElem = doc.createElement( "attributeEditorForm" );

// add attribute actions
mActions->writeXML( node, doc );
for ( QList< QgsAttributeEditorElement* >::const_iterator it = mAttributeEditorElements.begin(); it != mAttributeEditorElements.end(); ++it )
{
QDomElement attributeEditorWidgetElem = ( *it )->toDomElement( doc );
tabsElem.appendChild( attributeEditorWidgetElem );
}

return true;
node.appendChild( tabsElem );
}

// add attribute actions
mActions->writeXML( node, doc );

return true;
}

bool QgsVectorLayer::readSld( const QDomNode& node, QString& errorMessage )
Expand Down
16 changes: 8 additions & 8 deletions src/gui/CMakeLists.txt
Expand Up @@ -56,16 +56,16 @@ editorwidgets/core/qgseditorwidgetregistry.cpp
editorwidgets/core/qgseditorwidgetwrapper.cpp
editorwidgets/core/qgswidgetwrapper.cpp

editorwidgets/qgscalendarconfigdlg.cpp
editorwidgets/qgscalendarwidget.cpp
editorwidgets/qgscalendarwidgetfactory.cpp
editorwidgets/qgscheckboxconfigdlg.cpp
editorwidgets/qgscheckboxwidget.cpp
editorwidgets/qgscheckboxwidgetfactory.cpp
editorwidgets/qgsclassificationwidget.cpp
editorwidgets/qgsclassificationwidgetwrapperfactory.cpp
editorwidgets/qgscolorwidget.cpp
editorwidgets/qgscolorwidgetfactory.cpp
editorwidgets/qgsdatetimeeditfactory.cpp
editorwidgets/qgsdatetimeeditconfig.cpp
editorwidgets/qgsdatetimeeditwrapper.cpp
editorwidgets/qgsdummyconfigdlg.cpp
editorwidgets/qgsenumerationwidget.cpp
editorwidgets/qgsenumerationwidgetfactory.cpp
Expand Down Expand Up @@ -270,12 +270,12 @@ editorwidgets/core/qgseditorconfigwidget.h
editorwidgets/core/qgseditorwidgetregistry.h
editorwidgets/core/qgseditorwidgetwrapper.h
editorwidgets/core/qgswidgetwrapper.h
editorwidgets/qgscalendarconfigdlg.h
editorwidgets/qgscalendarwidget.h
editorwidgets/qgscheckboxconfigdlg.h
editorwidgets/qgscheckboxwidget.h
editorwidgets/qgsclassificationwidget.h
editorwidgets/qgscolorwidget.h
editorwidgets/qgsdatetimeeditconfig.h
editorwidgets/qgsdatetimeeditwrapper.h
editorwidgets/qgsdummyconfigdlg.h
editorwidgets/qgsenumerationwidget.h
editorwidgets/qgsfilenamewidget.h
Expand Down Expand Up @@ -482,16 +482,16 @@ editorwidgets/core/qgseditorwidgetregistry.h
editorwidgets/core/qgseditorwidgetwrapper.h
editorwidgets/core/qgswidgetwrapper.h

editorwidgets/qgscalendarconfigdlg.h
editorwidgets/qgscalendarwidget.h
editorwidgets/qgscalendarwidgetfactory.h
editorwidgets/qgscheckboxconfigdlg.h
editorwidgets/qgscheckboxwidget.h
editorwidgets/qgscheckboxwidgetfactory.h
editorwidgets/qgsclassificationwidget.h
editorwidgets/qgsclassificationwidgetwrapperfactory.h
editorwidgets/qgscolorwidget.h
editorwidgets/qgscolorwidgetfactory.h
editorwidgets/qgsdatetimeeditfactory.h
editorwidgets/qgsdatetimeeditconfig.h
editorwidgets/qgsdatetimeeditwrapper.h
editorwidgets/qgsdummyconfigdlg.h
editorwidgets/qgsenumerationwidget.h
editorwidgets/qgsenumerationwidgetfactory.h
Expand Down

0 comments on commit 431b065

Please sign in to comment.