OpenWalnut  1.5.0dev
WPropertyStringWidget.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <cmath>
26 #include <string>
27 
28 #include "core/common/WLogger.h"
29 #include "core/common/WPropertyVariable.h"
30 #include "../WGuiConsts.h"
31 
32 #include "WPropertyStringWidget.h"
33 
34 WPropertyStringWidget::WPropertyStringWidget( WPropString property, QGridLayout* propertyGrid, QWidget* parent ):
35  WPropertyWidget( property, propertyGrid, parent ),
36  m_stringProperty( property ),
37  m_edit( &m_parameterWidgets ),
38  m_layout( &m_parameterWidgets ),
39  m_asText( &m_informationWidgets ),
40  m_infoLayout( &m_informationWidgets )
41 {
42  // initialize members
43  m_parameterWidgets.setLayout( &m_layout );
44 
45  // layout
46  m_layout.addWidget( &m_edit );
47  m_layout.setMargin( WGLOBAL_MARGIN );
48  m_layout.setSpacing( WGLOBAL_SPACING );
49 
50  // Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
51  m_infoLayout.addWidget( &m_asText );
52  m_infoLayout.setMargin( WGLOBAL_MARGIN );
53  m_infoLayout.setSpacing( WGLOBAL_SPACING );
54  m_informationWidgets.setLayout( &m_infoLayout );
55 
56  // To have word warp work correctly -> set size policy
57  m_asText.setTextInteractionFlags( Qt::TextSelectableByMouse );
58  m_edit.setMinimumHeight( WMIN_WIDGET_HEIGHT );
59  m_asText.setMinimumHeight( WMIN_WIDGET_HEIGHT );
60 
61  // set the initial values
62  update();
63 
64  // connect the modification signal of the edit and slider with our callback
65  connect( &m_edit, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) );
66  connect( &m_edit, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) );
67 }
68 
70 {
71  // cleanup
72 }
73 
75 {
76  // To have word warp work correctly -> set size policy
77  m_asText.setTextInteractionFlags( disable ? Qt::NoTextInteraction : Qt::TextSelectableByMouse );
78 }
79 
81 {
82  QString val = QString::fromStdString( m_stringProperty->get() );
83  m_edit.setText( val );
84  m_asText.setText( val );
85 }
86 
88 {
89  std::string value = m_edit.text().toStdString();
90  // now: is the value acceptable by the property?
91  invalidate( !m_stringProperty->set( value ) ); // NOTE: set automatically checks the validity of the value
92 }
93 
94 void WPropertyStringWidget::textEdited( const QString& text )
95 {
96  // this method does NOT set the property actually, but tries to validate it
97  std::string value = text.toStdString();
98  invalidate( !m_stringProperty->accept( value ) );
99 }
100 
101 
void disableTextInteraction(bool disable=true)
Disable the ability to select text.
QHBoxLayout m_infoLayout
The layout used for the pure output (information properties)
void editChanged()
Called whenever the edit field changes.
WPropString m_stringProperty
The integer property represented by this widget.
void textEdited(const QString &text)
Called when the text in m_edit changes.
QLineEdit m_edit
The edit field showing the value.
virtual ~WPropertyStringWidget()
Destructor.
WScaleLabel m_asText
Used to show the property as text.
QHBoxLayout m_layout
Layout used to position the label and the checkbox.
WPropertyStringWidget(WPropString property, QGridLayout *propertyGrid, QWidget *parent=0)
Constructor.
virtual void update()
Called whenever the widget should update.
Class building the base for all widgets representing properties.
QWidget m_informationWidgets
The widget containing a layout and provides the widgets for showing information properties.
QWidget m_parameterWidgets
The widget containing a layout and provides the edit widgets for the property.
virtual void invalidate(bool invalid=true)
This method marks this widget as invalid.
virtual void setText(const QString &text)
reimplemented function to setText
Definition: WScaleLabel.cpp:93