IntEnumWidget.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <string>
5#include <utility>
6
7#include <QComboBox>
8
11
13#include "CustomWidget.h"
14
15namespace armarx::skills::gui
16{
17 // Custom wrapper around the QComboBox widget to represent IntEnums
18 // This class handles parsing once the user edited the field and is also responsible
19 // to parse the according aron data from text
21 {
22 Q_OBJECT
23 public:
24 IntEnumWidget(const aron::type::IntEnumPtr&, QTreeWidgetItem* currentItem);
25 // needs to be called after the constructor, because qt needs the meta object to be fully constructed at this point
27
28 static IntEnumWidget* DynamicCast(QWidget*);
29 static IntEnumWidget* DynamicCastAndCheck(QWidget*);
30
31 bool hasParseErrors();
32 void setText(const QString& text);
33 QString getText();
34 std::pair<bool, aron::data::IntPtr> parseToAron();
35
36 private:
37 // display format for an enum entry, e.g. "TopGrasp (2)".
38 // only affects what is shown in the GUI; parseToAron() resolves it back
39 // to the plain int value that is sent for the skill execution.
40 static std::string toDisplayText(const std::string& name, int value);
41 // resolves user-facing text (display format, plain name, or plain number)
42 // to the according enum entry
43 std::optional<std::pair<std::string, int>> resolveText(const std::string& text) const;
44
45 const aron::type::IntEnumPtr element_type;
46 QComboBox* innerWidget;
47
48 bool noParseErrors = true;
49
50 void highlightUnparsableEntries();
51 private slots:
52 void textChanged(const QString&);
53 };
54} // namespace armarx::skills::gui
CustomWidget(QTreeWidgetItem *overlayingItem)
void setText(const QString &text)
IntEnumWidget(const aron::type::IntEnumPtr &, QTreeWidgetItem *currentItem)
static IntEnumWidget * DynamicCastAndCheck(QWidget *)
std::pair< bool, aron::data::IntPtr > parseToAron()
static IntEnumWidget * DynamicCast(QWidget *)
std::shared_ptr< IntEnum > IntEnumPtr
Definition IntEnum.h:36