Medical Imaging Interaction Toolkit  2018.4.99-07c45cb1
Medical Imaging Interaction Toolkit
QmitkStringPropertyOnDemandEdit.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
13 #include <QInputDialog>
14 
16  : QFrame(parent), PropertyEditor(property), m_StringProperty(property)
17 {
18  setFrameStyle(QFrame::NoFrame);
19  setLineWidth(0);
20 
21  // create HBoxLayout with two buttons
22  m_layout = new QHBoxLayout(this);
23  m_layout->setMargin(0);
24 
25  m_label = new QLabel(this);
26  m_layout->addWidget(m_label);
27 
28  m_toolbutton = new QClickableLabel2(this);
29  m_toolbutton->setText("...");
30  m_layout->addWidget(m_toolbutton);
31 
32  m_layout->addStretch(10);
33 
34  connect(m_toolbutton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked()));
35 
36  ensurePolished();
37  adjustSize();
38 
40 }
41 
43 {
44 }
45 
47 {
48  if (m_Property)
49  m_label->setText(m_StringProperty->GetValue());
50 }
51 
53 {
54  m_Property = nullptr;
55  m_StringProperty = nullptr;
56  m_label->setText("n/a");
57 }
58 
60 {
61  bool ok(false);
62  QString newText = QInputDialog::getText(
63  this, "Change text", "You can change the displayed text here", QLineEdit::Normal, m_label->text(), &ok);
64 
65  if (ok)
66  {
67  BeginModifyProperty(); // deregister from events
68 
69  m_StringProperty->SetValue(newText.toStdString());
70  m_label->setText(newText);
71 
72  EndModifyProperty(); // again register for events
73  }
74 }
virtual const char * GetValue() const
mitk::BaseProperty * m_Property
QmitkStringPropertyOnDemandEdit(mitk::StringProperty *, QWidget *parent)
virtual void SetValue(const char *_arg)
Property for strings.