QGIS API Documentation 4.3.0-Master (0cef2469b72)
Loading...
Searching...
No Matches
qgsfieldsitem.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfieldsitem.h
3 -------------------
4 begin : 2011-04-01
5 copyright : (C) 2011 Radim Blazek
6 email : radim dot blazek at gmail dot 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#ifndef QGSFIELDSITEM_H
18#define QGSFIELDSITEM_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
23#include "qgsdataitem.h"
24#include "qgsfield.h"
25#include "qgsfielddomain.h"
26
27#include <QString>
28
29using namespace Qt::StringLiterals;
30
40class CORE_EXPORT QgsFieldsItem : public QgsDataItem
41{
42 Q_OBJECT
43
44 public:
55 QgsFieldsItem( QgsDataItem *parent SIP_TRANSFERTHIS, const QString &path, const QString &connectionUri, const QString &providerKey, const QString &schema, const QString &tableName );
56
57 ~QgsFieldsItem() override;
58
59#ifdef SIP_RUN
60 // clang-format off
61 SIP_PYOBJECT __repr__();
62 % MethodCode
63 QString str = u"<QgsFieldsItem: %1>"_s.arg( sipCpp->path() );
64 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
65 % End
66// clang-format on
67#endif
68
69 QVector<QgsDataItem *> createChildren() override;
70
71 QIcon icon() override;
72
76 QString schema() const;
77
81 QString tableName() const;
82
86 QString connectionUri() const;
87
92
100 QgsFields fields() const;
101
107
113 bool canRenameFields() const { return mCanRename; }
114
115 private:
116 QString mSchema;
117 QString mTableName;
118 QString mConnectionUri;
119 bool mCanRename = false;
120 std::unique_ptr<QgsAbstractDatabaseProviderConnection::TableProperty> mTableProperty;
121 QgsFields mFields;
122};
123
124
133class CORE_EXPORT QgsFieldItem : public QgsDataItem
134{
135 Q_OBJECT
136 public:
142
143 ~QgsFieldItem() override;
144
145#ifdef SIP_RUN
146 // clang-format off
147 SIP_PYOBJECT __repr__();
148 % MethodCode
149 QString str = u"<QgsFieldItem: %1>"_s.arg( sipCpp->name() );
150 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
151 % End
152// clang-format on
153#endif
154
155 QIcon icon() override;
156
162 QgsField field() const { return mField; }
163
164 bool equal( const QgsDataItem *other ) override;
165
171 void setDomain( QgsFieldDomain *domain SIP_TRANSFER );
172
173 private:
174 const QgsField mField;
175 std::unique_ptr<QgsFieldDomain> mDomain;
176};
177
178#endif // QGSFIELDSITEM_H
Base class for all items in the model.
Definition qgsdataitem.h:50
QgsDataItem(Qgis::BrowserItemType type, QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey=QString())
Constructor for QgsDataItem, with the specified parent item.
virtual QVector< QgsDataItem * > createChildren()
Create children.
QString path() const
virtual QIcon icon()
QgsDataItem * parent() const
Gets item parent.
QString providerKey() const
Returns the provider key that created this item (e.g.
virtual bool equal(const QgsDataItem *other)
Returns true if this item is equal to another item (by testing item type and path).
Base class for field domains.
QgsFieldItem(QgsDataItem *parent, const QgsField &field)
Constructor for QgsFieldItem, with the specified parent item and field.
QgsField field() const
Returns the field definition.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
QString tableName() const
Returns the table name.
QgsFieldsItem(QgsDataItem *parent, const QString &path, const QString &connectionUri, const QString &providerKey, const QString &schema, const QString &tableName)
Constructor for QgsFieldsItem, with the specified parent item.
QgsAbstractDatabaseProviderConnection::TableProperty * tableProperty() const
Returns the (possibly nullptr) properties of the table this fields belong to.
QString connectionUri() const
Returns the connection URI.
QgsVectorLayer * layer()
Creates and returns a (possibly nullptr) layer from the connection URI and schema/table information.
bool canRenameFields() const
Returns true if the connection supports renaming fields.
QgsFields fields() const
Returns the fields contained by the item.
QString schema() const
Returns the schema name.
Container of fields for a vector layer.
Definition qgsfields.h:45
Represents a vector layer which manages a vector based dataset.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
The TableProperty class represents a database table or view.