OpenStructure
Loading...
Searching...
No Matches
tool_option.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// This file is part of the OpenStructure project <www.openstructure.org>
3//
4// Copyright (C) 2008-2020 by the OpenStructure authors
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License as published by the Free
8// Software Foundation; either version 3.0 of the License, or (at your option)
9// any later version.
10// This library is distributed in the hope that it will be useful, but WITHOUT
11// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13// details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with this library; if not, write to the Free Software Foundation, Inc.,
17// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18//------------------------------------------------------------------------------
19#ifndef OST_GUI_TOOL_OPTION_HH
20#define OST_GUI_TOOL_OPTION_HH
21
22/*
23 Author: Marco Biasini
24 */
25
26#include <limits>
27#include <vector>
28#include <iostream>
29
30
32#include <QObject>
33
34
35namespace ost { namespace gui {
36
37class DLLEXPORT_OST_GUI ToolOption : public QObject {
38 Q_OBJECT
39public:
40 typedef enum {
41 INT, FLOAT, ENUM, BUTTON
42 } Type;
43protected:
44 ToolOption(const String& key, const String& verbose_name, Type type);
45public:
46 const String& GetKey() const;
47 const String& GetVerboseName() const;
48 Type GetType() const;
49private:
50 String key_;
51 String verbose_name_;
52 Type type_;
53};
54
55
56
57
58template <typename T, ToolOption::Type C>
59class DLLEXPORT ToolOptionNum : public ToolOption {
60public:
61 ToolOptionNum(const String& key, const String& verbose_name, T default_v,
62 T min_value=std::numeric_limits<T>::min(),
63 T max_value=std::numeric_limits<T>::max()):
64 ToolOption(key, verbose_name, C), value_(default_v),
65 default_(default_v), min_value_(min_value), max_value_(max_value)
66 {
67
68 }
69
70 T GetDefault() const { return default_; }
71 T GetUpperLimit() const { return max_value_; }
72 T GetLowerLimit() const { return min_value_; }
73 T GetValue() const { return value_; }
74 bool SetValue(T value)
75 {
76 if (value>=min_value_ && value<=max_value_) {
77 value_=value;
78 return true;
79 }
80 return false;
81 }
82private:
83 T value_;
84 T default_;
85 T min_value_;
86 T max_value_;
87};
88
91
92
93#if !defined(_MSC_VER)
94 extern template class ToolOptionNum<int,ToolOption::INT>;
95 extern template class ToolOptionNum<float,ToolOption::FLOAT>;
96#endif
97
98
99
101public:
102 struct Tuple {
104 int tag;
105 };
106 typedef std::vector<Tuple>::const_iterator ConstIterator;
107public:
108 ToolOptionEnum(const String& key, const String& verbose_name);
109
110 void Add(const String& text, int tag);
111
112 void SetIndex(int index) { index_=index; }
113
114 int GetIndex() const { return index_; }
115 int GetValue() const { return tuples_[index_].tag; }
116
117 ConstIterator Begin() const { return tuples_.begin(); }
118 ConstIterator End() const { return tuples_.end(); }
119 size_t Size() { return tuples_.size(); }
120
121private:
122 std::vector<Tuple> tuples_;
123 int index_;
124};
125
127public:
129 const String& verbose_name,
130 QObject* receiver,
131 const char *slot_method);
132 const char* GetSlotMethod() const { return slot_method_; }
133 QObject* GetReceiver() const { return receiver_; }
134private:
135 const char *slot_method_;
136 QObject* receiver_;
137};
138
139
140typedef std::vector<ToolOption*> ToolOptionList;
141
142}}
143
144#endif
ToolOptionButton(const String &key, const String &verbose_name, QObject *receiver, const char *slot_method)
const char * GetSlotMethod() const
QObject * GetReceiver() const
ConstIterator Begin() const
void Add(const String &text, int tag)
ToolOptionEnum(const String &key, const String &verbose_name)
std::vector< Tuple >::const_iterator ConstIterator
void SetIndex(int index)
ConstIterator End() const
const String & GetKey() const
Type GetType() const
const String & GetVerboseName() const
ToolOption(const String &key, const String &verbose_name, Type type)
ToolOptionNum(const String &key, const String &verbose_name, T default_v, T min_value=std::numeric_limits< T >::min(), T max_value=std::numeric_limits< T >::max())
#define DLLEXPORT_OST_GUI
std::string String
Definition base.hh:54
ToolOptionNum< int, ToolOption::INT > ToolOptionInt
std::vector< ToolOption * > ToolOptionList
ToolOptionNum< float, ToolOption::FLOAT > ToolOptionFloat
Definition base.dox:1