Skip to content

Commit b82a4d4

Browse files
committed
It compiles!
1 parent 06b2b66 commit b82a4d4

9 files changed

+153
-15
lines changed

src/app/qgsattributetabledialog.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
6666
, mDock( 0 )
6767
, mLayer( theLayer )
6868
, mRubberBand( 0 )
69-
, mCurrentSearchWidget( 0 )
69+
, mCurrentSearchWidgetWrapper( 0 )
7070
{
7171
setupUi( this );
7272

@@ -413,10 +413,9 @@ void QgsAttributeTableDialog::filterColumnChanged( QObject* filterAction )
413413
// replace the search line edit with a search widget that is suited to the selected field
414414
mFilterQuery->setVisible( false );
415415
// delete previous widget
416-
if ( mCurrentSearchWidget != 0 )
416+
if ( mCurrentSearchWidgetWrapper != 0 )
417417
{
418-
//mFilterContainer->removeWidget(mCurrentSearchWidget);
419-
delete mCurrentSearchWidget;
418+
delete mCurrentSearchWidgetWrapper;
420419
}
421420
QString fieldName = mFilterButton->defaultAction()->text();
422421
// get the search widget
@@ -425,8 +424,11 @@ void QgsAttributeTableDialog::filterColumnChanged( QObject* filterAction )
425424
return;
426425
const QString widgetType = mLayer->editorWidgetV2( fldIdx );
427426
const QgsEditorWidgetConfig widgetConfig = mLayer->editorWidgetV2Config( fldIdx );
428-
QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, mLayer, fldIdx, widgetConfig, 0 , mFilterContainer);
429-
mCurrentSearchWidget = eww->widget();
427+
//replace with createSearch or so
428+
//go to registry and create a create Search method
429+
mCurrentSearchWidgetWrapper= QgsEditorWidgetRegistry::instance()->createSearch( widgetType, mLayer, fldIdx, widgetConfig, mFilterContainer);
430+
mCurrentSearchWidgetWrapper->widget()->setObjectName("searchy");
431+
mCurrentSearchWidgetWrapper->widget()->setVisible( true );
430432

431433
mApplyFilterButton->setVisible( true );
432434
}

src/app/qgsattributetabledialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "qgsattributedialog.h"
3030
#include "qgsvectorlayer.h" //QgsFeatureIds
3131
#include "qgsfieldmodel.h"
32+
#include "qgseditorwidgetwrapper.h"
3233

3334
class QDialogButtonBox;
3435
class QPushButton;
@@ -208,7 +209,7 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
208209
QgsFieldModel* mFieldModel;
209210

210211
QgsRubberBand* mRubberBand;
211-
QWidget* mCurrentSearchWidget;
212+
QgsEditorWidgetWrapper* mCurrentSearchWidgetWrapper;
212213
};
213214

214215
#endif

src/gui/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ attributetable/qgsfeatureselectionmodel.cpp
6060
attributetable/qgsgenericfeatureselectionmanager.cpp
6161
attributetable/qgsvectorlayerselectionmanager.cpp
6262

63+
editorwidgets/core/qgsdefaultsearchwidgetwrapper.cpp
6364
editorwidgets/core/qgseditorconfigwidget.cpp
6465
editorwidgets/core/qgseditorwidgetfactory.cpp
6566
editorwidgets/core/qgseditorwidgetregistry.cpp
@@ -399,6 +400,9 @@ SET(QGIS_GUI_MOC_HDRS
399400
effects/qgspainteffectwidget.h
400401
effects/qgseffectstackpropertieswidget.h
401402

403+
editorwidgets/core/qgsdefaultsearchwidgetwrapper.h
404+
editorwidgets/core/qgseditorconfigwidget.h
405+
editorwidgets/core/qgseditorwidgetregistry.h
402406
editorwidgets/core/qgseditorconfigwidget.h
403407
editorwidgets/core/qgseditorwidgetregistry.h
404408
editorwidgets/core/qgseditorwidgetwrapper.h
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/***************************************************************************
2+
qgstexteditwrapper.cpp
3+
--------------------------------------
4+
Date : 5.1.2014
5+
Copyright : (C) 2014 Matthias Kuhn
6+
Email : matthias dot kuhn at gmx dot ch
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+
#include "qgsdefaultsearchwidgetwrapper.h"
17+
18+
#include "qgsfield.h"
19+
#include "qgsfieldvalidator.h"
20+
21+
#include <QSettings>
22+
23+
QgsDefaultSearchWidgetWrapper::QgsDefaultSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent )
24+
: QgsEditorWidgetWrapper( vl, fieldIdx, editor, parent )
25+
, mLineEdit( NULL )
26+
{
27+
}
28+
29+
QVariant QgsDefaultSearchWidgetWrapper::value()
30+
{
31+
return QString("foo");
32+
}
33+
34+
QWidget* QgsDefaultSearchWidgetWrapper::createWidget( QWidget* parent )
35+
{
36+
return new QgsFilterLineEdit( parent );
37+
}
38+
39+
void QgsDefaultSearchWidgetWrapper::initWidget( QWidget* editor )
40+
{
41+
connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) );
42+
}
43+
44+
void QgsDefaultSearchWidgetWrapper::setValue( const QVariant& value )
45+
{
46+
mLineEdit->setText( value.toString() ); //FIXME no null check :(
47+
}
48+
49+
void QgsDefaultSearchWidgetWrapper::setEnabled( bool enabled )
50+
{
51+
mLineEdit->setReadOnly( !enabled );
52+
//if ( enabled )
53+
//mLineEdit->setPalette( mWritablePalette );
54+
//else
55+
//mLineEdit->setPalette( mReadOnlyPalette );
56+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/***************************************************************************
2+
qgstexteditwrapper.h
3+
--------------------------------------
4+
Date : 5.1.2014
5+
Copyright : (C) 2014 Matthias Kuhn
6+
Email : matthias dot kuhn at gmx dot ch
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 QGSDEFAULTSEARCHWIDGETWRAPPER_H
17+
#define QGSDEFAULTSEARCHWIDGETWRAPPER_H
18+
19+
#include "qgseditorwidgetwrapper.h"
20+
#include <qgsfilterlineedit.h>
21+
22+
23+
/**
24+
* Wraps a search widget. Default form is just a QgsLineFilterEdit
25+
*
26+
*/
27+
28+
class GUI_EXPORT QgsDefaultSearchWidgetWrapper : public QgsEditorWidgetWrapper
29+
{
30+
Q_OBJECT
31+
public:
32+
explicit QgsDefaultSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor = 0, QWidget* parent = 0 );
33+
34+
// QgsEditorWidgetWrapper interface
35+
public:
36+
QVariant value() override;
37+
38+
protected:
39+
QWidget* createWidget( QWidget* parent ) override;
40+
void initWidget( QWidget* editor ) override;
41+
42+
public slots:
43+
void setValue( const QVariant& value ) override;
44+
void setEnabled( bool enabled ) override;
45+
46+
private:
47+
QgsFilterLineEdit* mLineEdit;
48+
};
49+
50+
#endif // QGSDEFAULTSEARCHWIDGETWRAPPER_H

src/gui/editorwidgets/core/qgseditorwidgetfactory.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
***************************************************************************/
1515

1616
#include "qgseditorwidgetfactory.h"
17-
#include "qgsfilterlineedit.h"
17+
#include "qgsdefaultsearchwidgetwrapper.h"
1818

1919
#include <QSettings>
2020

21+
class QgsDefaultSearchWidgetWrapper;
22+
2123
QgsEditorWidgetFactory::QgsEditorWidgetFactory( const QString& name )
2224
: mName( name )
2325
{
@@ -27,9 +29,9 @@ QgsEditorWidgetFactory::~QgsEditorWidgetFactory()
2729
{
2830
}
2931

30-
QgsEditorWidgetWrapper* QgsEditorWidgetFactory::createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ){
32+
QgsEditorWidgetWrapper* QgsEditorWidgetFactory::createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) {
3133

32-
return create(vl, fieldIdx, 0, parent);
34+
return new QgsDefaultSearchWidgetWrapper(vl, fieldIdx, 0, parent);
3335
}
3436

3537
QString QgsEditorWidgetFactory::name()

src/gui/editorwidgets/core/qgseditorwidgetfactory.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "qgseditorwidgetwrapper.h"
2020
#include "qgsapplication.h"
21+
#include "qgsdefaultsearchwidgetwrapper.h"
2122

2223
#include <QDomNode>
2324
#include <QMap>
@@ -60,10 +61,6 @@ class GUI_EXPORT QgsEditorWidgetFactory
6061
*/
6162
virtual QgsEditorWidgetWrapper* create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const = 0;
6263

63-
/**
64-
* Override this in your implementation, to get
65-
* something different than a QLineEdit
66-
*/
6764
QgsEditorWidgetWrapper* createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent );
6865

6966
/**

src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "qgseditorwidgetregistry.h"
1717

1818
#include "qgsattributeeditorcontext.h"
19-
#include "qgseditorwidgetfactory.h"
19+
//#include "qgseditorwidgetfactory.h"
2020
#include "qgslegacyhelpers.h"
2121
#include "qgsmessagelog.h"
2222
#include "qgsproject.h"
@@ -100,6 +100,25 @@ QgsEditorWidgetWrapper* QgsEditorWidgetRegistry::create( const QString& widgetId
100100
return 0;
101101
}
102102

103+
QgsEditorWidgetWrapper* QgsEditorWidgetRegistry::createSearch( const QString& widgetId, QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, QWidget* parent, const QgsAttributeEditorContext &context )
104+
{
105+
if ( mWidgetFactories.contains( widgetId ) )
106+
{
107+
QgsEditorWidgetWrapper* ww = mWidgetFactories[widgetId]->createSearchWidget( vl, fieldIdx, parent );
108+
109+
if ( ww )
110+
{
111+
ww->setConfig( config );
112+
ww->setContext( context );
113+
// Make sure that there is a widget created at this point
114+
// so setValue() et al won't crash
115+
ww->widget();
116+
return ww;
117+
}
118+
}
119+
return 0;
120+
}
121+
103122
QgsEditorConfigWidget* QgsEditorWidgetRegistry::createConfigWidget( const QString& widgetId, QgsVectorLayer* vl, int fieldIdx, QWidget* parent )
104123
{
105124
if ( mWidgetFactories.contains( widgetId ) )

src/gui/editorwidgets/core/qgseditorwidgetregistry.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
8383
QWidget* parent,
8484
const QgsAttributeEditorContext& context = QgsAttributeEditorContext() );
8585

86+
QgsEditorWidgetWrapper* createSearch( const QString& widgetId,
87+
QgsVectorLayer* vl,
88+
int fieldIdx,
89+
const QgsEditorWidgetConfig& config,
90+
QWidget* parent,
91+
const QgsAttributeEditorContext& context = QgsAttributeEditorContext() );
92+
8693
/**
8794
* Creates a configuration widget
8895
*

0 commit comments

Comments
 (0)