Fraxinus  18.10
An IGT application
cxLabeledLineEditWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
14 #include <iostream>
15 #include "cxTypeConversions.h"
16 #include "cxLogger.h"
17 
18 
19 namespace cx
20 {
21 
23 
25  QGridLayout* gridLayout, int row) :
26  OptimizedUpdateWidget(parent)
27 {
28  CX_ASSERT(dataInterface->getAllowOnlyValuesInRange()==false);
29  mData = dataInterface;
30  connect(mData.get(), SIGNAL(changed()), this, SLOT(setModified()));
31 
32  QHBoxLayout* topLayout = new QHBoxLayout;
33  topLayout->setMargin(0);
34  this->setLayout(topLayout);
35 
36  mLabel = new QLabel(this);
37  mLabel->setText(mData->getDisplayName());
38  topLayout->addWidget(mLabel);
39 
40  mLine = new QLineEdit(this);
41  topLayout->addWidget(mLine);
42  connect(mLine, SIGNAL(editingFinished()), this, SLOT(editingFinished()));
43 
44  if (gridLayout) // add to input gridlayout
45  {
46  gridLayout->addWidget(mLabel, row, 0);
47  gridLayout->addWidget(mLine, row, 1);
48  }
49  else // add directly to this
50  {
51  topLayout->addWidget(mLabel);
52  topLayout->addWidget(mLine, 1);
53  }
54 
55  this->setModified();
56 }
57 
58 void LabeledLineEditWidget::editingFinished()
59 {
60  mData->setValue(mLine->text());
61 }
62 
63 void LabeledLineEditWidget::prePaintEvent()
64 {
65  mLine->blockSignals(true);
66  mLine->setReadOnly(mData->isReadOnly());
67  mLine->setText(mData->getValue());
68  mLine->setToolTip(mData->getHelp());
69  mLabel->setToolTip(mData->getHelp());
70  mLine->blockSignals(false);
71 }
72 
73 } // namespace cx
LabeledLineEditWidget(QWidget *parent, StringPropertyBasePtr, QGridLayout *gridLayout=0, int row=0)
#define CX_ASSERT(statement)
Definition: cxLogger.h:116
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr
Interface for all classes following the modified/prepaint paradigm.
Namespace for all CustusX production code.