chore(color): Cleanup and optimise EdgeTxTheme class (#4013)

This commit is contained in:
philmoz
2023-09-21 19:39:05 +10:00
committed by GitHub
parent 4d148e5c0c
commit 0aff002c8a
35 changed files with 309 additions and 677 deletions
@@ -132,23 +132,6 @@ bool RadioLayout::CustomScreenData::isEmpty() const
return strlen(layoutId) == 0;
}
void RadioTheme::init(const char* themeName, ThemeData& themeData)
{
memset(&themeData, 0, sizeof(ThemeData));
memcpy(&themeData.themeName, themeName, THEME_NAME_LEN);
PersistentData& persistentData = themeData.themePersistentData;
persistentData.options[0].type =
zoneValueEnumFromType(ZoneOption::Type::Color);
setZoneOptionValue(persistentData.options[0].value, (unsigned int)WHITE);
persistentData.options[1].type =
zoneValueEnumFromType(ZoneOption::Type::Color);
setZoneOptionValue(persistentData.options[1].value, (unsigned int)RED);
}
void RadioLayout::init(const char* layoutId, CustomScreens& customScreens)
{
memset(&customScreens, 0, sizeof(CustomScreens));
@@ -31,7 +31,6 @@
*/
constexpr int MAX_CUSTOM_SCREENS {10};
constexpr int THEME_NAME_LEN {8};
constexpr int MAX_THEME_OPTIONS {5};
constexpr int LEN_ZONE_OPTION_STRING {8};
constexpr int MAX_LAYOUT_ZONES {10};
@@ -146,23 +145,6 @@ typedef WidgetsContainerPersistentData<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
typedef WidgetsContainerPersistentData<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS>
TopBarPersistentData;
class RadioTheme
{
Q_DECLARE_TR_FUNCTIONS(RadioTheme)
public:
struct PersistentData {
ZoneOptionValueTyped options[MAX_THEME_OPTIONS];
};
struct ThemeData {
char themeName[THEME_NAME_LEN + 1];
PersistentData themePersistentData;
};
static void init(const char * themeName, ThemeData & themeData);
};
class RadioLayout
{
Q_DECLARE_TR_FUNCTIONS(RadioLayout)
@@ -299,9 +299,6 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
node["potsConfig"] = potsConfig;
}
// Color lcd theme settings are not used in EdgeTx
// RadioTheme::ThemeData themeData;
node["ownerRegistrationID"] = rhs.registrationId;
// Gyro (for now only xlites)
@@ -573,9 +570,6 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
}
}
// Color lcd theme settings are not used in EdgeTx
// RadioTheme::ThemeData themeData;
node["ownerRegistrationID"] >> rhs.registrationId;
// Gyro (for now only xlites)
@@ -277,8 +277,6 @@ class GeneralSettings {
char sliderName[CPN_MAX_SLIDERS][HARDWARE_NAME_LEN + 1];
unsigned int sliderConfig[CPN_MAX_SLIDERS];
RadioTheme::ThemeData themeData;
char registrationId[REGISTRATION_ID_LEN + 1];
int gyroMax;
int gyroOffset;
@@ -3304,15 +3304,6 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type
internalField.Append(new ZCharField<10>(this, generalData.bluetoothName, "Bluetooth name"));
}
if (IS_FAMILY_HORUS_OR_T16(board)) {
if (version >= 220) { // data from earlier versions cannot be converted so fields initialised in afterImport
internalField.Append(new CharField<8>(this, generalData.themeData.themeName, true, "Theme name"));
for (int i = 0; i < MAX_THEME_OPTIONS; i++) {
internalField.Append(new ZoneOptionValueTypedField(this, generalData.themeData.themePersistentData.options[i], board, version));
}
}
}
if (version >= 220) {
internalField.Append(new CharField<8>(this, generalData.registrationId, "ACCESS Registration ID"));
}
@@ -3357,13 +3348,6 @@ void OpenTxGeneralData::beforeExport()
void OpenTxGeneralData::afterImport()
{
if (IS_FAMILY_HORUS_OR_T16(board)) {
if (version < 220) { // re-initialise as no conversion possible
const char * themeName = IS_FLYSKY_NV14(board) ? "FlySky" : "EdgeTX";
RadioTheme::init(themeName, generalData.themeData);
}
}
if (Boards::getCapability((Board::Type)generalData.variant,
Board::SportMaxBaudRate) >= 400000)
generalData.internalModuleBaudrate =
@@ -39,8 +39,6 @@
UserInterfacePanel::UserInterfacePanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
ModelPanel(parent, model, generalSettings, firmware)
{
RadioTheme::ThemeData & td = generalSettings.themeData;
QString sdPath = QString(g.profile[g.id()].sdPath()).trimmed();
grid = new QGridLayout(this);
@@ -191,11 +189,6 @@ UserInterfacePanel::UserInterfacePanel(QWidget * parent, ModelData & model, Gene
col = 0;
if (SHOW_RAW_INFO) {
addGridLabel(grid, tr("Theme"), row, col++);
grid->addLayout(addOptionsLayout<RadioTheme::PersistentData>(td.themePersistentData, MAX_THEME_OPTIONS), row, col);
}
// the grid must be fully built for the rowspan to work as required
foreach (QWidget * wgt, optswidgets) {
grid->addWidget(wgt, widgetdetailsrow, widgetdetailscol, 3, Qt::AlignTop);