QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgsnewauxiliaryfielddialog.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsnewauxiliaryfielddialog.cpp - description
3
-------------------
4
begin : Sept 05, 2017
5
copyright : (C) 2017 by Paul Blottiere
6
email : paul.blottiere@oslandia.com
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#include "
qgsnewauxiliaryfielddialog.h
"
19
20
#include "
qgsapplication.h
"
21
#include "
qgsauxiliarystorage.h
"
22
#include "
qgsgui.h
"
23
#include "
qgsvariantutils.h
"
24
25
#include <QMessageBox>
26
27
#include "moc_qgsnewauxiliaryfielddialog.cpp"
28
29
QgsNewAuxiliaryFieldDialog::QgsNewAuxiliaryFieldDialog
(
const
QgsPropertyDefinition
&def,
QgsVectorLayer
*layer,
bool
nameOnly, QWidget *parent )
30
: QDialog( parent )
31
,
mLayer
( layer )
32
,
mNameOnly
( nameOnly )
33
,
mPropertyDefinition
( def )
34
{
35
setupUi(
this
);
36
QgsGui::enableAutoGeometryRestore
(
this
);
37
38
mType->addItem(
QgsFields::iconForFieldType
( QMetaType::Type::QString ),
QgsVariantUtils::typeToDisplayString
( QMetaType::Type::QString ),
QgsPropertyDefinition::DataTypeString
);
39
mType->addItem(
QgsFields::iconForFieldType
( QMetaType::Type::Double ),
QgsVariantUtils::typeToDisplayString
( QMetaType::Type::Double ),
QgsPropertyDefinition::DataTypeNumeric
);
40
mType->addItem(
QgsFields::iconForFieldType
( QMetaType::Type::Int ), tr(
"Integer"
),
QgsPropertyDefinition::DataTypeBoolean
);
41
42
mType->setCurrentIndex( mType->findData( def.
dataType
() ) );
43
44
if
(
mNameOnly
)
45
mType->setEnabled(
false
);
46
else
47
mType->setEnabled(
true
);
48
}
49
50
void
QgsNewAuxiliaryFieldDialog::accept
()
51
{
52
QgsPropertyDefinition
def =
mPropertyDefinition
;
53
def.
setComment
( mName->text() );
54
55
if
( !
mNameOnly
)
56
{
57
def.
setDataType
(
static_cast<
QgsPropertyDefinition::DataType
>
( mType->currentData().toInt() ) );
58
59
def.
setOrigin
(
"user"
);
60
def.
setName
(
"custom"
);
61
}
62
63
const
QString fieldName =
QgsAuxiliaryLayer::nameFromProperty
( def,
true
);
64
const
int
idx =
mLayer
->fields().lookupField( fieldName );
65
if
( idx >= 0 )
66
{
67
const
QString title = tr(
"New Auxiliary Field"
);
68
const
QString msg = tr(
"Invalid name. Auxiliary field '%1' already exists."
).arg( fieldName );
69
QMessageBox::critical(
this
, title, msg, QMessageBox::Ok );
70
}
71
else
if
( def.
comment
().isEmpty() )
72
{
73
const
QString title = tr(
"New Auxiliary Field"
);
74
const
QString msg = tr(
"Name is a mandatory parameter."
);
75
QMessageBox::critical(
this
, title, msg, QMessageBox::Ok );
76
}
77
else
78
{
79
if
(
mLayer
->auxiliaryLayer()->addAuxiliaryField( def ) )
80
mPropertyDefinition
= def;
81
QDialog::accept();
82
}
83
}
84
85
QgsPropertyDefinition
QgsNewAuxiliaryFieldDialog::propertyDefinition
()
const
86
{
87
return
mPropertyDefinition
;
88
}
QgsAuxiliaryLayer::nameFromProperty
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
QgsFields::iconForFieldType
static QIcon iconForFieldType(QMetaType::Type type, QMetaType::Type subType=QMetaType::Type::UnknownType, const QString &typeString=QString())
Returns an icon corresponding to a field type.
Definition
qgsfields.cpp:340
QgsGui::enableAutoGeometryRestore
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition
qgsgui.cpp:225
QgsNewAuxiliaryFieldDialog::mNameOnly
bool mNameOnly
Definition
qgsnewauxiliaryfielddialog.h:55
QgsNewAuxiliaryFieldDialog::mLayer
QgsVectorLayer * mLayer
Definition
qgsnewauxiliaryfielddialog.h:54
QgsNewAuxiliaryFieldDialog::accept
void accept() override
Definition
qgsnewauxiliaryfielddialog.cpp:50
QgsNewAuxiliaryFieldDialog::mPropertyDefinition
QgsPropertyDefinition mPropertyDefinition
Definition
qgsnewauxiliaryfielddialog.h:56
QgsNewAuxiliaryFieldDialog::propertyDefinition
QgsPropertyDefinition propertyDefinition() const
Returns the underlying property definition.
Definition
qgsnewauxiliaryfielddialog.cpp:85
QgsNewAuxiliaryFieldDialog::QgsNewAuxiliaryFieldDialog
QgsNewAuxiliaryFieldDialog(const QgsPropertyDefinition &definition, QgsVectorLayer *layer, bool nameOnly=true, QWidget *parent=nullptr)
Constructor.
Definition
qgsnewauxiliaryfielddialog.cpp:29
QgsPropertyDefinition
Definition for a property.
Definition
qgsproperty.h:47
QgsPropertyDefinition::comment
QString comment() const
Returns the comment of the property.
Definition
qgsproperty.h:167
QgsPropertyDefinition::dataType
DataType dataType() const
Returns the allowable field/value data type for the property.
Definition
qgsproperty.h:187
QgsPropertyDefinition::setOrigin
void setOrigin(const QString &origin)
Sets the origin of the property.
Definition
qgsproperty.h:157
QgsPropertyDefinition::setDataType
void setDataType(DataType type)
Sets the data type.
Definition
qgsproperty.h:182
QgsPropertyDefinition::setName
void setName(const QString &name)
Sets the name of the property.
Definition
qgsproperty.h:143
QgsPropertyDefinition::setComment
void setComment(const QString &comment)
Sets comment of the property.
Definition
qgsproperty.h:172
QgsPropertyDefinition::DataType
DataType
Valid data types required by property.
Definition
qgsproperty.h:84
QgsPropertyDefinition::DataTypeString
@ DataTypeString
Property requires a string value.
Definition
qgsproperty.h:91
QgsPropertyDefinition::DataTypeBoolean
@ DataTypeBoolean
Property requires a boolean value.
Definition
qgsproperty.h:105
QgsPropertyDefinition::DataTypeNumeric
@ DataTypeNumeric
Property requires a numeric value.
Definition
qgsproperty.h:98
QgsVariantUtils::typeToDisplayString
static QString typeToDisplayString(QMetaType::Type type, QMetaType::Type subType=QMetaType::Type::UnknownType)
Returns a user-friendly translated string representing a QVariant type.
Definition
qgsvariantutils.cpp:44
QgsVectorLayer
Represents a vector layer which manages a vector based dataset.
Definition
qgsvectorlayer.h:414
qgsapplication.h
qgsauxiliarystorage.h
qgsgui.h
qgsnewauxiliaryfielddialog.h
qgsvariantutils.h
Generated on
for QGIS API Documentation by
1.17.0