Navigation Menu

Skip to content

Commit

Permalink
It compiles!
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinux committed May 21, 2015
1 parent 06b2b66 commit b82a4d4
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 15 deletions.
14 changes: 8 additions & 6 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -66,7 +66,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
, mDock( 0 )
, mLayer( theLayer )
, mRubberBand( 0 )
, mCurrentSearchWidget( 0 )
, mCurrentSearchWidgetWrapper( 0 )
{
setupUi( this );

Expand Down Expand Up @@ -413,10 +413,9 @@ void QgsAttributeTableDialog::filterColumnChanged( QObject* filterAction )
// replace the search line edit with a search widget that is suited to the selected field
mFilterQuery->setVisible( false );
// delete previous widget
if ( mCurrentSearchWidget != 0 )
if ( mCurrentSearchWidgetWrapper != 0 )
{
//mFilterContainer->removeWidget(mCurrentSearchWidget);
delete mCurrentSearchWidget;
delete mCurrentSearchWidgetWrapper;
}
QString fieldName = mFilterButton->defaultAction()->text();
// get the search widget
Expand All @@ -425,8 +424,11 @@ void QgsAttributeTableDialog::filterColumnChanged( QObject* filterAction )
return;
const QString widgetType = mLayer->editorWidgetV2( fldIdx );
const QgsEditorWidgetConfig widgetConfig = mLayer->editorWidgetV2Config( fldIdx );
QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, mLayer, fldIdx, widgetConfig, 0 , mFilterContainer);
mCurrentSearchWidget = eww->widget();
//replace with createSearch or so
//go to registry and create a create Search method
mCurrentSearchWidgetWrapper= QgsEditorWidgetRegistry::instance()->createSearch( widgetType, mLayer, fldIdx, widgetConfig, mFilterContainer);
mCurrentSearchWidgetWrapper->widget()->setObjectName("searchy");
mCurrentSearchWidgetWrapper->widget()->setVisible( true );

mApplyFilterButton->setVisible( true );
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsattributetabledialog.h
Expand Up @@ -29,6 +29,7 @@
#include "qgsattributedialog.h"
#include "qgsvectorlayer.h" //QgsFeatureIds
#include "qgsfieldmodel.h"
#include "qgseditorwidgetwrapper.h"

class QDialogButtonBox;
class QPushButton;
Expand Down Expand Up @@ -208,7 +209,7 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
QgsFieldModel* mFieldModel;

QgsRubberBand* mRubberBand;
QWidget* mCurrentSearchWidget;
QgsEditorWidgetWrapper* mCurrentSearchWidgetWrapper;
};

#endif
4 changes: 4 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -60,6 +60,7 @@ attributetable/qgsfeatureselectionmodel.cpp
attributetable/qgsgenericfeatureselectionmanager.cpp
attributetable/qgsvectorlayerselectionmanager.cpp

editorwidgets/core/qgsdefaultsearchwidgetwrapper.cpp
editorwidgets/core/qgseditorconfigwidget.cpp
editorwidgets/core/qgseditorwidgetfactory.cpp
editorwidgets/core/qgseditorwidgetregistry.cpp
Expand Down Expand Up @@ -399,6 +400,9 @@ SET(QGIS_GUI_MOC_HDRS
effects/qgspainteffectwidget.h
effects/qgseffectstackpropertieswidget.h

editorwidgets/core/qgsdefaultsearchwidgetwrapper.h
editorwidgets/core/qgseditorconfigwidget.h
editorwidgets/core/qgseditorwidgetregistry.h
editorwidgets/core/qgseditorconfigwidget.h
editorwidgets/core/qgseditorwidgetregistry.h
editorwidgets/core/qgseditorwidgetwrapper.h
Expand Down
56 changes: 56 additions & 0 deletions src/gui/editorwidgets/core/qgsdefaultsearchwidgetwrapper.cpp
@@ -0,0 +1,56 @@
/***************************************************************************
qgstexteditwrapper.cpp
--------------------------------------
Date : 5.1.2014
Copyright : (C) 2014 Matthias Kuhn
Email : matthias dot kuhn at gmx dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsdefaultsearchwidgetwrapper.h"

#include "qgsfield.h"
#include "qgsfieldvalidator.h"

#include <QSettings>

QgsDefaultSearchWidgetWrapper::QgsDefaultSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent )
: QgsEditorWidgetWrapper( vl, fieldIdx, editor, parent )
, mLineEdit( NULL )
{
}

QVariant QgsDefaultSearchWidgetWrapper::value()
{
return QString("foo");
}

QWidget* QgsDefaultSearchWidgetWrapper::createWidget( QWidget* parent )
{
return new QgsFilterLineEdit( parent );
}

void QgsDefaultSearchWidgetWrapper::initWidget( QWidget* editor )
{
connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) );
}

void QgsDefaultSearchWidgetWrapper::setValue( const QVariant& value )
{
mLineEdit->setText( value.toString() ); //FIXME no null check :(
}

void QgsDefaultSearchWidgetWrapper::setEnabled( bool enabled )
{
mLineEdit->setReadOnly( !enabled );
//if ( enabled )
//mLineEdit->setPalette( mWritablePalette );
//else
//mLineEdit->setPalette( mReadOnlyPalette );
}
50 changes: 50 additions & 0 deletions src/gui/editorwidgets/core/qgsdefaultsearchwidgetwrapper.h
@@ -0,0 +1,50 @@
/***************************************************************************
qgstexteditwrapper.h
--------------------------------------
Date : 5.1.2014
Copyright : (C) 2014 Matthias Kuhn
Email : matthias dot kuhn at gmx dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSDEFAULTSEARCHWIDGETWRAPPER_H
#define QGSDEFAULTSEARCHWIDGETWRAPPER_H

#include "qgseditorwidgetwrapper.h"
#include <qgsfilterlineedit.h>


/**
* Wraps a search widget. Default form is just a QgsLineFilterEdit
*
*/

class GUI_EXPORT QgsDefaultSearchWidgetWrapper : public QgsEditorWidgetWrapper
{
Q_OBJECT
public:
explicit QgsDefaultSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor = 0, QWidget* parent = 0 );

// QgsEditorWidgetWrapper interface
public:
QVariant value() override;

protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;

public slots:
void setValue( const QVariant& value ) override;
void setEnabled( bool enabled ) override;

private:
QgsFilterLineEdit* mLineEdit;
};

#endif // QGSDEFAULTSEARCHWIDGETWRAPPER_H
8 changes: 5 additions & 3 deletions src/gui/editorwidgets/core/qgseditorwidgetfactory.cpp
Expand Up @@ -14,10 +14,12 @@
***************************************************************************/

#include "qgseditorwidgetfactory.h"
#include "qgsfilterlineedit.h"
#include "qgsdefaultsearchwidgetwrapper.h"

#include <QSettings>

class QgsDefaultSearchWidgetWrapper;

QgsEditorWidgetFactory::QgsEditorWidgetFactory( const QString& name )
: mName( name )
{
Expand All @@ -27,9 +29,9 @@ QgsEditorWidgetFactory::~QgsEditorWidgetFactory()
{
}

QgsEditorWidgetWrapper* QgsEditorWidgetFactory::createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ){
QgsEditorWidgetWrapper* QgsEditorWidgetFactory::createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) {

return create(vl, fieldIdx, 0, parent);
return new QgsDefaultSearchWidgetWrapper(vl, fieldIdx, 0, parent);
}

QString QgsEditorWidgetFactory::name()
Expand Down
5 changes: 1 addition & 4 deletions src/gui/editorwidgets/core/qgseditorwidgetfactory.h
Expand Up @@ -18,6 +18,7 @@

#include "qgseditorwidgetwrapper.h"
#include "qgsapplication.h"
#include "qgsdefaultsearchwidgetwrapper.h"

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

/**
* Override this in your implementation, to get
* something different than a QLineEdit
*/
QgsEditorWidgetWrapper* createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent );

/**
Expand Down
21 changes: 20 additions & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
Expand Up @@ -16,7 +16,7 @@
#include "qgseditorwidgetregistry.h"

#include "qgsattributeeditorcontext.h"
#include "qgseditorwidgetfactory.h"
//#include "qgseditorwidgetfactory.h"
#include "qgslegacyhelpers.h"
#include "qgsmessagelog.h"
#include "qgsproject.h"
Expand Down Expand Up @@ -100,6 +100,25 @@ QgsEditorWidgetWrapper* QgsEditorWidgetRegistry::create( const QString& widgetId
return 0;
}

QgsEditorWidgetWrapper* QgsEditorWidgetRegistry::createSearch( const QString& widgetId, QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, QWidget* parent, const QgsAttributeEditorContext &context )
{
if ( mWidgetFactories.contains( widgetId ) )
{
QgsEditorWidgetWrapper* ww = mWidgetFactories[widgetId]->createSearchWidget( vl, fieldIdx, parent );

if ( ww )
{
ww->setConfig( config );
ww->setContext( context );
// Make sure that there is a widget created at this point
// so setValue() et al won't crash
ww->widget();
return ww;
}
}
return 0;
}

QgsEditorConfigWidget* QgsEditorWidgetRegistry::createConfigWidget( const QString& widgetId, QgsVectorLayer* vl, int fieldIdx, QWidget* parent )
{
if ( mWidgetFactories.contains( widgetId ) )
Expand Down
7 changes: 7 additions & 0 deletions src/gui/editorwidgets/core/qgseditorwidgetregistry.h
Expand Up @@ -83,6 +83,13 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
QWidget* parent,
const QgsAttributeEditorContext& context = QgsAttributeEditorContext() );

QgsEditorWidgetWrapper* createSearch( const QString& widgetId,
QgsVectorLayer* vl,
int fieldIdx,
const QgsEditorWidgetConfig& config,
QWidget* parent,
const QgsAttributeEditorContext& context = QgsAttributeEditorContext() );

/**
* Creates a configuration widget
*
Expand Down

0 comments on commit b82a4d4

Please sign in to comment.