fix(cpn): crash when creating a new model on Windows (#6869)
This commit is contained in:
@@ -29,22 +29,23 @@
|
|||||||
|
|
||||||
ZoneOptionValue::ZoneOptionValue()
|
ZoneOptionValue::ZoneOptionValue()
|
||||||
{
|
{
|
||||||
memset((void*)this, 0, sizeof(ZoneOptionValue));
|
unsignedValue = 0;
|
||||||
|
signedValue = 0;
|
||||||
|
boolValue = 0;
|
||||||
|
stringValue.clear();
|
||||||
|
sourceValue.clear();
|
||||||
|
colorValue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ZoneOptionValue::isEmpty() const
|
||||||
|
{
|
||||||
|
return unsignedValue == 0 && signedValue == 0 && boolValue == 0 && colorValue == 0 &&
|
||||||
|
stringValue.empty() && sourceValue.toValue() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoneOptionValueTyped::ZoneOptionValueTyped()
|
ZoneOptionValueTyped::ZoneOptionValueTyped()
|
||||||
{
|
{
|
||||||
memset((void*)this, 0, sizeof(ZoneOptionValueTyped));
|
type = ZOV_Unsigned;
|
||||||
}
|
|
||||||
|
|
||||||
WidgetPersistentData::WidgetPersistentData()
|
|
||||||
{
|
|
||||||
memset((void*)this, 0, sizeof(WidgetPersistentData));
|
|
||||||
}
|
|
||||||
|
|
||||||
ZonePersistentData::ZonePersistentData()
|
|
||||||
{
|
|
||||||
memset((void*)this, 0, sizeof(ZonePersistentData));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setZoneOptionValue(ZoneOptionValue& zov, bool value)
|
inline void setZoneOptionValue(ZoneOptionValue& zov, bool value)
|
||||||
@@ -57,9 +58,9 @@ inline void setZoneOptionValue(ZoneOptionValue& zov, int value)
|
|||||||
zov.signedValue = value;
|
zov.signedValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setZoneOptionValue(ZoneOptionValue& zov, char value)
|
inline void setZoneOptionValue(ZoneOptionValue& zov, const char* value)
|
||||||
{
|
{
|
||||||
memset(&zov.stringValue, value, LEN_ZONE_OPTION_STRING);
|
zov.stringValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setZoneOptionValue(ZoneOptionValue& zov, unsigned int value)
|
inline void setZoneOptionValue(ZoneOptionValue& zov, unsigned int value)
|
||||||
@@ -110,22 +111,17 @@ static const ZoneOptionValueTyped zero_widget_option = {};
|
|||||||
|
|
||||||
bool ZoneOptionValueTyped::isEmpty() const
|
bool ZoneOptionValueTyped::isEmpty() const
|
||||||
{
|
{
|
||||||
return !memcmp((void*)this, &zero_widget_option, sizeof(zero_widget_option));
|
return type == ZOV_Unsigned && value.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZonePersistentData::isEmpty() const
|
bool ZonePersistentData::isEmpty() const
|
||||||
{
|
{
|
||||||
return strlen(widgetName) == 0;
|
return widgetName.empty();
|
||||||
}
|
|
||||||
|
|
||||||
RadioLayout::CustomScreenData::CustomScreenData()
|
|
||||||
{
|
|
||||||
memset((void*)this, 0, sizeof(RadioLayout::CustomScreenData));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RadioLayout::CustomScreenData::isEmpty() const
|
bool RadioLayout::CustomScreenData::isEmpty() const
|
||||||
{
|
{
|
||||||
return strlen(layoutId) == 0;
|
return layoutId.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioLayout::CustomScreens::clear()
|
void RadioLayout::CustomScreens::clear()
|
||||||
@@ -141,7 +137,7 @@ void RadioLayout::init(const char* layoutId, CustomScreens& customScreens)
|
|||||||
|
|
||||||
for (int i = 0; i < MAX_CUSTOM_SCREENS; i++) {
|
for (int i = 0; i < MAX_CUSTOM_SCREENS; i++) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
strncpy(customScreens.customScreenData[i].layoutId, layoutId, LAYOUT_ID_LEN);
|
customScreens.customScreenData[i].layoutId = layoutId;
|
||||||
|
|
||||||
LayoutPersistentData& persistentData =
|
LayoutPersistentData& persistentData =
|
||||||
customScreens.customScreenData[i].layoutPersistentData;
|
customScreens.customScreenData[i].layoutPersistentData;
|
||||||
|
|||||||
@@ -33,14 +33,11 @@
|
|||||||
|
|
||||||
constexpr int MAX_CUSTOM_SCREENS {10};
|
constexpr int MAX_CUSTOM_SCREENS {10};
|
||||||
constexpr int MAX_THEME_OPTIONS {5};
|
constexpr int MAX_THEME_OPTIONS {5};
|
||||||
constexpr int LEN_ZONE_OPTION_STRING {255}; // TODO: use std::string instead of fixed length char array
|
|
||||||
constexpr int MAX_LAYOUT_ZONES {10};
|
constexpr int MAX_LAYOUT_ZONES {10};
|
||||||
constexpr int MAX_LAYOUT_OPTIONS {10};
|
constexpr int MAX_LAYOUT_OPTIONS {10};
|
||||||
constexpr int WIDGET_NAME_LEN {255}; // TODO: use std::string instead of fixed length char array
|
|
||||||
constexpr int MAX_WIDGET_OPTIONS {50};
|
constexpr int MAX_WIDGET_OPTIONS {50};
|
||||||
constexpr int MAX_TOPBAR_ZONES {7}; // 4 for portrait LCD, 6 for standard LCD, 7 for wide screen LCD
|
constexpr int MAX_TOPBAR_ZONES {7}; // 4 for portrait LCD, 6 for standard LCD, 7 for wide screen LCD
|
||||||
constexpr int MAX_TOPBAR_OPTIONS {1};
|
constexpr int MAX_TOPBAR_OPTIONS {1};
|
||||||
constexpr int LAYOUT_ID_LEN {255}; // TODO: use std::string instead of fixed length char array
|
|
||||||
|
|
||||||
// Common 'ZoneOptionValue's among all layouts
|
// Common 'ZoneOptionValue's among all layouts
|
||||||
enum {
|
enum {
|
||||||
@@ -58,11 +55,12 @@ struct ZoneOptionValue // union in radio/src/datastructs.h
|
|||||||
unsigned int unsignedValue;
|
unsigned int unsignedValue;
|
||||||
int signedValue;
|
int signedValue;
|
||||||
unsigned int boolValue;
|
unsigned int boolValue;
|
||||||
char stringValue[LEN_ZONE_OPTION_STRING + 1];
|
std::string stringValue;
|
||||||
RawSource sourceValue;
|
RawSource sourceValue;
|
||||||
unsigned int colorValue;
|
unsigned int colorValue;
|
||||||
|
|
||||||
ZoneOptionValue();
|
ZoneOptionValue();
|
||||||
|
bool isEmpty() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ZoneOptionValueEnum {
|
enum ZoneOptionValueEnum {
|
||||||
@@ -119,14 +117,14 @@ struct ZoneOptionValueTyped
|
|||||||
struct WidgetPersistentData {
|
struct WidgetPersistentData {
|
||||||
ZoneOptionValueTyped options[MAX_WIDGET_OPTIONS];
|
ZoneOptionValueTyped options[MAX_WIDGET_OPTIONS];
|
||||||
|
|
||||||
WidgetPersistentData();
|
WidgetPersistentData() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ZonePersistentData {
|
struct ZonePersistentData {
|
||||||
char widgetName[WIDGET_NAME_LEN + 1];
|
std::string widgetName;
|
||||||
WidgetPersistentData widgetData;
|
WidgetPersistentData widgetData;
|
||||||
|
|
||||||
ZonePersistentData();
|
ZonePersistentData() {}
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -135,9 +133,7 @@ struct WidgetsContainerPersistentData {
|
|||||||
ZonePersistentData zones[N];
|
ZonePersistentData zones[N];
|
||||||
ZoneOptionValueTyped options[O];
|
ZoneOptionValueTyped options[O];
|
||||||
|
|
||||||
WidgetsContainerPersistentData() {
|
WidgetsContainerPersistentData() {}
|
||||||
memset((void*)this, 0, sizeof(WidgetsContainerPersistentData));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef WidgetsContainerPersistentData<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
|
typedef WidgetsContainerPersistentData<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
|
||||||
@@ -152,10 +148,10 @@ class RadioLayout
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
struct CustomScreenData {
|
struct CustomScreenData {
|
||||||
char layoutId[LAYOUT_ID_LEN + 1];
|
std::string layoutId;
|
||||||
LayoutPersistentData layoutPersistentData;
|
LayoutPersistentData layoutPersistentData;
|
||||||
|
|
||||||
CustomScreenData();
|
CustomScreenData() {}
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ struct convert<WidgetsContainerPersistentData<N,O> > {
|
|||||||
{
|
{
|
||||||
Node node;
|
Node node;
|
||||||
for (int i=0; i<N; i++) {
|
for (int i=0; i<N; i++) {
|
||||||
if (strlen(rhs.zones[i].widgetName) > 0) {
|
if (!rhs.zones[i].widgetName.empty()) {
|
||||||
node["zones"][std::to_string(i)] = rhs.zones[i];
|
node["zones"][std::to_string(i)] = rhs.zones[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ UserInterfacePanel::UserInterfacePanel(QWidget * parent, ModelData & model, Gene
|
|||||||
|
|
||||||
for (int i = 0; i < firmware->getCapability(TopBarZones); i++) {
|
for (int i = 0; i < firmware->getCapability(TopBarZones); i++) {
|
||||||
ZonePersistentData & zpd = model.topBarData.zones[i];
|
ZonePersistentData & zpd = model.topBarData.zones[i];
|
||||||
QPushButton * btn = new QPushButton(zpd.widgetName, this);
|
QPushButton * btn = new QPushButton(zpd.widgetName.c_str(), this);
|
||||||
btn->setProperty("index", i);
|
btn->setProperty("index", i);
|
||||||
btn->setFixedSize(QSize(180, 50));
|
btn->setFixedSize(QSize(180, 50));
|
||||||
widgetbtns.append(btn);
|
widgetbtns.append(btn);
|
||||||
@@ -165,7 +165,7 @@ UserInterfacePanel::UserInterfacePanel(QWidget * parent, ModelData & model, Gene
|
|||||||
optswidgets.append(wgt);
|
optswidgets.append(wgt);
|
||||||
|
|
||||||
QGridLayout * layout = new QGridLayout(wgt); // must be owned by QWidget so visibility can be set
|
QGridLayout * layout = new QGridLayout(wgt); // must be owned by QWidget so visibility can be set
|
||||||
layout->addLayout(addOptionsLayout<WidgetPersistentData>(zpd.widgetData, MAX_WIDGET_OPTIONS, zpd.widgetName), 0, 0);
|
layout->addLayout(addOptionsLayout<WidgetPersistentData>(zpd.widgetData, MAX_WIDGET_OPTIONS, zpd.widgetName.c_str()), 0, 0);
|
||||||
optsgrids.append(layout);
|
optsgrids.append(layout);
|
||||||
|
|
||||||
connect(btn, &QPushButton::clicked, this, [&]() {
|
connect(btn, &QPushButton::clicked, this, [&]() {
|
||||||
@@ -239,7 +239,7 @@ CustomScreenPanel::CustomScreenPanel(QWidget * parent, ModelData & model, int in
|
|||||||
addGridLabel(grid, tr("Layout:"), row, col++);
|
addGridLabel(grid, tr("Layout:"), row, col++);
|
||||||
|
|
||||||
// currently no point continuing if no layout but will change if editing becomes possible
|
// currently no point continuing if no layout but will change if editing becomes possible
|
||||||
if (model.customScreens.customScreenData[index].layoutId[0] == '\0') {
|
if (model.customScreens.customScreenData[index].layoutId.empty()) {
|
||||||
addGridLabel(grid, tr("None"), row, col);
|
addGridLabel(grid, tr("None"), row, col);
|
||||||
addHSpring(grid, grid->columnCount(), 0);
|
addHSpring(grid, grid->columnCount(), 0);
|
||||||
addVSpring(grid, 0, grid->rowCount());
|
addVSpring(grid, 0, grid->rowCount());
|
||||||
@@ -248,7 +248,7 @@ CustomScreenPanel::CustomScreenPanel(QWidget * parent, ModelData & model, int in
|
|||||||
|
|
||||||
QLabel * img = new QLabel(this);
|
QLabel * img = new QLabel(this);
|
||||||
|
|
||||||
QString path(QString(":/layouts/mask_%1.png").arg(QString(scrns.customScreenData[index].layoutId).toLower()));
|
QString path(QString(":/layouts/mask_%1.png").arg(QString(scrns.customScreenData[index].layoutId.c_str()).toLower()));
|
||||||
QFile f(path);
|
QFile f(path);
|
||||||
|
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
@@ -278,7 +278,7 @@ CustomScreenPanel::CustomScreenPanel(QWidget * parent, ModelData & model, int in
|
|||||||
|
|
||||||
for (int i = 0; i < MAX_LAYOUT_ZONES; i++) {
|
for (int i = 0; i < MAX_LAYOUT_ZONES; i++) {
|
||||||
ZonePersistentData & zpd = lpd.zones[i];
|
ZonePersistentData & zpd = lpd.zones[i];
|
||||||
QPushButton * btn = new QPushButton(zpd.widgetName, this);
|
QPushButton * btn = new QPushButton(zpd.widgetName.c_str(), this);
|
||||||
btn->setProperty("index", i);
|
btn->setProperty("index", i);
|
||||||
btn->setFixedSize(QSize(180, 50));
|
btn->setFixedSize(QSize(180, 50));
|
||||||
widgetbtns.append(btn);
|
widgetbtns.append(btn);
|
||||||
@@ -294,7 +294,7 @@ CustomScreenPanel::CustomScreenPanel(QWidget * parent, ModelData & model, int in
|
|||||||
optswidgets.append(wgt);
|
optswidgets.append(wgt);
|
||||||
|
|
||||||
QGridLayout * layout = new QGridLayout(wgt); // must be owned by QWidget so visibility can be set
|
QGridLayout * layout = new QGridLayout(wgt); // must be owned by QWidget so visibility can be set
|
||||||
layout->addLayout(addOptionsLayout<WidgetPersistentData>(zpd.widgetData, MAX_WIDGET_OPTIONS, zpd.widgetName), 0, 0, Qt::AlignTop);
|
layout->addLayout(addOptionsLayout<WidgetPersistentData>(zpd.widgetData, MAX_WIDGET_OPTIONS, zpd.widgetName.c_str()), 0, 0, Qt::AlignTop);
|
||||||
optsgrids.append(layout);
|
optsgrids.append(layout);
|
||||||
|
|
||||||
connect(btn, &QPushButton::clicked, this, [&]() {
|
connect(btn, &QPushButton::clicked, this, [&]() {
|
||||||
@@ -369,7 +369,7 @@ CustomScreenPanel::CustomScreenPanel(QWidget * parent, ModelData & model, int in
|
|||||||
break;
|
break;
|
||||||
case ZOV_String:
|
case ZOV_String:
|
||||||
lbl = new QLabel(this);
|
lbl = new QLabel(this);
|
||||||
lbl->setText(lpd.options[i].value.stringValue);
|
lbl->setText(lpd.options[i].value.stringValue.c_str());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
lbl = new QLabel(this);
|
lbl = new QLabel(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user