1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-26 09:45:16 +03:00

Add RX numbers to CPN models list (2.3) (#6447)

Add RX numbers to models list (#5088)
This commit is contained in:
Neil Horne 2019-06-08 18:45:38 +10:00 committed by Bertrand Songis
parent aff6c3fd1d
commit cd6c599f43
3 changed files with 67 additions and 5 deletions

View file

@ -25,7 +25,8 @@ TreeItem::TreeItem(const QVector<QVariant> & itemData):
parentItem(NULL),
categoryIndex(-1),
modelIndex(-1),
flags(0)
flags(0),
highlightRX(false)
{
}
@ -139,13 +140,15 @@ TreeModel::TreeModel(RadioData * radioData, QObject * parent):
availableEEpromSize(-1)
{
Board::Type board = getCurrentBoard();
hasCategories = getCurrentFirmware()->getCapability(Capability::HasModelCategories);
QVector<QVariant> labels;
if (!getCurrentFirmware()->getCapability(Capability::HasModelCategories))
if (!hasCategories)
labels << tr("Index");
labels << tr("Name");
if (!(IS_HORUS(board) || IS_SKY9X(board))) {
labels << tr("Size");
}
labels << tr("RX #");
rootItem = new TreeItem(labels);
// uniqueId and version for drag/drop operations (see encodeHeaderData())
mimeHeaderData.instanceId = QUuid::createUuid();
@ -187,6 +190,14 @@ QVariant TreeModel::data(const QModelIndex & index, int role) const
return QPalette().brush(QPalette::Disabled, QPalette::Text);
}
if (role == Qt::ForegroundRole && item->isModel()) {
if (index.column() == (item->columnCount() - 1) && item->isHighlightRX()) {
QBrush brush;
brush.setColor(Qt::red);
return brush;
}
}
return QVariant();
}
@ -640,8 +651,7 @@ void TreeModel::refresh()
EEPROMInterface * eepromInterface = getCurrentEEpromInterface();
Board::Type board = eepromInterface->getBoard();
TreeItem * defaultCategoryItem = NULL;
bool hasCategories = getCurrentFirmware()->getCapability(Capability::HasModelCategories);
bool hasEepromSizeData = (rootItem->columnCount() > 2);
bool hasEepromSizeData = (IS_HORUS(board) ? false : true);
if (hasEepromSizeData) {
availableEEpromSize = Boards::getEEpromSize(board) - 64; // let's consider fat
@ -710,6 +720,28 @@ void TreeModel::refresh()
availableEEpromSize -= size;
}
}
int protocol;
QString rxs;
for (unsigned j=0; j<CPN_MAX_MODULES; j++) {
protocol = model.moduleData[j].protocol;
// These are the only RXs that allow nominating RX # but changing RX or copying models can leave residual configuration which can cause issues
// if (protocol == PULSES_PXX_XJT_X16 || protocol == PULSES_PXX_XJT_LR12 || protocol == PULSES_PXX_R9M || protocol == PULSES_DSMX || protocol == PULSES_MULTIMODULE) {
if (!protocol == PULSES_OFF && model.moduleData[j].modelId > 0) {
if (!rxs.isEmpty()) {
rxs.append(", ");
}
unsigned mdlidx = model.moduleData[j].modelId;
rxs.append(QString("%1").arg(uint(mdlidx), 2, 10, QChar('0')));
if (!isModelIdUnique(mdlidx)) {
current->setHighlightRX(true);
}
ModelData & mdl = radioData->models[mdlidx-1];
if (mdl.isEmpty()) {
current->setHighlightRX(true);
}
}
}
current->setData(currentColumn++, rxs);
}
}
@ -717,3 +749,21 @@ void TreeModel::refresh()
availableEEpromSize = (availableEEpromSize / 16) * 15;
}
}
bool TreeModel::isModelIdUnique(unsigned modelIdx)
{
int cnt = 0;
for (unsigned i=0; i<radioData->models.size(); i++) {
ModelData & model = radioData->models[i];
if (!model.isEmpty()) {
for (unsigned j=0; j<CPN_MAX_MODULES; j++) {
if (model.moduleData[j].protocol != PULSES_OFF && model.moduleData[j].modelId == modelIdx) {
if (++cnt > 1) {
return false;
}
}
}
}
}
return true;
}