1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
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.
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.
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/>.
23
//---------------------------------------------------------------------------
28
#include <boost/lexical_cast.hpp>
30
#include "core/common/WLogger.h"
31
#include "core/common/WPropertyVariable.h"
32
#include "../WGuiConsts.h"
34
#include "WPropertyStringWidget.h"
35
#include "WPropertyStringWidget.moc"
37
WPropertyStringWidget::WPropertyStringWidget( WPropString property, QGridLayout* propertyGrid, QWidget* parent ):
38
WPropertyWidget( property, propertyGrid, parent ),
39
m_stringProperty( property ),
40
m_edit( &m_parameterWidgets ),
41
m_layout( &m_parameterWidgets ),
42
m_asText( &m_informationWidgets ),
43
m_infoLayout( &m_informationWidgets )
46
m_parameterWidgets.setLayout( &m_layout );
49
m_layout.addWidget( &m_edit );
50
m_layout.setMargin( WGLOBAL_MARGIN );
51
m_layout.setSpacing( WGLOBAL_SPACING );
53
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
54
m_infoLayout.addWidget( &m_asText );
55
m_infoLayout.setMargin( WGLOBAL_MARGIN );
56
m_infoLayout.setSpacing( WGLOBAL_SPACING );
57
m_informationWidgets.setLayout( &m_infoLayout );
58
m_asText.setWordWrap( true );
59
// To have word warp work correctly -> set size policy
60
m_asText.setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) );
62
m_asText.setTextInteractionFlags( Qt::TextSelectableByMouse );
64
// set the initial values
67
// connect the modification signal of the edit and slider with our callback
68
connect( &m_edit, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) );
69
connect( &m_edit, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) );
72
WPropertyStringWidget::~WPropertyStringWidget()
77
void WPropertyStringWidget::update()
79
QString val = QString::fromStdString( m_stringProperty->get() );
80
m_edit.setText( val );
81
m_asText.setText( val );
84
void WPropertyStringWidget::editChanged()
86
std::string value = m_edit.text().toStdString();
87
// now: is the value acceptable by the property?
88
invalidate( !m_stringProperty->set( value ) ); // NOTE: set automatically checks the validity of the value
91
void WPropertyStringWidget::textEdited( const QString& text )
93
// this method does NOT set the property actually, but tries to validate it
94
std::string value = text.toStdString();
95
invalidate( !m_stringProperty->accept( value ) );