1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 01:05:10 +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

@ -534,7 +534,6 @@ void MdiChild::initModelsList()
connect(modelsListModel, &QAbstractItemModel::dataChanged, this, &MdiChild::onDataChanged);
ui->modelsList->setModel(modelsListModel);
ui->modelsList->header()->setVisible(!firmware->getCapability(Capability::HasModelCategories));
if (IS_HORUS(board)) {
ui->modelsList->setIndentation(20);
// ui->modelsList->resetIndentation(); // introduced in next Qt versions ...
@ -543,6 +542,14 @@ void MdiChild::initModelsList()
ui->modelsList->setIndentation(0);
}
refresh();
if (firmware->getCapability(Capability::HasModelCategories)) {
ui->modelsList->header()->resizeSection(0, ui->modelsList->header()->sectionSize(0) * 2); // pad out categories and model names
}
else {
ui->modelsList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); // minimise Index
ui->modelsList->header()->resizeSection(1, ui->modelsList->header()->sectionSize(1) * 1.5); // pad out model names
}
}
void MdiChild::refresh()

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;
}

View file

@ -53,6 +53,8 @@ class TreeItem
void setModelIndex(int value) { modelIndex = value; }
int getCategoryIndex() const { return categoryIndex; }
void setCategoryIndex(int value) { categoryIndex = value; }
void setHighlightRX(int value) { highlightRX = value; }
bool isHighlightRX() const { return highlightRX; }
quint16 getFlags() const { return flags; }
void setFlags(const quint16 & value) { flags = value; }
@ -68,6 +70,7 @@ class TreeItem
int categoryIndex;
int modelIndex;
quint16 flags;
bool highlightRX;
};
@ -146,11 +149,13 @@ class TreeModel : public QAbstractItemModel
private:
TreeItem * getItem(const QModelIndex & index) const;
bool isModelIdUnique(unsigned modelId);
TreeItem * rootItem;
RadioData * radioData;
int availableEEpromSize;
MimeHeaderData mimeHeaderData;
bool hasCategories;
};
#endif // _MODELSLIST_H_