QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscheckboxwidgetwrapper.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscheckboxwidgetwrapper.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 
17 
18 QgsCheckboxWidgetWrapper::QgsCheckboxWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent )
19  : QgsEditorWidgetWrapper( vl, fieldIdx, editor, parent )
20 {
21 }
22 
23 
25 {
26  QVariant v;
27 
28  if ( mGroupBox )
29  v = mGroupBox->isChecked() ? config( "CheckedState" ) : config( "UncheckedState" );
30 
31  if ( mCheckBox )
32  v = mCheckBox->isChecked() ? config( "CheckedState" ) : config( "UncheckedState" );
33 
34 
35  return v;
36 }
37 
38 QWidget* QgsCheckboxWidgetWrapper::createWidget( QWidget* parent )
39 {
40  return new QCheckBox( parent );
41 }
42 
43 void QgsCheckboxWidgetWrapper::initWidget( QWidget* editor )
44 {
45  mCheckBox = qobject_cast<QCheckBox*>( editor );
46  mGroupBox = qobject_cast<QGroupBox*>( editor );
47 
48  if ( mCheckBox )
49  connect( mCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( valueChanged( bool ) ) );
50  if ( mGroupBox )
51  connect( mGroupBox, SIGNAL( toggled( bool ) ), this, SLOT( valueChanged( bool ) ) );
52 }
53 
54 void QgsCheckboxWidgetWrapper::setValue( const QVariant& value )
55 {
56  if ( mGroupBox )
57  {
58  mGroupBox->setChecked( value == config( "CheckedState" ) );
59  }
60 
61  if ( mCheckBox )
62  {
63  mCheckBox->setChecked( value == config( "CheckedState" ) );
64  }
65 }
void setValue(const QVariant &value)
void valueChanged()
Will call the value() method to determine the emitted value.
Manages an editor widget Widget and wrapper share the same parent.
QVariant value()
Will be used to access the widget's value.
void initWidget(QWidget *editor)
This method should initialize the editor widget with runtime data.
QWidget * createWidget(QWidget *parent)
This method should create a new widget with the provided parent.
const QgsEditorWidgetConfig config()
Returns the whole config.
Represents a vector layer which manages a vector based data sets.
QgsCheckboxWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *editor=0, QWidget *parent=0)