Skip to content

Commit

Permalink
cpn: refresh all model refs to LS when name changed. UI tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
elecpower authored and pfeerick committed Dec 7, 2022
1 parent a58c3a4 commit ce36ca6
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 74 deletions.
4 changes: 3 additions & 1 deletion companion/src/firmwares/customfunctiondata.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <QtCore>
#include <QComboBox>

#define CF_CUSTNAME_LEN 10

class Firmware;
class ModelData;
class GeneralSettings;
Expand Down Expand Up @@ -105,7 +107,7 @@ class CustomFunctionData {
unsigned int enabled; // TODO perhaps not any more the right name
unsigned int adjustMode;
int repeatParam;
char custName[10+1];
char custName[CF_CUSTNAME_LEN + 1];

void convert(RadioDataConversionState & cstate);

Expand Down
8 changes: 2 additions & 6 deletions companion/src/firmwares/logicalswitchdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

bool LogicalSwitchData::isEmpty() const
{
return (func == 0);
return (func == LS_FN_OFF);
}

CSFunctionFamily LogicalSwitchData::getFunctionFamily() const
Expand Down Expand Up @@ -115,11 +115,7 @@ QString LogicalSwitchData::funcToString() const

QString LogicalSwitchData::nameToString(int index) const
{
return RadioData::getElementName(tr("L"), index + 1, NULL, true);
}
QString LogicalSwitchData::custNameToString() const
{
return custName;
return RadioData::getElementName(tr("L"), index + 1, custName, true);
}

void LogicalSwitchData::convert(RadioDataConversionState & cstate)
Expand Down
14 changes: 6 additions & 8 deletions companion/src/firmwares/logicalswitchdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
* GNU General Public License for more details.
*/

#ifndef LOGICALSWITCHDATA_H
#define LOGICALSWITCHDATA_H
#pragma once

#include <QtCore>

#define LS_CUSTNAME_LEN 10

class RadioDataConversionState;

enum CSFunction {
Expand All @@ -49,8 +50,8 @@ enum CSFunction {
LS_FN_EDGE,
LS_FN_SAFE,
// later ... LS_FN_RANGE,
LS_FN_MAX,
LS_FN_MAX,

};

enum CSFunctionFamily {
Expand Down Expand Up @@ -79,16 +80,13 @@ class LogicalSwitchData {
unsigned int delay;
unsigned int duration;
int andsw;
char custName[10+1];
char custName[LS_CUSTNAME_LEN + 1];

void clear() { memset(this, 0, sizeof(LogicalSwitchData)); }
bool isEmpty() const;
CSFunctionFamily getFunctionFamily() const;
unsigned int getRangeFlags() const;
QString funcToString() const;
QString nameToString(int index) const;
QString custNameToString() const;
void convert(RadioDataConversionState & cstate);
};

#endif // LOGICALSWITCHDATA_H
2 changes: 1 addition & 1 deletion companion/src/firmwares/rawsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
return result;

case SOURCE_TYPE_CUSTOM_SWITCH:
return RawSwitch(SWITCH_TYPE_VIRTUAL, index + 1).toString();
return RawSwitch(SWITCH_TYPE_VIRTUAL, index + 1).toString(board, generalSettings, model);

case SOURCE_TYPE_CYC:
return tr("CYC%1").arg(index + 1);
Expand Down
4 changes: 2 additions & 2 deletions companion/src/firmwares/rawswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen

case SWITCH_TYPE_VIRTUAL:
if (modelData)
return modelData->logicalSw[index].nameToString(index-1) + ": " + modelData->logicalSw[index-1].custNameToString() ;
return modelData->logicalSw[index - 1].nameToString(index - 1);
else
return LogicalSwitchData().nameToString(index-1);
return LogicalSwitchData().nameToString(index - 1);

case SWITCH_TYPE_FUNCTIONSWITCH:
if (!Boards::getCapability(board, Board::FunctionSwitches))
Expand Down
50 changes: 17 additions & 33 deletions companion/src/modeledit/customfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
playIcon.addImage("stop.png", QIcon::Normal, QIcon::On);

QStringList headerLabels;
headerLabels << "#" << tr("Switch") << tr("Action") << tr("Parameters") << "" << "Name";
headerLabels << "#" << tr("Name") << tr("Switch") << tr("Action") << tr("Parameters") << "";
TableLayout * tableLayout = new TableLayout(this, fswCapability, headerLabels);

for (int i = 0; i < fswCapability; i++) {
Expand All @@ -116,16 +116,16 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
connect(label, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenuRequested(QPoint)));
tableLayout->addWidget(i, 0, label);


// The Custom Name
name[i] = new QLineEdit(this);
name[i]->setProperty("index", i);
name[i]->setMaxLength(10);
name[i]->setMaxLength(CF_CUSTNAME_LEN);
QRegExp rx(CHAR_FOR_NAMES_REGEX);
name[i]->setValidator(new QRegExpValidator(rx, this));
connect(name[i], SIGNAL(editingFinished()), this, SLOT(nameEdited()));
tableLayout->addWidget(i, 5, name[i]);
name[i]->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
connect(name[i], SIGNAL(editingFinished()), this, SLOT(onNameEdited()));
tableLayout->addWidget(i, 1, name[i]);

// The switch
fswtchSwtch[i] = new QComboBox(this);
Expand All @@ -136,8 +136,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
fswtchSwtch[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents);
fswtchSwtch[i]->setMaxVisibleItems(10);
connect(fswtchSwtch[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));
connect(fswtchSwtch[i], SIGNAL(LogicalSwitchesPanel::editingFinished()), this, SLOT(refreshSwitchComboBoxes()));
tableLayout->addWidget(i, 1, fswtchSwtch[i]);
tableLayout->addWidget(i, 2, fswtchSwtch[i]);

// The function
fswtchFunc[i] = new QComboBox(this);
Expand All @@ -146,11 +145,11 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(functions[i].func));
fswtchFunc[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents);
connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(functionEdited()));
tableLayout->addWidget(i, 2, fswtchFunc[i]);
tableLayout->addWidget(i, 3, fswtchFunc[i]);

// The parameters
QHBoxLayout * paramLayout = new QHBoxLayout();
tableLayout->addLayout(i, 3, paramLayout);
tableLayout->addLayout(i, 4, paramLayout);

fswtchGVmode[i] = new QComboBox(this);
fswtchGVmode[i]->setProperty("index", i);
Expand Down Expand Up @@ -201,11 +200,11 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
connect(playBT[i], &QToolButton::clicked, this, &CustomFunctionsPanel::toggleSound);

QHBoxLayout * repeatLayout = new QHBoxLayout();
tableLayout->addLayout(i, 4, repeatLayout);
tableLayout->addLayout(i, 5, repeatLayout);
fswtchRepeat[i] = new QComboBox(this);
fswtchRepeat[i]->setProperty("index", i);
fswtchRepeat[i]->setModel(tabModelFactory->getItemModel(repeatId));
fswtchRepeat[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
fswtchRepeat[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
fswtchRepeat[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents);
repeatLayout->addWidget(fswtchRepeat[i], i + 1);
connect(fswtchRepeat[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));
Expand All @@ -216,13 +215,11 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
fswtchEnable[i]->setFixedWidth(200);
repeatLayout->addWidget(fswtchEnable[i], i + 1);
connect(fswtchEnable[i], SIGNAL(stateChanged(int)), this, SLOT(customFunctionEdited()));


}

disableMouseScrolling();
tableLayout->resizeColumnsToContents();
tableLayout->setColumnWidth(3, 300);
tableLayout->setColumnWidth(5, 300);
tableLayout->pushRowsUp(fswCapability + 1);

update();
Expand All @@ -236,18 +233,6 @@ CustomFunctionsPanel::~CustomFunctionsPanel()
delete tabModelFactory;
delete tabFilterFactory;
}
void CustomFunctionsPanel::refreshSwitchComboBoxes()
{
// The switch
for (int i = 0; i < fswCapability; i++) {
fswtchSwtch[i]->setProperty("index", i);
fswtchSwtch[i]->setModel(tabFilterFactory->getItemModel(rawSwitchId));
fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(functions[i].swtch.toValue()));
fswtchSwtch[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
fswtchSwtch[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents);
fswtchSwtch[i]->setMaxVisibleItems(10);
}
}

void CustomFunctionsPanel::onMediaPlayerStateChanged(QMediaPlayer::State state)
{
Expand Down Expand Up @@ -347,27 +332,26 @@ void CustomFunctionsPanel::functionEdited()
int index = sender()->property("index").toInt();
RawSwitch swtch = functions[index].swtch;
int paramTemp =functions[index].param;

functions[index].clear();
functions[index].swtch = swtch;
functions[index].func = (AssignFunc)fswtchFunc[index]->currentData().toInt();
functions[index].param = paramTemp;
strcpy(functions[index].custName, name[index]->text().toLatin1());

refreshCustomFunction(index);
emit modified();
lock = false;
}
}

void CustomFunctionsPanel::nameEdited()
void CustomFunctionsPanel::onNameEdited()
{
QLineEdit *le = qobject_cast<QLineEdit*>(sender());
int index = le->property("index").toInt();
CustomFunctionData & cfn = functions[index];
if (cfn.custName != le->text()) {
strcpy(cfn.custName, le->text().toLatin1());

emit modified();
}
}
Expand All @@ -376,8 +360,8 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
{
CustomFunctionData & cfn = functions[i];
AssignFunc func = (AssignFunc)fswtchFunc[i]->currentData().toInt();



unsigned int widgetsMask = 0;
if (modified) {
Expand All @@ -388,7 +372,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)

}
else {
name[i]->setText(cfn.custName);
name[i]->setText(cfn.custName);
fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(cfn.swtch.toValue()));
fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(cfn.func));
}
Expand Down
3 changes: 1 addition & 2 deletions companion/src/modeledit/customfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class CustomFunctionsPanel : public GenericPanel

private slots:
void customFunctionEdited();
void nameEdited();
void refreshSwitchComboBoxes();
void onNameEdited();
void functionEdited();
void onCustomContextMenuRequested(QPoint pos);
void refreshCustomFunction(int index, bool modified=false);
Expand Down
31 changes: 15 additions & 16 deletions companion/src/modeledit/logicalswitches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
lsCapabilityExt = firmware->getCapability(LogicalSwitchesExt);

QStringList headerLabels;
headerLabels << "#" << "Name" << tr("Function") << tr("V1") << tr("V2") << tr("AND Switch");
headerLabels << "#" << tr("Name") << tr("Function") << tr("V1") << tr("V2") << tr("AND Switch");
if (lsCapabilityExt) {
headerLabels << tr("Duration") << tr("Delay");
}
Expand All @@ -66,13 +66,13 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
// The Custom Name
name[i] = new QLineEdit(this);
name[i]->setProperty("index", i);
name[i]->setMaxLength(10);
name[i]->setMaxLength(LS_CUSTNAME_LEN);
QRegExp rx(CHAR_FOR_NAMES_REGEX);
name[i]->setValidator(new QRegExpValidator(rx, this));
connect(name[i], SIGNAL(editingFinished()), this, SLOT(nameEdited()));
name[i]->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
connect(name[i], SIGNAL(editingFinished()), this, SLOT(onNameEdited()));
tableLayout->addWidget(i, 1, name[i]);


// The function
cbFunction[i] = new QComboBox(this);
cbFunction[i]->setProperty("index", i);
Expand Down Expand Up @@ -166,27 +166,26 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,

disableMouseScrolling();
tableLayout->resizeColumnsToContents();
tableLayout->pushRowsUp(lsCapability+1);
tableLayout->pushRowsUp(lsCapability + 1);
}

LogicalSwitchesPanel::~LogicalSwitchesPanel()
{
delete rawSourceFilteredModel;
delete rawSwitchFilteredModel;
}
void LogicalSwitchesPanel::nameEdited()

void LogicalSwitchesPanel::onNameEdited()
{

QLineEdit *le = qobject_cast<QLineEdit*>(sender());
int index = le->property("index").toInt();

if (model->logicalSw[index].custName != le->text()) {
strcpy(model->logicalSw[index].custName, le->text().toLatin1());
QLineEdit *le = qobject_cast<QLineEdit*>(sender());
int index = le->property("index").toInt();

int currentCbInt = cbSource1[index]->currentIndex();
model->logicalSw[index].val1 = cbSource1[index]->itemData(currentCbInt).toInt();
emit modified();
}
if (model->logicalSw[index].custName != le->text()) {
strcpy(model->logicalSw[index].custName, le->text().toLatin1());
if (model->logicalSw[index].func != LS_FN_OFF)
updateItemModels();
emit modified();
}
}

void LogicalSwitchesPanel::onFunctionChanged()
Expand Down
7 changes: 2 additions & 5 deletions companion/src/modeledit/logicalswitches.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
* GNU General Public License for more details.
*/

#ifndef _LOGICALSWITCHES_H_
#define _LOGICALSWITCHES_H_
#pragma once

#include "modeledit.h"
#include "radiodata.h"
Expand All @@ -42,7 +41,7 @@ class LogicalSwitchesPanel : public ModelPanel

private slots:
void onFunctionChanged();
void nameEdited();
void onNameEdited();
void onV1Changed(int value);
void onV2Changed(int value);
void onAndSwitchChanged(int value);
Expand Down Expand Up @@ -93,5 +92,3 @@ class LogicalSwitchesPanel : public ModelPanel
void updateItemModels();
void connectItemModelEvents(const FilteredItemModel * itemModel);
};

#endif // _LOGICALSWITCHES_H_

0 comments on commit ce36ca6

Please sign in to comment.