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