From cd6c599f43b628cefa972dbf975277d0e28da4a6 Mon Sep 17 00:00:00 2001 From: Neil Horne Date: Sat, 8 Jun 2019 18:45:38 +1000 Subject: [PATCH] Add RX numbers to CPN models list (2.3) (#6447) Add RX numbers to models list (#5088) --- companion/src/mdichild.cpp | 9 +++++- companion/src/modelslist.cpp | 58 +++++++++++++++++++++++++++++++++--- companion/src/modelslist.h | 5 ++++ 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index ade0caeb1..f3001e615 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -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() diff --git a/companion/src/modelslist.cpp b/companion/src/modelslist.cpp index ecc7dcec7..443432a3c 100644 --- a/companion/src/modelslist.cpp +++ b/companion/src/modelslist.cpp @@ -25,7 +25,8 @@ TreeItem::TreeItem(const QVector & 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 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 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; imodels.size(); i++) { + ModelData & model = radioData->models[i]; + if (!model.isEmpty()) { + for (unsigned j=0; j 1) { + return false; + } + } + } + } + } + return true; +} diff --git a/companion/src/modelslist.h b/companion/src/modelslist.h index 499e96a6b..d7e60684c 100644 --- a/companion/src/modelslist.h +++ b/companion/src/modelslist.h @@ -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_