SoDaRadio-5.0.3-master:8901fb5
soda_comboboxes.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2017 Matthew H. Reilly (kb1vc)
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef SODA_WFALL_COMBO_BOXES_H
30 #define SODA_WFALL_COMBO_BOXES_H
31 
32 #include <QWidget>
33 #include <QComboBox>
34 #include <QString>
35 #include <boost/format.hpp>
36 #include <vector>
37 #include <map>
38 #include <cmath>
39 #include <iostream>
40 
41 namespace GUISoDa {
42  class ValComboBox : public QComboBox {
43  Q_OBJECT
44  public:
45  explicit ValComboBox(QWidget * parent = 0) : QComboBox(parent) {
46 
47  clear();
48  connect(this, &QComboBox::currentTextChanged, this, &ValComboBox::textChanged);
49  }
50 
51  double value() {
52  return valmap[currentText()];
53  }
54 
55  public slots:
56  void addValue(QString lab, double val);
57  void setValue(double v);
58 
59  signals:
60  void valueChanged(double v);
61 
62  protected:
63  void textChanged(const QString & txt);
64 
65  std::map<QString, double> valmap;
66  };
67 
69  Q_OBJECT
70  public:
71  WFallDynRangeComboBox(QWidget * parent = 0) : ValComboBox(parent) {
72 
73  addValue("50", 50.0);
74  addValue("45", 45.0);
75  addValue("40", 40.0);
76  addValue("35", 35.0);
77  addValue("30", 30.0);
78  addValue("25", 25.0);
79  addValue("15", 15.0);
80  addValue("10", 10.0);
81  addValue("5", 5.0);
82  setValue(25.0);
83  }
84  };
85 
86  class WFallSpanComboBox : public ValComboBox {
87  Q_OBJECT
88  public:
89  WFallSpanComboBox(QWidget * parent = 0) : ValComboBox(parent) {
90  addValue("200", 200.0);
91  addValue("100", 100.0);
92  addValue("50", 50.0);
93  addValue("25", 25.0);
94  addValue("10", 10.0);
95  setValue(200.0);
96  }
97  };
98 
99 
100  class IntValComboBox : public QComboBox {
101  Q_OBJECT
102  public:
103  explicit IntValComboBox(QWidget * parent = 0) : QComboBox(parent) {
104 
105  clear();
106  connect(this, &QComboBox::currentTextChanged, this, &IntValComboBox::textChanged);
107  }
108 
109  int value() {
110  return valmap[currentText()];
111  }
112 
113  public slots:
114  void addValue(QString lab, int val);
115 
116  void setValue(int v);
117  void setValue(const QString & s);
118 
119  signals:
120  void valueChanged(int v);
121 
122  protected:
123  void textChanged(const QString & txt);
124 
125  std::map<QString, int> valmap;
126  };
127 }
128 
129 #endif
void textChanged(const QString &txt)
WFallDynRangeComboBox(QWidget *parent=0)
WFallSpanComboBox(QWidget *parent=0)
std::map< QString, double > valmap
IntValComboBox(QWidget *parent=0)
void textChanged(const QString &txt)
ValComboBox(QWidget *parent=0)
void setValue(double v)
void valueChanged(double v)
void addValue(QString lab, double val)
std::map< QString, int > valmap