WSF
PlatformDataTreeWidgetItem.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2016 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11#ifndef PLATFORMDATATREEWIDGETITEM_HPP
12#define PLATFORMDATATREEWIDGETITEM_HPP
13
14#include "UtUnitTypes.hpp"
15#include "WkfUnitTypes.hpp"
16
17namespace wizard
18{
19template<class T>
20class ValidatedUnitTreeWidgetItem : public wkf::UnitTreeWidgetItemT<T>
21{
22public:
23 ValidatedUnitTreeWidgetItem(QTreeWidgetItem* aParent, const QString& aLabelName)
24 : wkf::UnitTreeWidgetItemT<T>(aParent, aLabelName)
25 {
26 }
27
28 void setData(int column, int role, const QVariant& value) override
29 {
30 QStringList tokenList = value.toString().split(" ");
31 if (tokenList.size() == 0)
32 {
33 return;
34 }
35
36 // Latitude and Longitude validity are checked elsewhere
37 if (std::is_same<wkf::Latitude, T>::value || std::is_same<wkf::Longitude, T>::value)
38 {
39 QTreeWidgetItem::setData(column, role, value);
40 return;
41 }
42
43 std::map<std::string, int> unitStrings;
44 if (std::is_same<wkf::Acceleration, T>::value)
45 {
46 unitStrings = UtUnitAcceleration::mUnitStrings;
47 }
48 else if (std::is_same<wkf::Altitude, T>::value)
49 {
50 unitStrings = UtUnitLength::mUnitStrings;
51 }
52 else if (std::is_same<wkf::Angle, T>::value)
53 {
54 unitStrings = UtUnitAngle::mUnitStrings;
55 }
56 else if (std::is_same<wkf::AngularRate, T>::value)
57 {
58 unitStrings = UtUnitAngularRate::mUnitStrings;
59 }
60 else if (std::is_same<wkf::AngularAcceleration, T>::value)
61 {
62 unitStrings = UtUnitAngularAcceleration::mUnitStrings;
63 }
64 else if (std::is_same<wkf::Force, T>::value)
65 {
66 unitStrings = UtUnitForce::mUnitStrings;
67 }
68 else if (std::is_same<wkf::Frequency, T>::value)
69 {
70 unitStrings = UtUnitFrequency::mUnitStrings;
71 }
72 else if (std::is_same<wkf::Length, T>::value)
73 {
74 unitStrings = UtUnitLength::mUnitStrings;
75 }
76 else if (std::is_same<wkf::Mass, T>::value)
77 {
78 unitStrings = UtUnitMass::mUnitStrings;
79 }
80 else if (std::is_same<wkf::MassTransfer, T>::value)
81 {
82 unitStrings = UtUnitMassTransfer::mUnitStrings;
83 }
84 else if (std::is_same<wkf::Power, T>::value)
85 {
86 unitStrings = UtUnitPower::mUnitStrings;
87 }
88 else if (std::is_same<wkf::PowerDB, T>::value)
89 {
90 unitStrings = UtUnitPowerDB::mUnitStrings;
91 }
92 else if (std::is_same<wkf::Pressure, T>::value)
93 {
94 unitStrings = UtUnitPressure::mUnitStrings;
95 }
96 else if (std::is_same<wkf::Ratio, T>::value)
97 {
98 unitStrings = UtUnitRatio::mUnitStrings;
99 }
100 else if (std::is_same<wkf::Speed, T>::value)
101 {
102 unitStrings = UtUnitSpeed::mUnitStrings;
103 }
104 else if (std::is_same<wkf::Time, T>::value)
105 {
106 unitStrings = UtUnitTime::mUnitStrings;
107 }
108 else if (std::is_same<wkf::Torque, T>::value)
109 {
110 unitStrings = UtUnitTorque::mUnitStrings;
111 }
112 else
113 {
114 return;
115 }
116
117 bool isDouble = false;
118 tokenList[0].toDouble(&isDouble);
119 if (isDouble)
120 {
121 // If second token is a valid unit, use it
122 if (tokenList.size() >= 2 && unitStrings.count(tokenList[1].toStdString()) != 0)
123 {
124 QTreeWidgetItem::setData(column, role, value);
125 }
126 // If no second token, or second token is invalid, use previous unit.
127 else
128 {
129 QStringList prevTokenList = wkf::UnitTreeWidgetItemT<T>::text(column).split(" ");
130 if (prevTokenList.size() >= 2)
131 {
132 QTreeWidgetItem::setData(column, role, QVariant(tokenList[0] + " " + prevTokenList[1]));
133 }
134 }
135 }
136 }
137
138 void SetUnitText(const QString& aText) override
139 {
140 mUnitChanged = true;
141 setData(1, 0, QVariant(aText));
142 mUnitChanged = false;
143 }
144
145 bool GetUnitChanged() const { return mUnitChanged; }
146
147private:
148 // True if last setData call was through SetUnitText
149 bool mUnitChanged = false;
150};
151
152// SPECIALIZED TREEWIDGETITEMs
155} // namespace wizard
156#endif // PLATFORMDATATREEWIDGETITEM_HPP
Definition PlatformDataTreeWidgetItem.hpp:21
ValidatedUnitTreeWidgetItem(QTreeWidgetItem *aParent, const QString &aLabelName)
Definition PlatformDataTreeWidgetItem.hpp:23
void SetUnitText(const QString &aText) override
Definition PlatformDataTreeWidgetItem.hpp:138
void setData(int column, int role, const QVariant &value) override
Definition PlatformDataTreeWidgetItem.hpp:28
bool GetUnitChanged() const
Definition PlatformDataTreeWidgetItem.hpp:145
Definition Runner.hpp:22
ValidatedUnitTreeWidgetItem< wkf::Angle > ValidatedAngleTreeWidgetItem
Definition PlatformDataTreeWidgetItem.hpp:154
ValidatedUnitTreeWidgetItem< wkf::Altitude > ValidatedAltitudeTreeWidgetItem
Definition PlatformDataTreeWidgetItem.hpp:153
Definition ActionManager.hpp:28
Copyrights Multiple, All Rights Reserved