feat(color): New label based Model Selector (#1374)

* Model Labels Selector

* Portrait Layout

* Receiver ID Check

* Fix Labels .yml format

* Companion Initial Commit

commit 967ddf3979b4954402fe62c858faba4b7a416bba
Author: dlktdr <cblackburn320@gmail.com>
Date:   Mon Aug 29 01:49:15 2022 -0700

    Fix Labels .yml format

commit 534221cad9e01146c47a9ac1080a655e04f1f6c8
Author: dlktdr <cblackburn320@gmail.com>
Date:   Mon Aug 29 01:20:57 2022 -0700

    Receiver ID Check

commit f32c0939d44e9ae60bc0705a9176354c23fec198
Author: dlktdr <cblackburn320@gmail.com>
Date:   Sun Aug 28 23:13:25 2022 -0700

    Portrait Layout

commit 961181217c7841ff3f21299ac6aa419b810f80e9
Author: dlktdr <cblackburn320@gmail.com>
Date:   Sat Dec 11 16:56:13 2021 -0800

    Model Labels Selector

commit dc99dd40d2
Author: David PHAM-VAN <1387855+DavBfr@users.noreply.github.com>
Date:   Fri Aug 26 03:04:34 2022 -0300

    feat: Allow Lua widget to override built-in widget with same name (#2208)

    * Allow CPP Widgets Override with LUA

    * Reset a widget option it the type differs

commit 4b747caff9
Author: eshifri <46511024+eshifri@users.noreply.github.com>
Date:   Thu Aug 25 19:47:53 2022 -0700

    fix: Write model name into models.yml when duplicating model (#2224)

    * Update model name in the models.yml file (#2214)

    * Fix the length of the name.

commit e97f23a305
Author: eshifri <46511024+eshifri@users.noreply.github.com>
Date:   Wed Aug 24 21:19:52 2022 -0700

    fix(cpn): Fix full path to model notes for Simulator (#2223)

* Correct Highlighted Column

* labels .yml indentation

* Update da.h

New defines translated to Danish

* Update dataconstants.h

Omit warnings due to difference of LEN_MODEL_FILENAME and LEN_MODEL_NAME in modellist.cpp

* Update modelslist.cpp

Wonder if this are the right file in PR #1374 (?), seems a lot are changed to the better in #1374

* Update dataconstants.h

Restore #define for LEN_MODEL_FILENAME to 16

* Rebase, Correct Issues

Delete now deletes instead of select
New model stores correct information
Duplicate save all information in cell
Rework items to use cell over button
Reword function variables

* CMPN: Add context menu

Fix output not functional. Removed Yaml::null at some point :)
Fix some compiler warnings

* CMPN: Compiler warning, replace ,->_ in list

* FW: Various Changes

Change view to a grid
Don't allow comma in label name
Add scroll indicators
Save sort order

Co-authored-by: HThuren <99370924+HThuren@users.noreply.github.com>
This commit is contained in:
Cliff
2022-09-03 09:01:19 +10:00
committed by GitHub
co-authored by HThuren
parent 20dc9c4d26
commit c8693569b0
85 changed files with 4006 additions and 2067 deletions
+105 -126
View File
@@ -20,7 +20,7 @@
#include "modelslist.h"
TreeItem::TreeItem(const QVector<QVariant> & itemData):
ModelListItem::ModelListItem(const QVector<QVariant> & itemData):
itemData(itemData),
parentItem(NULL),
categoryIndex(-1),
@@ -30,60 +30,60 @@ TreeItem::TreeItem(const QVector<QVariant> & itemData):
{
}
TreeItem::TreeItem(TreeItem * parent, int categoryIndex, int modelIndex):
TreeItem(QVector<QVariant>(parent->columnCount()))
ModelListItem::ModelListItem(ModelListItem * parent, int categoryIndex, int modelIndex):
ModelListItem(QVector<QVariant>(parent->columnCount()))
{
setParent(parent);
setCategoryIndex(categoryIndex);
setModelIndex(modelIndex);
}
TreeItem::~TreeItem()
ModelListItem::~ModelListItem()
{
qDeleteAll(childItems);
}
TreeItem * TreeItem::child(int number)
ModelListItem * ModelListItem::child(int number)
{
return childItems.value(number);
}
int TreeItem::childCount() const
int ModelListItem::childCount() const
{
return childItems.count();
}
int TreeItem::childNumber() const
int ModelListItem::childNumber() const
{
if (parentItem)
return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
return parentItem->childItems.indexOf(const_cast<ModelListItem*>(this));
return 0;
}
int TreeItem::columnCount() const
int ModelListItem::columnCount() const
{
return itemData.count();
}
QVariant TreeItem::data(int column) const
QVariant ModelListItem::data(int column) const
{
return itemData.value(column);
}
TreeItem *TreeItem::insertChild(const int row, int categoryIndex, int modelIndex)
ModelListItem *ModelListItem::insertChild(const int row, int categoryIndex, int modelIndex)
{
TreeItem * item = new TreeItem(this, categoryIndex, modelIndex);
ModelListItem * item = new ModelListItem(this, categoryIndex, modelIndex);
childItems.insert(row, item);
return item;
}
TreeItem * TreeItem::appendChild(int categoryIndex, int modelIndex)
ModelListItem * ModelListItem::appendChild(int categoryIndex, int modelIndex)
{
return insertChild(childItems.size(), categoryIndex, modelIndex);
}
bool TreeItem::removeChildren(int position, int count)
bool ModelListItem::removeChildren(int position, int count)
{
if (position < 0 || position + count > childItems.size())
return false;
@@ -94,7 +94,7 @@ bool TreeItem::removeChildren(int position, int count)
return true;
}
bool TreeItem::insertChildren(int row, int count)
bool ModelListItem::insertChildren(int row, int count)
{
for (int i=0; i < count; ++i) {
insertChild(row + i, -1, -1);
@@ -102,7 +102,7 @@ bool TreeItem::insertChildren(int row, int count)
return true;
}
bool TreeItem::setData(int column, const QVariant & value)
bool ModelListItem::setData(int column, const QVariant & value)
{
if (column < 0 || column >= itemData.size())
return false;
@@ -111,7 +111,7 @@ bool TreeItem::setData(int column, const QVariant & value)
return true;
}
void TreeItem::setFlag(const quint16 & flag, const bool on)
void ModelListItem::setFlag(const quint16 & flag, const bool on)
{
if (on)
flags |= flag;
@@ -119,57 +119,60 @@ void TreeItem::setFlag(const quint16 & flag, const bool on)
flags &= ~flag;
}
bool TreeItem::isCategory() const
bool ModelListItem::isCategory() const
{
return (modelIndex < 0 && categoryIndex > -1);
}
bool TreeItem::isModel() const
bool ModelListItem::isModel() const
{
return (modelIndex > -1);
}
/*
* TreeModel
* ModelsListModel
*/
TreeModel::TreeModel(RadioData * radioData, QObject * parent):
ModelsListModel::ModelsListModel(RadioData * radioData, QObject * parent):
QAbstractItemModel(parent),
radioData(radioData)
{
hasCategories = getCurrentFirmware()->getCapability(Capability::HasModelCategories);
hasLabels = getCurrentFirmware()->getCapability(Capability::HasModelLabels);
QVector<QVariant> labels;
if (!hasCategories)
if (!hasLabels)
labels << tr("Index");
labels << tr("Name");
labels << tr("RX #");
rootItem = new TreeItem(labels);
if (hasLabels)
labels << tr("Labels");
rootItem = new ModelListItem(labels);
// uniqueId and version for drag/drop operations (see encodeHeaderData())
mimeHeaderData.instanceId = QUuid::createUuid();
mimeHeaderData.dataVersion = 1;
refresh();
//connect(this, &QAbstractItemModel::rowsAboutToBeRemoved, this, &TreeModel::onRowsAboutToBeRemoved);
connect(this, &QAbstractItemModel::rowsRemoved, this, &TreeModel::onRowsRemoved);
//connect(this, &QAbstractItemModel::rowsAboutToBeRemoved, this, &ModelsListModel::onRowsAboutToBeRemoved);
connect(this, &QAbstractItemModel::rowsRemoved, this, &ModelsListModel::onRowsRemoved);
}
TreeModel::~TreeModel()
ModelsListModel::~ModelsListModel()
{
delete rootItem;
}
int TreeModel::columnCount(const QModelIndex & /* parent */) const
int ModelsListModel::columnCount(const QModelIndex & /* parent */) const
{
return rootItem->columnCount();
}
QVariant TreeModel::data(const QModelIndex & index, int role) const
QVariant ModelsListModel::data(const QModelIndex & index, int role) const
{
if (!index.isValid())
return QVariant();
TreeItem * item = getItem(index);
ModelListItem * item = getItem(index);
if (role == Qt::DisplayRole || role == Qt::EditRole) {
return item->data(index.column());
@@ -181,12 +184,15 @@ QVariant TreeModel::data(const QModelIndex & index, int role) const
return font;
}
if (role == Qt::ForegroundRole && (item->getFlags() & TreeItem::MarkedForCut)) {
if (role == Qt::ForegroundRole && (item->getFlags() & ModelListItem::MarkedForCut)) {
return QPalette().brush(QPalette::Disabled, QPalette::Text);
}
if (role == Qt::ForegroundRole && item->isModel()) {
if (index.column() == (item->columnCount() - 1) && item->isHighlightRX()) {
int col = item->columnCount() - 1;
if(hasLabels)
col --;
if (index.column() == col && item->isHighlightRX()) {
QBrush brush;
brush.setColor(Qt::red);
return brush;
@@ -196,23 +202,18 @@ QVariant TreeModel::data(const QModelIndex & index, int role) const
return QVariant();
}
Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
Qt::ItemFlags ModelsListModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags f = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
if (index.isValid()) {
if (getItem(index)->isCategory())
f |= Qt::ItemIsEditable;
else
f |= Qt::ItemIsDragEnabled; // TODO drag/drop categories
}
f |= Qt::ItemIsDragEnabled;
f |= Qt::ItemIsDropEnabled;
//qDebug() << f;
return f;
}
QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
QVariant ModelsListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return rootItem->data(section);
@@ -220,36 +221,27 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int rol
return QVariant();
}
QModelIndex TreeModel::index(int row, int column, const QModelIndex & parent) const
QModelIndex ModelsListModel::index(int row, int column, const QModelIndex & parent) const
{
if (parent.isValid() && parent.column() != 0)
return QModelIndex();
TreeItem * parentItem = getItem(parent);
TreeItem * childItem = parentItem->child(row);
ModelListItem * parentItem = getItem(parent);
ModelListItem * childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex TreeModel::parent(const QModelIndex & index) const
QModelIndex ModelsListModel::parent(const QModelIndex & index) const
{
if (!index.isValid())
return QModelIndex();
TreeItem * childItem = getItem(index);
TreeItem * parentItem = childItem->parent();
if (parentItem == rootItem)
return QModelIndex();
return createIndex(parentItem->childNumber(), 0, parentItem);
return QModelIndex();
}
bool TreeModel::removeRows(int position, int rows, const QModelIndex & parent)
bool ModelsListModel::removeRows(int position, int rows, const QModelIndex & parent)
{
TreeItem * parentItem = getItem(parent);
ModelListItem * parentItem = getItem(parent);
if (!parentItem)
return false;
@@ -264,9 +256,9 @@ bool TreeModel::removeRows(int position, int rows, const QModelIndex & parent)
}
/* unused but possibly useful in future
bool TreeModel::insertRows(int row, int count, const QModelIndex & parent)
bool ModelsListModel::insertRows(int row, int count, const QModelIndex & parent)
{
TreeItem * parentItem = getItem(parent);
ModelListItem * parentItem = getItem(parent);
if (!parentItem)
return false;
@@ -280,13 +272,13 @@ bool TreeModel::insertRows(int row, int count, const QModelIndex & parent)
return success;
} */
int TreeModel::rowCount(const QModelIndex &parent) const
int ModelsListModel::rowCount(const QModelIndex &parent) const
{
TreeItem * parentItem = getItem(parent);
ModelListItem * parentItem = getItem(parent);
return parentItem->childCount();
}
bool TreeModel::setData(const QModelIndex & index, const QVariant & value, int role)
bool ModelsListModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
if (role != Qt::EditRole)
return false;
@@ -294,7 +286,7 @@ bool TreeModel::setData(const QModelIndex & index, const QVariant & value, int r
if (!index.isValid())
return false;
TreeItem * item = getItem(index);
ModelListItem * item = getItem(index);
bool result = item->setData(index.column(), value);
if (result) {
@@ -304,7 +296,7 @@ bool TreeModel::setData(const QModelIndex & index, const QVariant & value, int r
return result;
}
QStringList TreeModel::mimeTypes() const
QStringList ModelsListModel::mimeTypes() const
{
QStringList types;
types << "application/x-companion-modeldata";
@@ -313,18 +305,18 @@ QStringList TreeModel::mimeTypes() const
return types;
}
Qt::DropActions TreeModel::supportedDropActions() const
Qt::DropActions ModelsListModel::supportedDropActions() const
{
return Qt::CopyAction | Qt::MoveAction;
}
Qt::DropActions TreeModel::supportedDragActions() const
Qt::DropActions ModelsListModel::supportedDragActions() const
{
return Qt::CopyAction | Qt::MoveAction;
}
// This method encodes all the data on default drag operation, including general radio settings. This is useful for eg. Compare dialog/model printer.
QMimeData * TreeModel::mimeData(const QModelIndexList & indexes) const
QMimeData * ModelsListModel::mimeData(const QModelIndexList & indexes) const
{
QMimeData * mimeData = new QMimeData();
getModelsMimeData(indexes, mimeData);
@@ -333,7 +325,7 @@ QMimeData * TreeModel::mimeData(const QModelIndexList & indexes) const
return mimeData;
}
bool TreeModel::canDropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) const
bool ModelsListModel::canDropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) const
{
Q_UNUSED(action);
//qDebug() << action << row << column << parent.row();
@@ -345,7 +337,7 @@ bool TreeModel::canDropMimeData(const QMimeData * data, Qt::DropAction action, i
return false;
}
bool TreeModel::dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent)
bool ModelsListModel::dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent)
{
if (!canDropMimeData(data, action, row, column, parent))
return false;
@@ -380,7 +372,7 @@ bool TreeModel::dropMimeData(const QMimeData * data, Qt::DropAction action, int
return true;
}
QMimeData *TreeModel::getModelsMimeData(const QModelIndexList & indexes, QMimeData * mimeData) const
QMimeData *ModelsListModel::getModelsMimeData(const QModelIndexList & indexes, QMimeData * mimeData) const
{
if (!mimeData)
mimeData = new QMimeData();
@@ -390,7 +382,7 @@ QMimeData *TreeModel::getModelsMimeData(const QModelIndexList & indexes, QMimeDa
return mimeData;
}
QMimeData *TreeModel::getGeneralMimeData(QMimeData * mimeData) const
QMimeData *ModelsListModel::getGeneralMimeData(QMimeData * mimeData) const
{
if (!mimeData)
mimeData = new QMimeData();
@@ -400,7 +392,7 @@ QMimeData *TreeModel::getGeneralMimeData(QMimeData * mimeData) const
return mimeData;
}
QMimeData *TreeModel::getHeaderMimeData(QMimeData * mimeData) const
QMimeData *ModelsListModel::getHeaderMimeData(QMimeData * mimeData) const
{
if (!mimeData)
mimeData = new QMimeData();
@@ -410,14 +402,14 @@ QMimeData *TreeModel::getHeaderMimeData(QMimeData * mimeData) const
return mimeData;
}
QUuid TreeModel::getMimeDataSourceId(const QMimeData * mimeData) const
QUuid ModelsListModel::getMimeDataSourceId(const QMimeData * mimeData) const
{
MimeHeaderData header;
decodeHeaderData(mimeData, &header);
return header.instanceId;
}
bool TreeModel::hasSupportedMimeData(const QMimeData * mimeData) const
bool ModelsListModel::hasSupportedMimeData(const QMimeData * mimeData) const
{
foreach (const QString & mtype, mimeTypes()) {
if (mimeData->hasFormat(mtype))
@@ -426,28 +418,28 @@ bool TreeModel::hasSupportedMimeData(const QMimeData * mimeData) const
return false;
}
bool TreeModel::hasModelsMimeData(const QMimeData * mimeData) const
bool ModelsListModel::hasModelsMimeData(const QMimeData * mimeData) const
{
return mimeData->hasFormat("application/x-companion-modeldata");
}
bool TreeModel::hasGenralMimeData(const QMimeData * mimeData) const
bool ModelsListModel::hasGenralMimeData(const QMimeData * mimeData) const
{
return mimeData->hasFormat("application/x-companion-generaldata");
}
bool TreeModel::hasHeaderMimeData(const QMimeData * mimeData) const
bool ModelsListModel::hasHeaderMimeData(const QMimeData * mimeData) const
{
return mimeData->hasFormat("application/x-companion-radiodata-header");
}
// returns true if mime data origin was this data model (vs. from another file window)
bool TreeModel::hasOwnMimeData(const QMimeData * mimeData) const
bool ModelsListModel::hasOwnMimeData(const QMimeData * mimeData) const
{
return (getMimeDataSourceId(mimeData) == mimeHeaderData.instanceId);
}
void TreeModel::encodeModelsData(const QModelIndexList & indexes, QByteArray * data) const
void ModelsListModel::encodeModelsData(const QModelIndexList & indexes, QByteArray * data) const
{
foreach (const QModelIndex &index, indexes) {
if (index.isValid() && index.column() == 0) {
@@ -459,15 +451,15 @@ void TreeModel::encodeModelsData(const QModelIndexList & indexes, QByteArray * d
}
}
void TreeModel::encodeGeneralData(QByteArray * data) const
void ModelsListModel::encodeGeneralData(QByteArray * data) const
{
data->append('G');
data->append((char *)&radioData->generalSettings, sizeof(GeneralSettings));
}
void TreeModel::encodeHeaderData(QByteArray * data) const
void ModelsListModel::encodeHeaderData(QByteArray * data) const
{
// We use a unique ID representing this TreeModel instance (a unique file).
// We use a unique ID representing this ModelsListModel instance (a unique file).
// This can be used eg. to detect cross-file drop operations.
QDataStream stream(data, QIODevice::WriteOnly);
stream << mimeHeaderData.dataVersion;
@@ -475,7 +467,7 @@ void TreeModel::encodeHeaderData(QByteArray * data) const
}
// static
bool TreeModel::decodeHeaderData(const QMimeData * mimeData, MimeHeaderData * header)
bool ModelsListModel::decodeHeaderData(const QMimeData * mimeData, MimeHeaderData * header)
{
if (header && mimeData->hasFormat("application/x-companion-radiodata-header")) {
QByteArray data = mimeData->data("application/x-companion-radiodata-header");
@@ -487,7 +479,7 @@ bool TreeModel::decodeHeaderData(const QMimeData * mimeData, MimeHeaderData * he
}
// static
bool TreeModel::decodeMimeData(const QMimeData * mimeData, QVector<ModelData> * models, GeneralSettings * gs, bool * hasGenSet)
bool ModelsListModel::decodeMimeData(const QMimeData * mimeData, QVector<ModelData> * models, GeneralSettings * gs, bool * hasGenSet)
{
bool ret = false;
char * gData;
@@ -528,7 +520,7 @@ bool TreeModel::decodeMimeData(const QMimeData * mimeData, QVector<ModelData> *
}
// static
int TreeModel::countModelsInMimeData(const QMimeData * mimeData)
int ModelsListModel::countModelsInMimeData(const QMimeData * mimeData)
{
int ret = 0;
if (mimeData->hasFormat("application/x-companion-modeldata")) {
@@ -539,10 +531,10 @@ int TreeModel::countModelsInMimeData(const QMimeData * mimeData)
}
TreeItem * TreeModel::getItem(const QModelIndex & index) const
ModelListItem * ModelsListModel::getItem(const QModelIndex & index) const
{
if (index.isValid()) {
TreeItem * item = static_cast<TreeItem *>(index.internalPointer());
ModelListItem * item = static_cast<ModelListItem *>(index.internalPointer());
if (item) {
return item;
}
@@ -551,7 +543,7 @@ TreeItem * TreeModel::getItem(const QModelIndex & index) const
}
// recursive
QModelIndex TreeModel::getIndexForModel(const int modelIndex, QModelIndex parent)
QModelIndex ModelsListModel::getIndexForModel(const int modelIndex, QModelIndex parent)
{
for (int i = 0; i < rowCount(parent); ++i) {
QModelIndex idx = index(i, 0, parent);
@@ -563,7 +555,7 @@ QModelIndex TreeModel::getIndexForModel(const int modelIndex, QModelIndex parent
return QModelIndex();
}
QModelIndex TreeModel::getIndexForCategory(const int categoryIndex)
QModelIndex ModelsListModel::getIndexForCategory(const int categoryIndex)
{
for (int i = 0; i < rowCount(); ++i) {
if (getItem(index(i, 0))->getCategoryIndex() == categoryIndex)
@@ -572,51 +564,51 @@ QModelIndex TreeModel::getIndexForCategory(const int categoryIndex)
return QModelIndex();
}
int TreeModel::getModelIndex(const QModelIndex & index) const
int ModelsListModel::getModelIndex(const QModelIndex & index) const
{
return getItem(index)->getModelIndex();
}
int TreeModel::getCategoryIndex(const QModelIndex & index) const
int ModelsListModel::getCategoryIndex(const QModelIndex & index) const
{
return getItem(index)->getCategoryIndex();
}
int TreeModel::rowNumber(const QModelIndex & index) const
int ModelsListModel::rowNumber(const QModelIndex & index) const
{
return getItem(index)->childNumber();
}
bool TreeModel::isCategoryType(const QModelIndex & index) const
bool ModelsListModel::isCategoryType(const QModelIndex & index) const
{
return index.isValid() && getItem(index)->isCategory();
}
bool TreeModel::isModelType(const QModelIndex & index) const
bool ModelsListModel::isModelType(const QModelIndex & index) const
{
return index.isValid() && getItem(index)->isModel();
}
void TreeModel::markItemForCut(const QModelIndex & index, bool on)
void ModelsListModel::markItemForCut(const QModelIndex & index, bool on)
{
if (index.isValid() && index.column() == 0)
getItem(index)->setFlag(TreeItem::MarkedForCut, on);
getItem(index)->setFlag(ModelListItem::MarkedForCut, on);
}
void TreeModel::markItemsForCut(const QModelIndexList & indexes, bool on)
void ModelsListModel::markItemsForCut(const QModelIndexList & indexes, bool on)
{
foreach (const QModelIndex &index, indexes)
markItemForCut(index, on);
}
// onRowsAboutToBeRemoved could be a way to deal with models being drag-drop moved to another window/file.
// TreeModel detects these as removals and runs removeRows(), which deletes the Model indexes
// ModelsListModel detects these as removals and runs removeRows(), which deletes the Model indexes
// but not the actual models from the RadioData::models array.
// BUT this also runs when moving rows within our own tree, and if there is an error during the move,
// or the user cancels the operation, removeRows() is still called automatically somewhere inside QAbstractItemModel().
// If a solution could be found to this problem then we could enable DnD-moving models between file windows.
/*
void TreeModel::onRowsAboutToBeRemoved(const QModelIndex & parent, int first, int last)
void ModelsListModel::onRowsAboutToBeRemoved(const QModelIndex & parent, int first, int last)
{
qDebug() << parent << first << last;
QVector<int> modelIndices;
@@ -628,55 +620,38 @@ void TreeModel::onRowsAboutToBeRemoved(const QModelIndex & parent, int first, in
}
*/
void TreeModel::onRowsRemoved(const QModelIndex & parent, int first, int last)
void ModelsListModel::onRowsRemoved(const QModelIndex & parent, int first, int last)
{
// This is a workaround to deal with models being DnD moved to another window/file or if user cancels a DnD move within our own.
// TreeModel detects these as removals and runs removeRows(), which deletes the Model indexes but not our actual models. See notes above.
// ModelsListModel detects these as removals and runs removeRows(), which deletes the Model indexes but not our actual models. See notes above.
//qDebug() << parent << first << last;
emit refreshRequested(); // request refresh from View because it may have it's own ideas
}
void TreeModel::refresh()
void ModelsListModel::refresh()
{
TreeItem * defaultCategoryItem = NULL;
ModelListItem * defaultCategoryItem = NULL;
this->blockSignals(true); // make sure onRowsRemoved is not triggered
removeRows(0, rowCount());
this->blockSignals(false);
if (hasCategories) {
/*if (hasCategories) {
for (unsigned i = 0; i < radioData->categories.size(); i++) {
TreeItem * current = rootItem->appendChild(i, -1);
ModelListItem * current = rootItem->appendChild(i, -1);
current->setData(0, QString(radioData->categories[i].name));
}
}
}*/
for (unsigned i = 0; i < radioData->models.size(); i++) {
ModelData & model = radioData->models[i];
int currentColumn = 0;
TreeItem * current = NULL;
ModelListItem * current = NULL;
model.modelIndex = i;
if (hasCategories) {
if (!model.isEmpty()) {
TreeItem * categoryItem;
// TODO category should be set to -1 if not Horus
if (model.category >= 0 && model.category < rootItem->childCount()) {
categoryItem = rootItem->child(model.category);
}
else {
model.category = 0;
if (!defaultCategoryItem) {
defaultCategoryItem = rootItem->appendChild(0, -1);
/*: Translators do NOT use accent for this, this is the default category name on Horus. */
defaultCategoryItem->setData(0, tr("Models"));
radioData->categories.push_back(qPrintable(tr("Models")));
}
categoryItem = defaultCategoryItem;
}
current = categoryItem->appendChild(model.category, i);
}
if (hasLabels) {
current = rootItem->appendChild(0, i);
}
else {
current = rootItem->appendChild(0, i);
@@ -715,10 +690,13 @@ void TreeModel::refresh()
}
current->setData(currentColumn++, rxs);
}
if (hasLabels) {
current->setData(currentColumn++, QString(model.labels));
}
}
}
bool TreeModel::isModelIdUnique(unsigned modelIdx, unsigned module, unsigned protocol)
bool ModelsListModel::isModelIdUnique(unsigned modelIdx, unsigned module, unsigned protocol)
{
int cnt = 0;
if (protocol== PULSES_PXX_XJT_D8)
@@ -736,3 +714,4 @@ bool TreeModel::isModelIdUnique(unsigned modelIdx, unsigned module, unsigned pro
}
return true;
}