mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
[FEATURE] add uuid generator widget
This commit is contained in:
parent
d7b14999a0
commit
100d702bd0
@ -68,6 +68,7 @@ public:
|
|||||||
Calendar, /* calendar widget @added in 1.5 */
|
Calendar, /* calendar widget @added in 1.5 */
|
||||||
DialRange, /* dial range @added in 1.5 */
|
DialRange, /* dial range @added in 1.5 */
|
||||||
ValueRelation, /* value map from an table @added in 1.8 */
|
ValueRelation, /* value map from an table @added in 1.8 */
|
||||||
|
UuidGenerator, /* uuid generator - readonly and automatically intialized @added in 1.9 */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RangeData {
|
struct RangeData {
|
||||||
|
@ -279,6 +279,10 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy
|
|||||||
case QgsVectorLayer::ValueRelation:
|
case QgsVectorLayer::ValueRelation:
|
||||||
setPage( 12 );
|
setPage( 12 );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case QgsVectorLayer::UuidGenerator:
|
||||||
|
setPage( 13 );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,7 +423,7 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case QgsVectorLayer::UniqueValuesEditable:
|
case QgsVectorLayer::UniqueValuesEditable:
|
||||||
editableUniqueValues->setChecked( editType == QgsVectorLayer::UniqueValuesEditable );
|
editableUniqueValues->setChecked( true );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QgsVectorLayer::ValueRelation:
|
case QgsVectorLayer::ValueRelation:
|
||||||
@ -440,6 +444,7 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT
|
|||||||
case QgsVectorLayer::Hidden:
|
case QgsVectorLayer::Hidden:
|
||||||
case QgsVectorLayer::TextEdit:
|
case QgsVectorLayer::TextEdit:
|
||||||
case QgsVectorLayer::Calendar:
|
case QgsVectorLayer::Calendar:
|
||||||
|
case QgsVectorLayer::UuidGenerator:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -600,6 +605,9 @@ void QgsAttributeTypeDialog::accept()
|
|||||||
mValueRelationData.mAllowNull = valueRelationAllowNull->isChecked();
|
mValueRelationData.mAllowNull = valueRelationAllowNull->isChecked();
|
||||||
mValueRelationData.mOrderByValue = valueRelationOrderByValue->isChecked();
|
mValueRelationData.mOrderByValue = valueRelationOrderByValue->isChecked();
|
||||||
break;
|
break;
|
||||||
|
case 13:
|
||||||
|
mEditType = QgsVectorLayer::UuidGenerator;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
|
@ -310,6 +310,7 @@ void QgsVectorLayerProperties::attributeTypeDialog( )
|
|||||||
case QgsVectorLayer::Immutable:
|
case QgsVectorLayer::Immutable:
|
||||||
case QgsVectorLayer::Hidden:
|
case QgsVectorLayer::Hidden:
|
||||||
case QgsVectorLayer::Calendar:
|
case QgsVectorLayer::Calendar:
|
||||||
|
case QgsVectorLayer::UuidGenerator:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,6 +584,7 @@ void QgsVectorLayerProperties::setupEditTypes()
|
|||||||
editTypeMap.insert( QgsVectorLayer::TextEdit, tr( "Text edit" ) );
|
editTypeMap.insert( QgsVectorLayer::TextEdit, tr( "Text edit" ) );
|
||||||
editTypeMap.insert( QgsVectorLayer::Calendar, tr( "Calendar" ) );
|
editTypeMap.insert( QgsVectorLayer::Calendar, tr( "Calendar" ) );
|
||||||
editTypeMap.insert( QgsVectorLayer::ValueRelation, tr( "Value relation" ) );
|
editTypeMap.insert( QgsVectorLayer::ValueRelation, tr( "Value relation" ) );
|
||||||
|
editTypeMap.insert( QgsVectorLayer::UuidGenerator, tr( "UUID generator" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsVectorLayerProperties::editTypeButtonText( QgsVectorLayer::EditType type )
|
QString QgsVectorLayerProperties::editTypeButtonText( QgsVectorLayer::EditType type )
|
||||||
@ -690,6 +692,7 @@ void QgsVectorLayerProperties::apply()
|
|||||||
case QgsVectorLayer::Hidden:
|
case QgsVectorLayer::Hidden:
|
||||||
case QgsVectorLayer::TextEdit:
|
case QgsVectorLayer::TextEdit:
|
||||||
case QgsVectorLayer::Calendar:
|
case QgsVectorLayer::Calendar:
|
||||||
|
case QgsVectorLayer::UuidGenerator:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3048,37 +3048,61 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
|
|||||||
EditType editType = ( EditType ) editTypeElement.attribute( "type" ).toInt();
|
EditType editType = ( EditType ) editTypeElement.attribute( "type" ).toInt();
|
||||||
mEditTypes.insert( name, editType );
|
mEditTypes.insert( name, editType );
|
||||||
|
|
||||||
if ( editType == ValueMap && editTypeNode.hasChildNodes() )
|
switch ( editType )
|
||||||
{
|
{
|
||||||
mValueMaps.insert( name, QMap<QString, QVariant>() );
|
case ValueMap:
|
||||||
|
if ( editTypeNode.hasChildNodes() )
|
||||||
|
{
|
||||||
|
mValueMaps.insert( name, QMap<QString, QVariant>() );
|
||||||
|
|
||||||
QDomNodeList valueMapNodes = editTypeNode.childNodes();
|
QDomNodeList valueMapNodes = editTypeNode.childNodes();
|
||||||
for ( int j = 0; j < valueMapNodes.size(); j++ )
|
for ( int j = 0; j < valueMapNodes.size(); j++ )
|
||||||
|
{
|
||||||
|
QDomElement value = valueMapNodes.at( j ).toElement();
|
||||||
|
mValueMaps[ name ].insert( value.attribute( "key" ), value.attribute( "value" ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EditRange:
|
||||||
|
case SliderRange:
|
||||||
|
case DialRange:
|
||||||
{
|
{
|
||||||
QDomElement value = valueMapNodes.at( j ).toElement();
|
QVariant min = editTypeElement.attribute( "min" );
|
||||||
mValueMaps[ name ].insert( value.attribute( "key" ), value.attribute( "value" ) );
|
QVariant max = editTypeElement.attribute( "max" );
|
||||||
}
|
QVariant step = editTypeElement.attribute( "step" );
|
||||||
}
|
|
||||||
else if ( editType == EditRange || editType == SliderRange )
|
|
||||||
{
|
|
||||||
QVariant min = editTypeElement.attribute( "min" );
|
|
||||||
QVariant max = editTypeElement.attribute( "max" );
|
|
||||||
QVariant step = editTypeElement.attribute( "step" );
|
|
||||||
|
|
||||||
mRanges[ name ] = RangeData( min, max, step );
|
mRanges[ name ] = RangeData( min, max, step );
|
||||||
}
|
}
|
||||||
else if ( editType == CheckBox )
|
break;
|
||||||
{
|
|
||||||
mCheckedStates[ name ] = QPair<QString, QString>( editTypeElement.attribute( "checked" ), editTypeElement.attribute( "unchecked" ) );
|
case CheckBox:
|
||||||
}
|
mCheckedStates[ name ] = QPair<QString, QString>( editTypeElement.attribute( "checked" ), editTypeElement.attribute( "unchecked" ) );
|
||||||
else if ( editType == ValueRelation )
|
break;
|
||||||
{
|
|
||||||
QString id = editTypeElement.attribute( "layer" );
|
case ValueRelation:
|
||||||
QString key = editTypeElement.attribute( "key" );
|
{
|
||||||
QString value = editTypeElement.attribute( "value" );
|
QString id = editTypeElement.attribute( "layer" );
|
||||||
bool allowNull = editTypeElement.attribute( "allowNull" ) == "true";
|
QString key = editTypeElement.attribute( "key" );
|
||||||
bool orderByValue = editTypeElement.attribute( "orderByValue" ) == "true";
|
QString value = editTypeElement.attribute( "value" );
|
||||||
mValueRelations[ name ] = ValueRelationData( id, key, value, allowNull, orderByValue );
|
bool allowNull = editTypeElement.attribute( "allowNull" ) == "true";
|
||||||
|
bool orderByValue = editTypeElement.attribute( "orderByValue" ) == "true";
|
||||||
|
mValueRelations[ name ] = ValueRelationData( id, key, value, allowNull, orderByValue );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Classification:
|
||||||
|
case FileName:
|
||||||
|
case Immutable:
|
||||||
|
case Hidden:
|
||||||
|
case LineEdit:
|
||||||
|
case TextEdit:
|
||||||
|
case Calendar:
|
||||||
|
case Enumeration:
|
||||||
|
case UniqueValues:
|
||||||
|
case UniqueValuesEditable:
|
||||||
|
case UuidGenerator:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3297,6 +3321,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
|
|||||||
case Calendar:
|
case Calendar:
|
||||||
case Enumeration:
|
case Enumeration:
|
||||||
case Immutable:
|
case Immutable:
|
||||||
|
case UuidGenerator:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +105,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
|
|||||||
Calendar, /* calendar widget @added in 1.5 */
|
Calendar, /* calendar widget @added in 1.5 */
|
||||||
DialRange, /* dial range @added in 1.5 */
|
DialRange, /* dial range @added in 1.5 */
|
||||||
ValueRelation, /* value map from an table @added in 1.8 */
|
ValueRelation, /* value map from an table @added in 1.8 */
|
||||||
|
UuidGenerator, /* uuid generator - readonly and automatically intialized @added in 1.9 */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RangeData
|
struct RangeData
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <qgslonglongvalidator.h>
|
#include <qgslonglongvalidator.h>
|
||||||
#include <qgsfieldvalidator.h>
|
#include <qgsfieldvalidator.h>
|
||||||
#include <qgsmaplayerregistry.h>
|
#include <qgsmaplayerregistry.h>
|
||||||
|
#include <qgslogger.h>
|
||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
@ -40,6 +41,7 @@
|
|||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
void QgsAttributeEditor::selectFileName()
|
void QgsAttributeEditor::selectFileName()
|
||||||
{
|
{
|
||||||
@ -268,7 +270,6 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case QgsVectorLayer::DialRange:
|
case QgsVectorLayer::DialRange:
|
||||||
case QgsVectorLayer::SliderRange:
|
case QgsVectorLayer::SliderRange:
|
||||||
case QgsVectorLayer::EditRange:
|
case QgsVectorLayer::EditRange:
|
||||||
@ -365,6 +366,7 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
|
|||||||
|
|
||||||
case QgsVectorLayer::LineEdit:
|
case QgsVectorLayer::LineEdit:
|
||||||
case QgsVectorLayer::TextEdit:
|
case QgsVectorLayer::TextEdit:
|
||||||
|
case QgsVectorLayer::UuidGenerator:
|
||||||
case QgsVectorLayer::UniqueValuesEditable:
|
case QgsVectorLayer::UniqueValuesEditable:
|
||||||
case QgsVectorLayer::Immutable:
|
case QgsVectorLayer::Immutable:
|
||||||
{
|
{
|
||||||
@ -404,6 +406,11 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
|
|||||||
le->setCompleter( c );
|
le->setCompleter( c );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( editType == QgsVectorLayer::UuidGenerator )
|
||||||
|
{
|
||||||
|
le->setReadOnly( true );
|
||||||
|
}
|
||||||
|
|
||||||
le->setValidator( new QgsFieldValidator( le, field ) );
|
le->setValidator( new QgsFieldValidator( le, field ) );
|
||||||
myWidget = le;
|
myWidget = le;
|
||||||
}
|
}
|
||||||
@ -735,6 +742,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
|
|||||||
case QgsVectorLayer::LineEdit:
|
case QgsVectorLayer::LineEdit:
|
||||||
case QgsVectorLayer::UniqueValuesEditable:
|
case QgsVectorLayer::UniqueValuesEditable:
|
||||||
case QgsVectorLayer::Immutable:
|
case QgsVectorLayer::Immutable:
|
||||||
|
case QgsVectorLayer::UuidGenerator:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
QLineEdit *le = qobject_cast<QLineEdit *>( editor );
|
QLineEdit *le = qobject_cast<QLineEdit *>( editor );
|
||||||
@ -745,12 +753,18 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
|
|||||||
|
|
||||||
QString text;
|
QString text;
|
||||||
if ( value.isNull() )
|
if ( value.isNull() )
|
||||||
|
{
|
||||||
if ( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong )
|
if ( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong )
|
||||||
text = "";
|
text = "";
|
||||||
|
else if ( editType == QgsVectorLayer::UuidGenerator )
|
||||||
|
text = QUuid::createUuid().toString();
|
||||||
else
|
else
|
||||||
text = nullValue;
|
text = nullValue;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
text = value.toString();
|
text = value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
if ( le )
|
if ( le )
|
||||||
le->setText( text );
|
le->setText( text );
|
||||||
|
@ -1736,6 +1736,7 @@ bool QgsPostgresProvider::loadFields()
|
|||||||
fieldTypeName == "geometry" ||
|
fieldTypeName == "geometry" ||
|
||||||
fieldTypeName == "money" ||
|
fieldTypeName == "money" ||
|
||||||
fieldTypeName == "ltree" ||
|
fieldTypeName == "ltree" ||
|
||||||
|
fieldTypeName == "uuid" ||
|
||||||
fieldTypeName.startsWith( "time" ) ||
|
fieldTypeName.startsWith( "time" ) ||
|
||||||
fieldTypeName.startsWith( "date" ) )
|
fieldTypeName.startsWith( "date" ) )
|
||||||
{
|
{
|
||||||
|
@ -81,6 +81,11 @@
|
|||||||
<string>Value relation</string>
|
<string>Value relation</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>UUID generator</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -92,7 +97,7 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>12</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="lineEditPage">
|
<widget class="QWidget" name="lineEditPage">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_1">
|
<layout class="QVBoxLayout" name="verticalLayout_1">
|
||||||
@ -596,7 +601,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="page">
|
<widget class="QWidget" name="valueRelationPage">
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_5">
|
<widget class="QLabel" name="label_5">
|
||||||
@ -679,6 +684,30 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="uuidGenPage">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_14">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_9">
|
||||||
|
<property name="text">
|
||||||
|
<string>Read-only field that generates a UUID if empty.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer_11">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>294</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user