fw4spl
t/src/fwGuiQt/dialog/InputDialog.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 
8 #include "fwGuiQt/dialog/InputDialog.hpp"
9 
10 #include <fwGui/registry/macros.hpp>
11 
12 #include <boost/assign/list_of.hpp>
13 #include <QApplication>
14 #include <QInputDialog>
15 #include <QObject>
16 
17 fwGuiRegisterMacro( ::fwGuiQt::dialog::InputDialog, ::fwGui::dialog::IInputDialog::REGISTRY_KEY );
18 
19 namespace fwGuiQt
20 {
21 namespace dialog
22 {
23 
24 //------------------------------------------------------------------------------
25 
26 InputDialog::InputDialog(::fwGui::GuiBaseObject::Key key) : m_input("")
27 {
28 }
29 
30 //------------------------------------------------------------------------------
31 
33 {
34 }
35 
36 //------------------------------------------------------------------------------
37 
38 void InputDialog::setTitle( const std::string &title )
39 {
40  m_title = title;
41 }
42 
43 //------------------------------------------------------------------------------
44 
45 void InputDialog::setMessage( const std::string &msg )
46 {
47  m_message = msg;
48 }
49 
50 //------------------------------------------------------------------------------
51 
53 void InputDialog::setInput(const std::string &text)
54 {
55  m_input = text;
56 }
57 
58 //------------------------------------------------------------------------------
59 
61 std::string InputDialog::getInput()
62 {
63  QString title = QObject::tr(m_title.c_str());
64  QString text = QObject::tr(m_message.c_str());
65 
66  bool IsOkClicked;
67  QString outputText = QInputDialog::getText(
68  qApp->activeWindow(), title, text, QLineEdit::Normal,QString::fromStdString(m_input),&IsOkClicked);
69 
70  if ( IsOkClicked)
71  {
72  m_input = outputText.toStdString();
73  }
74  else
75  {
76  m_input = "";
77  }
78  return m_input;
79 }
80 
81 //------------------------------------------------------------------------------
82 
83 } // namespace dialog
84 } // namespace fwGuiQt
85 
86 
87 
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the input dialog.
virtual FWGUI_API std::string getInput() override
Get the input text in the input field.
The namespace fwGuiQt contains classes which provide the implementation of the Gui using Qt library...
Definition: WindowLevel.hpp:32
virtual FWGUI_API ~InputDialog()
Destructor. Do nothing.
virtual FWGUI_API void setInput(const std::string &text) override
Set the input text in the input field.