Skip to content

Commit 431b065

Browse files
3nidsm-kuhn
authored andcommitted
[FEATURE] new edit type: date/time edit
1 parent ea91b6f commit 431b065

16 files changed

+805
-571
lines changed

src/app/qgisapp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@
285285
#include "qgswebviewwidgetfactory.h"
286286
#include "qgscolorwidgetfactory.h"
287287
#include "qgsrelationreferencefactory.h"
288+
#include "qgsdatetimeeditfactory.h"
288289

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

686688
mInternalClipboard = new QgsClipboard; // create clipboard
687689
connect( mInternalClipboard, SIGNAL( changed() ), this, SLOT( clipboardChanged() ) );

src/core/qgslegacyhelpers.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ const QString QgsLegacyHelpers::convertEditType( QgsVectorLayer::EditType editTy
102102

103103
case QgsVectorLayer::Calendar:
104104
{
105-
widgetType = "Calendar";
106-
cfg.insert( "DateFormat", editTypeElement.attribute( "dateFormat" ) );
105+
widgetType = "DateTime";
106+
cfg.insert( "display_format", editTypeElement.attribute( "dateFormat" ) );
107+
cfg.insert( "field_format", "yyyy-mm-dd" );
107108
break;
108109
}
109110

@@ -278,7 +279,7 @@ QgsVectorLayer::EditType QgsLegacyHelpers::convertEditType( const QString& editT
278279
return QgsVectorLayer::CheckBox;
279280
}
280281

281-
if ( editType == "Calendar" )
282+
if ( editType == "DateTime" )
282283
{
283284
return QgsVectorLayer::Calendar;
284285
}

src/core/qgsvectorlayer.cpp

Lines changed: 86 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,192 +1860,114 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
18601860
editTypeElement.setAttribute( "editable", mFieldEditables[field.name()] ? 1 : 0 );
18611861
editTypeElement.setAttribute( "labelontop", mLabelOnTop[field.name()] ? 1 : 0 );
18621862

1863-
#if 0
1864-
switch (( EditType ) it.value() )
1865-
{
1866-
case ValueMap:
1867-
if ( mValueMaps.contains( it.key() ) )
1868-
{
1869-
const QMap<QString, QVariant> &map = mValueMaps[ it.key()];
1870-
1871-
for ( QMap<QString, QVariant>::const_iterator vmit = map.begin(); vmit != map.end(); ++vmit )
1872-
{
1873-
QDomElement value = doc.createElement( "valuepair" );
1874-
value.setAttribute( "key", vmit.key() );
1875-
value.setAttribute( "value", vmit.value().toString() );
1876-
editTypeElement.appendChild( value );
1877-
}
1878-
}
1879-
break;
1880-
1881-
case EditRange:
1882-
case SliderRange:
1883-
case DialRange:
1884-
if ( mRanges.contains( it.key() ) )
1885-
{
1886-
editTypeElement.setAttribute( "min", mRanges[ it.key()].mMin.toString() );
1887-
editTypeElement.setAttribute( "max", mRanges[ it.key()].mMax.toString() );
1888-
editTypeElement.setAttribute( "step", mRanges[ it.key()].mStep.toString() );
1889-
}
1890-
break;
1891-
1892-
case CheckBox:
1893-
if ( mCheckedStates.contains( it.key() ) )
1894-
{
1895-
editTypeElement.setAttribute( "checked", mCheckedStates[ it.key()].first );
1896-
editTypeElement.setAttribute( "unchecked", mCheckedStates[ it.key()].second );
1897-
}
1898-
break;
1899-
1900-
case ValueRelation:
1901-
if ( mValueRelations.contains( it.key() ) )
1902-
{
1903-
const ValueRelationData &data = mValueRelations[ it.key()];
1904-
editTypeElement.setAttribute( "layer", data.mLayer );
1905-
editTypeElement.setAttribute( "key", data.mKey );
1906-
editTypeElement.setAttribute( "value", data.mValue );
1907-
editTypeElement.setAttribute( "allowNull", data.mAllowNull ? "true" : "false" );
1908-
editTypeElement.setAttribute( "orderByValue", data.mOrderByValue ? "true" : "false" );
1909-
editTypeElement.setAttribute( "allowMulti", data.mAllowMulti ? "true" : "false" );
1910-
if ( !data.mFilterExpression.isNull() )
1911-
editTypeElement.setAttribute( "filterExpression", data.mFilterExpression );
1912-
}
1913-
break;
1914-
1915-
case Calendar:
1916-
editTypeElement.setAttribute( "dateFormat", mDateFormats[ it.key()] );
1917-
break;
1918-
1919-
case Photo:
1920-
case WebView:
1921-
editTypeElement.setAttribute( "widgetWidth", mWidgetSize[ it.key()].width() );
1922-
editTypeElement.setAttribute( "widgetHeight", mWidgetSize[ it.key()].height() );
1923-
break;
19241863

1925-
case LineEdit:
1926-
case UniqueValues:
1927-
case UniqueValuesEditable:
1928-
case Classification:
1929-
case FileName:
1930-
case Hidden:
1931-
case TextEdit:
1932-
case Enumeration:
1933-
case Immutable:
1934-
case UuidGenerator:
1935-
case Color:
1936-
case EditorWidgetV2: // Will get a signal and save there
1937-
break;
1938-
}
1864+
editTypesElement.appendChild( editTypeElement );
19391865
}
1940-
#endif
1941-
1942-
editTypesElement.appendChild( editTypeElement );
1943-
}
19441866

1945-
node.appendChild( editTypesElement );
1867+
node.appendChild( editTypesElement );
19461868

1947-
QDomElement efField = doc.createElement( "editform" );
1948-
QDomText efText = doc.createTextNode( QgsProject::instance()->writePath( mEditForm ) );
1949-
efField.appendChild( efText );
1950-
node.appendChild( efField );
1869+
QDomElement efField = doc.createElement( "editform" );
1870+
QDomText efText = doc.createTextNode( QgsProject::instance()->writePath( mEditForm ) );
1871+
efField.appendChild( efText );
1872+
node.appendChild( efField );
19511873

1952-
QDomElement efiField = doc.createElement( "editforminit" );
1953-
QDomText efiText = doc.createTextNode( mEditFormInit );
1954-
efiField.appendChild( efiText );
1955-
node.appendChild( efiField );
1874+
QDomElement efiField = doc.createElement( "editforminit" );
1875+
QDomText efiText = doc.createTextNode( mEditFormInit );
1876+
efiField.appendChild( efiText );
1877+
node.appendChild( efiField );
19561878

1957-
QDomElement fFSuppElem = doc.createElement( "featformsuppress" );
1958-
QDomText fFSuppText = doc.createTextNode( QString::number( featureFormSuppress() ) );
1959-
fFSuppElem.appendChild( fFSuppText );
1960-
node.appendChild( fFSuppElem );
1879+
QDomElement fFSuppElem = doc.createElement( "featformsuppress" );
1880+
QDomText fFSuppText = doc.createTextNode( QString::number( featureFormSuppress() ) );
1881+
fFSuppElem.appendChild( fFSuppText );
1882+
node.appendChild( fFSuppElem );
19611883

1962-
QDomElement afField = doc.createElement( "annotationform" );
1963-
QDomText afText = doc.createTextNode( QgsProject::instance()->writePath( mAnnotationForm ) );
1964-
afField.appendChild( afText );
1965-
node.appendChild( afField );
1884+
QDomElement afField = doc.createElement( "annotationform" );
1885+
QDomText afText = doc.createTextNode( QgsProject::instance()->writePath( mAnnotationForm ) );
1886+
afField.appendChild( afText );
1887+
node.appendChild( afField );
19661888

1967-
// tab display
1968-
QDomElement editorLayoutElem = doc.createElement( "editorlayout" );
1969-
switch ( mEditorLayout )
1970-
{
1971-
case UiFileLayout:
1972-
editorLayoutElem.appendChild( doc.createTextNode( "uifilelayout" ) );
1973-
break;
1889+
// tab display
1890+
QDomElement editorLayoutElem = doc.createElement( "editorlayout" );
1891+
switch ( mEditorLayout )
1892+
{
1893+
case UiFileLayout:
1894+
editorLayoutElem.appendChild( doc.createTextNode( "uifilelayout" ) );
1895+
break;
19741896

1975-
case TabLayout:
1976-
editorLayoutElem.appendChild( doc.createTextNode( "tablayout" ) );
1977-
break;
1897+
case TabLayout:
1898+
editorLayoutElem.appendChild( doc.createTextNode( "tablayout" ) );
1899+
break;
19781900

1979-
case GeneratedLayout:
1980-
default:
1981-
editorLayoutElem.appendChild( doc.createTextNode( "generatedlayout" ) );
1982-
break;
1983-
}
1901+
case GeneratedLayout:
1902+
default:
1903+
editorLayoutElem.appendChild( doc.createTextNode( "generatedlayout" ) );
1904+
break;
1905+
}
19841906

1985-
node.appendChild( editorLayoutElem );
1907+
node.appendChild( editorLayoutElem );
19861908

1987-
//attribute aliases
1988-
if ( mAttributeAliasMap.size() > 0 )
1989-
{
1990-
QDomElement aliasElem = doc.createElement( "aliases" );
1991-
QMap<QString, QString>::const_iterator a_it = mAttributeAliasMap.constBegin();
1992-
for ( ; a_it != mAttributeAliasMap.constEnd(); ++a_it )
1909+
//attribute aliases
1910+
if ( mAttributeAliasMap.size() > 0 )
19931911
{
1994-
int idx = fieldNameIndex( a_it.key() );
1995-
if ( idx < 0 )
1996-
continue;
1912+
QDomElement aliasElem = doc.createElement( "aliases" );
1913+
QMap<QString, QString>::const_iterator a_it = mAttributeAliasMap.constBegin();
1914+
for ( ; a_it != mAttributeAliasMap.constEnd(); ++a_it )
1915+
{
1916+
int idx = fieldNameIndex( a_it.key() );
1917+
if ( idx < 0 )
1918+
continue;
19971919

1998-
QDomElement aliasEntryElem = doc.createElement( "alias" );
1999-
aliasEntryElem.setAttribute( "field", a_it.key() );
2000-
aliasEntryElem.setAttribute( "index", idx );
2001-
aliasEntryElem.setAttribute( "name", a_it.value() );
2002-
aliasElem.appendChild( aliasEntryElem );
1920+
QDomElement aliasEntryElem = doc.createElement( "alias" );
1921+
aliasEntryElem.setAttribute( "field", a_it.key() );
1922+
aliasEntryElem.setAttribute( "index", idx );
1923+
aliasEntryElem.setAttribute( "name", a_it.value() );
1924+
aliasElem.appendChild( aliasEntryElem );
1925+
}
1926+
node.appendChild( aliasElem );
20031927
}
2004-
node.appendChild( aliasElem );
2005-
}
2006-
2007-
//exclude attributes WMS
2008-
QDomElement excludeWMSElem = doc.createElement( "excludeAttributesWMS" );
2009-
QSet<QString>::const_iterator attWMSIt = mExcludeAttributesWMS.constBegin();
2010-
for ( ; attWMSIt != mExcludeAttributesWMS.constEnd(); ++attWMSIt )
2011-
{
2012-
QDomElement attrElem = doc.createElement( "attribute" );
2013-
QDomText attrText = doc.createTextNode( *attWMSIt );
2014-
attrElem.appendChild( attrText );
2015-
excludeWMSElem.appendChild( attrElem );
2016-
}
2017-
node.appendChild( excludeWMSElem );
20181928

2019-
//exclude attributes WFS
2020-
QDomElement excludeWFSElem = doc.createElement( "excludeAttributesWFS" );
2021-
QSet<QString>::const_iterator attWFSIt = mExcludeAttributesWFS.constBegin();
2022-
for ( ; attWFSIt != mExcludeAttributesWFS.constEnd(); ++attWFSIt )
2023-
{
2024-
QDomElement attrElem = doc.createElement( "attribute" );
2025-
QDomText attrText = doc.createTextNode( *attWFSIt );
2026-
attrElem.appendChild( attrText );
2027-
excludeWFSElem.appendChild( attrElem );
2028-
}
2029-
node.appendChild( excludeWFSElem );
2030-
2031-
// tabs and groups of edit form
2032-
if ( mAttributeEditorElements.size() > 0 )
2033-
{
2034-
QDomElement tabsElem = doc.createElement( "attributeEditorForm" );
1929+
//exclude attributes WMS
1930+
QDomElement excludeWMSElem = doc.createElement( "excludeAttributesWMS" );
1931+
QSet<QString>::const_iterator attWMSIt = mExcludeAttributesWMS.constBegin();
1932+
for ( ; attWMSIt != mExcludeAttributesWMS.constEnd(); ++attWMSIt )
1933+
{
1934+
QDomElement attrElem = doc.createElement( "attribute" );
1935+
QDomText attrText = doc.createTextNode( *attWMSIt );
1936+
attrElem.appendChild( attrText );
1937+
excludeWMSElem.appendChild( attrElem );
1938+
}
1939+
node.appendChild( excludeWMSElem );
20351940

2036-
for ( QList< QgsAttributeEditorElement* >::const_iterator it = mAttributeEditorElements.begin(); it != mAttributeEditorElements.end(); ++it )
1941+
//exclude attributes WFS
1942+
QDomElement excludeWFSElem = doc.createElement( "excludeAttributesWFS" );
1943+
QSet<QString>::const_iterator attWFSIt = mExcludeAttributesWFS.constBegin();
1944+
for ( ; attWFSIt != mExcludeAttributesWFS.constEnd(); ++attWFSIt )
20371945
{
2038-
QDomElement attributeEditorWidgetElem = ( *it )->toDomElement( doc );
2039-
tabsElem.appendChild( attributeEditorWidgetElem );
1946+
QDomElement attrElem = doc.createElement( "attribute" );
1947+
QDomText attrText = doc.createTextNode( *attWFSIt );
1948+
attrElem.appendChild( attrText );
1949+
excludeWFSElem.appendChild( attrElem );
20401950
}
1951+
node.appendChild( excludeWFSElem );
20411952

2042-
node.appendChild( tabsElem );
2043-
}
1953+
// tabs and groups of edit form
1954+
if ( mAttributeEditorElements.size() > 0 )
1955+
{
1956+
QDomElement tabsElem = doc.createElement( "attributeEditorForm" );
20441957

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

2048-
return true;
1964+
node.appendChild( tabsElem );
1965+
}
1966+
1967+
// add attribute actions
1968+
mActions->writeXML( node, doc );
1969+
1970+
return true;
20491971
}
20501972

20511973
bool QgsVectorLayer::readSld( const QDomNode& node, QString& errorMessage )

src/gui/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ editorwidgets/core/qgseditorwidgetregistry.cpp
5656
editorwidgets/core/qgseditorwidgetwrapper.cpp
5757
editorwidgets/core/qgswidgetwrapper.cpp
5858

59-
editorwidgets/qgscalendarconfigdlg.cpp
60-
editorwidgets/qgscalendarwidget.cpp
61-
editorwidgets/qgscalendarwidgetfactory.cpp
6259
editorwidgets/qgscheckboxconfigdlg.cpp
6360
editorwidgets/qgscheckboxwidget.cpp
6461
editorwidgets/qgscheckboxwidgetfactory.cpp
6562
editorwidgets/qgsclassificationwidget.cpp
6663
editorwidgets/qgsclassificationwidgetwrapperfactory.cpp
6764
editorwidgets/qgscolorwidget.cpp
6865
editorwidgets/qgscolorwidgetfactory.cpp
66+
editorwidgets/qgsdatetimeeditfactory.cpp
67+
editorwidgets/qgsdatetimeeditconfig.cpp
68+
editorwidgets/qgsdatetimeeditwrapper.cpp
6969
editorwidgets/qgsdummyconfigdlg.cpp
7070
editorwidgets/qgsenumerationwidget.cpp
7171
editorwidgets/qgsenumerationwidgetfactory.cpp
@@ -270,12 +270,12 @@ editorwidgets/core/qgseditorconfigwidget.h
270270
editorwidgets/core/qgseditorwidgetregistry.h
271271
editorwidgets/core/qgseditorwidgetwrapper.h
272272
editorwidgets/core/qgswidgetwrapper.h
273-
editorwidgets/qgscalendarconfigdlg.h
274-
editorwidgets/qgscalendarwidget.h
275273
editorwidgets/qgscheckboxconfigdlg.h
276274
editorwidgets/qgscheckboxwidget.h
277275
editorwidgets/qgsclassificationwidget.h
278276
editorwidgets/qgscolorwidget.h
277+
editorwidgets/qgsdatetimeeditconfig.h
278+
editorwidgets/qgsdatetimeeditwrapper.h
279279
editorwidgets/qgsdummyconfigdlg.h
280280
editorwidgets/qgsenumerationwidget.h
281281
editorwidgets/qgsfilenamewidget.h
@@ -482,16 +482,16 @@ editorwidgets/core/qgseditorwidgetregistry.h
482482
editorwidgets/core/qgseditorwidgetwrapper.h
483483
editorwidgets/core/qgswidgetwrapper.h
484484

485-
editorwidgets/qgscalendarconfigdlg.h
486-
editorwidgets/qgscalendarwidget.h
487-
editorwidgets/qgscalendarwidgetfactory.h
488485
editorwidgets/qgscheckboxconfigdlg.h
489486
editorwidgets/qgscheckboxwidget.h
490487
editorwidgets/qgscheckboxwidgetfactory.h
491488
editorwidgets/qgsclassificationwidget.h
492489
editorwidgets/qgsclassificationwidgetwrapperfactory.h
493490
editorwidgets/qgscolorwidget.h
494491
editorwidgets/qgscolorwidgetfactory.h
492+
editorwidgets/qgsdatetimeeditfactory.h
493+
editorwidgets/qgsdatetimeeditconfig.h
494+
editorwidgets/qgsdatetimeeditwrapper.h
495495
editorwidgets/qgsdummyconfigdlg.h
496496
editorwidgets/qgsenumerationwidget.h
497497
editorwidgets/qgsenumerationwidgetfactory.h

0 commit comments

Comments
 (0)