1 /***************************************************************************
2     qgsrelationreferencesearchwidgetwrapper.h
3      ----------------------------------------
4     Date                 : 2016-05-25
5     Copyright            : (C) 2016 Nyall Dawson
6     Email                : nyall dot dawson at gmail dot com
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 QGSRELATIONREFERENCESEARCHWIDGETWRAPPER_H
17 #define QGSRELATIONREFERENCESEARCHWIDGETWRAPPER_H
18 
19 #include "qgssearchwidgetwrapper.h"
20 
21 #include <QComboBox>
22 #include <QListWidget>
23 #include <QLineEdit>
24 
25 #include "qgis_gui.h"
26 #include "qgis_sip.h"
27 
28 class QgsRelationReferenceWidgetFactory;
29 class QgsMapCanvas;
30 class QgsRelationReferenceWidget;
31 
32 /**
33  * \ingroup gui
34  * \class QgsRelationReferenceSearchWidgetWrapper
35  * \brief Wraps a relation reference search widget.
36  * \since QGIS 2.16
37  */
38 
39 class GUI_EXPORT QgsRelationReferenceSearchWidgetWrapper : public QgsSearchWidgetWrapper
40 {
41     Q_OBJECT
42 
43   public:
44 
45     /**
46      * Constructor for QgsRelationReferenceSearchWidgetWrapper
47      * \param vl associated vector layer
48      * \param fieldIdx associated field index
49      * \param canvas optional map canvas
50      * \param parent parent widget
51      */
52     explicit QgsRelationReferenceSearchWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QgsMapCanvas *canvas, QWidget *parent = nullptr );
53 
54     /**
55      * Returns a variant representing the current state of the widget.
56      */
57     QVariant value() const;
58 
59     bool applyDirectly() override;
60     QString expression() const override;
61     bool valid() const override;
62     QgsSearchWidgetWrapper::FilterFlags supportedFlags() const override;
63 
64     /**
65      * Returns the default flags (equalTo)
66      */
67     QgsSearchWidgetWrapper::FilterFlags defaultFlags() const override;
68     QString createExpression( QgsSearchWidgetWrapper::FilterFlags flags ) const override;
69 
70   public slots:
71 
72     void clearWidget() override;
73     void setEnabled( bool enabled ) override;
74 
75   protected:
76     QWidget *createWidget( QWidget *parent ) override;
77     void initWidget( QWidget *editor ) override;
78 
79   public slots:
80 
81     /**
82      * Called when current value of search widget changes
83      * \deprecated since QGIS 3.10 made private
84      */
85     Q_DECL_DEPRECATED void onValueChanged( const QVariant &value ) SIP_DEPRECATED;
86 
87   protected slots:
88     void setExpression( const QString &exp ) override;
89 
90   private:
91     void onValuesChanged( const QVariantList &values );
92 
93     QgsRelationReferenceWidget *mWidget = nullptr;
94     QgsVectorLayer *mLayer = nullptr;
95     QgsMapCanvas *mCanvas = nullptr;
96 
97     friend class QgsRelationReferenceWidgetFactory;
98 };
99 
100 #endif // QGSRELATIONREFERENCESEARCHWIDGETWRAPPER_H
101