MEPP2 Project
SimpleLineEdit.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published
6 // by the Free Software Foundation; either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 #include <QLineEdit>
14 #include <functional>
15 
16 #ifndef Q_MOC_RUN // MT : very important to avoid the error : ' Parse error at
17  // "BOOST_JOIN" ' -> (qt4 pb with boost)
19 #endif
20 
21 namespace FEVV {
22 class SimpleLineEdit : public QLineEdit
23 {
24  Q_OBJECT
25 public:
26  std::string myPluginName;
28 
29  std::string *myStringValue = nullptr;
30  int *myIntValue = nullptr;
31  double *myDoubleValue = nullptr;
32  float *myFloatValue = nullptr;
33 
34  SimpleLineEdit(QWidget *parent = 0) : QLineEdit(parent) {}
35 
36  void
37  setParams(std::string *_value, std::string _pluginName, BasePlugin *_plugin)
38  {
39  this->myPluginName = _pluginName;
40  this->myPlugin = _plugin;
41  this->myStringValue = _value;
42  }
43  void setParams(int *_value, std::string _pluginName, BasePlugin *_plugin)
44  {
45  this->myPluginName = _pluginName;
46  this->myPlugin = _plugin;
47  this->myIntValue = _value;
48  }
49  void setParams(double *_value, std::string _pluginName, BasePlugin *_plugin)
50  {
51  this->myPluginName = _pluginName;
52  this->myPlugin = _plugin;
53  this->myDoubleValue = _value;
54  }
55  void setParams(float *_value, std::string _pluginName, BasePlugin *_plugin)
56  {
57  this->myPluginName = _pluginName;
58  this->myPlugin = _plugin;
59  this->myFloatValue = _value;
60  }
61 private slots:
63  {
64  emit modificationSignal(this->myPluginName, this->myPlugin);
65  if(myStringValue)
66  {
67  *myStringValue = text().toStdString();
68  }
69  else if(myIntValue)
70  {
71  *myIntValue = text().toInt();
72  }
73  else if(myDoubleValue)
74  {
75  *myDoubleValue = text().toDouble();
76  }
77  else if(myFloatValue)
78  {
79  *myFloatValue = text().toFloat();
80  }
81  }
82  void resetSlot()
83  {
84  // std::cout << "resetSlot SimpleLineEdit: ";
85 
86  if(myStringValue)
87  {
88  setText(QString::fromUtf8((*myStringValue).c_str()));
89 
90  // std::cout << *myStringValue << std::endl;
91  }
92  else if(myIntValue)
93  {
94  setText(QString::fromUtf8(std::to_string(*myIntValue).c_str()));
95 
96  // std::cout << *myIntValue << std::endl;
97  }
98  else if(myDoubleValue)
99  {
100  setText(QString::fromUtf8(std::to_string(*myDoubleValue).c_str()));
101 
102  // std::cout << *myDoubleValue << std::endl;
103  }
104  else if(myFloatValue)
105  {
106  setText(QString::fromUtf8(std::to_string(*myFloatValue).c_str()));
107 
108  // std::cout << *myFloatValue << std::endl;
109  }
110  }
111 signals:
112  void modificationSignal(std::string, BasePlugin *);
113 };
114 
115 } // namespace FEVV
FEVV::SimpleLineEdit::myPlugin
BasePlugin * myPlugin
Definition: SimpleLineEdit.h:27
FEVV::SimpleLineEdit::setParams
void setParams(float *_value, std::string _pluginName, BasePlugin *_plugin)
Definition: SimpleLineEdit.h:55
FEVV::SimpleLineEdit::setParams
void setParams(double *_value, std::string _pluginName, BasePlugin *_plugin)
Definition: SimpleLineEdit.h:49
FEVV::SimpleLineEdit::myFloatValue
float * myFloatValue
Definition: SimpleLineEdit.h:32
BasePlugin.h
FEVV::SimpleLineEdit::setParams
void setParams(int *_value, std::string _pluginName, BasePlugin *_plugin)
Definition: SimpleLineEdit.h:43
FEVV::SimpleLineEdit::modificationSignal
void modificationSignal(std::string, BasePlugin *)
FEVV::SimpleLineEdit::myPluginName
std::string myPluginName
Definition: SimpleLineEdit.h:26
FEVV::SimpleLineEdit
Definition: SimpleLineEdit.h:23
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::SimpleLineEdit::setParams
void setParams(std::string *_value, std::string _pluginName, BasePlugin *_plugin)
Definition: SimpleLineEdit.h:37
FEVV::SimpleLineEdit::modificationSlot
void modificationSlot()
Definition: SimpleLineEdit.h:62
FEVV::SimpleLineEdit::myDoubleValue
double * myDoubleValue
Definition: SimpleLineEdit.h:31
FEVV::SimpleLineEdit::myIntValue
int * myIntValue
Definition: SimpleLineEdit.h:30
FEVV::SimpleLineEdit::myStringValue
std::string * myStringValue
Definition: SimpleLineEdit.h:29
FEVV::SimpleLineEdit::resetSlot
void resetSlot()
Definition: SimpleLineEdit.h:82
FEVV::BasePlugin
Definition: BasePlugin.h:38
FEVV::SimpleLineEdit::SimpleLineEdit
SimpleLineEdit(QWidget *parent=0)
Definition: SimpleLineEdit.h:34