QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgskeyvaluewidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgskeyvaluewidget.h
3  --------------------------------------
4  Date : 08.2016
5  Copyright : (C) 2016 Patrick Valsecchi
6  Email : [email protected]
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSKEYVALUEWIDGET_H
17 #define QGSKEYVALUEWIDGET_H
18 
19 #include "qgstablewidgetbase.h"
20 #include "qgis.h"
21 #include <QAbstractTableModel>
22 #include <QMap>
23 #include "qgis_gui.h"
24 
25 
26 #ifndef SIP_RUN
27 
35 class GUI_EXPORT QgsKeyValueModel : public QAbstractTableModel
36 {
37  Q_OBJECT
38  public:
39 
40  explicit QgsKeyValueModel( QObject *parent = nullptr );
41  void setMap( const QVariantMap &map );
42  QVariantMap map() const;
43 
44  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
45  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
46  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
47  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
48  bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
49  Qt::ItemFlags flags( const QModelIndex &index ) const override;
50  bool insertRows( int position, int rows, const QModelIndex &parent = QModelIndex() ) override;
51  bool removeRows( int position, int rows, const QModelIndex &parent = QModelIndex() ) override;
52 
53  typedef QPair<QString, QVariant> Line;
54 
55  private:
56  QVector<Line> mLines;
57 };
59 #endif
60 
66 class GUI_EXPORT QgsKeyValueWidget: public QgsTableWidgetBase
67 {
68  Q_OBJECT
69  Q_PROPERTY( QVariantMap map READ map WRITE setMap )
70  public:
71 
75  explicit QgsKeyValueWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
76 
80  void setMap( const QVariantMap &map );
81 
86  QVariantMap map() const { return mModel.map(); }
87 
88  private:
89  QgsKeyValueModel mModel;
90 };
91 
92 
93 #endif // QGSKEYVALUEWIDGET_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Base widget allowing to edit a collection, using a table.
QVariantMap map() const
Gets the edit value.
Widget allowing to edit a QVariantMap, using a table.