Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
17 #include <QInputDialog>
18 
20  : QFrame(parent), PropertyEditor(property), m_StringProperty(property)
21 {
22  setFrameStyle(QFrame::NoFrame);
23  setLineWidth(0);
24 
25  // create HBoxLayout with two buttons
26  m_layout = new QHBoxLayout(this);
27  m_layout->setMargin(0);
28 
29  m_label = new QLabel(this);
30  m_layout->addWidget(m_label);
31 
32  m_toolbutton = new QClickableLabel2(this);
33  m_toolbutton->setText("...");
34  m_layout->addWidget(m_toolbutton);
35 
36  m_layout->addStretch(10);
37 
38  connect(m_toolbutton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked()));
39 
40  ensurePolished();
41  adjustSize();
42 
44 }
45 
47 {
48 }
49 
51 {
52  if (m_Property)
53  m_label->setText(m_StringProperty->GetValue());
54 }
55 
57 {
58  m_Property = nullptr;
59  m_StringProperty = nullptr;
60  m_label->setText("n/a");
61 }
62 
64 {
65  bool ok(false);
66  QString newText = QInputDialog::getText(
67  this, "Change text", "You can change the displayed text here", QLineEdit::Normal, m_label->text(), &ok);
68 
69  if (ok)
70  {
71  BeginModifyProperty(); // deregister from events
72 
73  m_StringProperty->SetValue(newText.toStdString());
74  m_label->setText(newText);
75 
76  EndModifyProperty(); // again register for events
77  }
78 }
virtual const char * GetValue() const
mitk::BaseProperty * m_Property
QmitkStringPropertyOnDemandEdit(mitk::StringProperty *, QWidget *parent)
virtual void SetValue(const char *_arg)
Property for strings.