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
+276
View File
@@ -0,0 +1,276 @@
#include "labels.h"
LabelsModel::LabelsModel(QItemSelectionModel *selectionModel,
RadioData *radioData, QObject *parent) :
QAbstractItemModel(parent),
modelsSelection(selectionModel),
radioData(radioData),
selectedModel(-1)
{
connect(modelsSelection, &QItemSelectionModel::currentChanged,
this, &LabelsModel::modelsSelectionChanged );
buildLabelsList();
}
LabelsModel::~LabelsModel()
{
}
Qt::ItemFlags LabelsModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags flags = Qt::ItemIsEnabled;
if(index.column() == 0) {
flags |= Qt::ItemIsUserCheckable;
flags |= Qt::ItemIsSelectable;
flags |= Qt::ItemIsDropEnabled;
flags |= Qt::ItemIsEditable;
if(index.isValid())
flags |= Qt::ItemIsDragEnabled;
}
return flags;
}
bool LabelsModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if(!index.isValid() || index.column() != 0 ||
index.row() >= radioData->labels.size() ||
selectedModel == -1)
return false;
if(role == Qt::CheckStateRole) {
if(value==Qt::Unchecked) {
if(radioData->removeLabelFromModel(selectedModel, radioData->labels.at(index.row())))
emit modelChanged(selectedModel);
} else {
if(radioData->addLabelToModel(selectedModel, radioData->labels.at(index.row())))
emit modelChanged(selectedModel);
}
emit dataChanged(this->index(index.row(), 0),
this->index(index.row(), 0));
return true;
} else if(role == Qt::EditRole) {
// Don't allow comma, replace with _
if(radioData->renameLabel(index.row(),value.toString().replace(',','_'))) {
labels[index.row()].label = value.toString().replace(',','_');
emit dataChanged(this->index(index.row(), 0),
this->index(index.row(), 0));
emit modelChanged(selectedModel);
}
return true;
}
return false;
}
QVariant LabelsModel::data(const QModelIndex &index, int role) const
{
// if(index.row() >= radioData->labels.size() || !index.isValid() )
if(index.row() >= labels.size() || !index.isValid() )
return QVariant();
QString label = radioData->labels.at(index.row());
if(role == Qt::DisplayRole || role == Qt::EditRole) {
if(index.column() == 0) {
return labels.at(index.row()).label;
//return label;
}
} else if (role == Qt::CheckStateRole) {
if(index.column() == 0 && selectedModel >= 0 &&
selectedModel < (int)radioData->models.size()) {
return QString(radioData->models.at(selectedModel).labels).contains(label)?Qt::Checked:Qt::Unchecked;
}
}
return QVariant();
}
QModelIndex LabelsModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent)
if(row < labels.size())
return createIndex(row,0);
return QModelIndex();
}
QModelIndex LabelsModel::parent(const QModelIndex &index) const
{
return QModelIndex();
}
int LabelsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
//return radioData->labels.size();
return labels.size();
}
int LabelsModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 1;
}
QVariant LabelsModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role != Qt::DisplayRole ||
orientation != Qt::Horizontal ||
section != 0)
return QVariant();
return tr("Labels");
}
Qt::DropActions LabelsModel::supportedDropActions() const
{
return Qt::MoveAction;
}
QStringList LabelsModel::mimeTypes() const
{
QStringList types;
types << "application/edglbl.text.list";
return types;
}
QMimeData *LabelsModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData;
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
for (const QModelIndex &index : indexes) {
if (index.isValid()) {
QString text = data(index, Qt::DisplayRole).toString();
stream << text;
}
}
mimeData->setData("application/edglbl.text.list", encodedData);
return mimeData;
}
bool LabelsModel::canDropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(action);
Q_UNUSED(row);
Q_UNUSED(parent);
if (!data->hasFormat("application/edglbl.text.list"))
return false;
if (column > 0)
return false;
return true;
}
bool LabelsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
// TODO: This needs to be completed
if (!canDropMimeData(data, action, row, column, parent))
return false;
if(row < 0) return false;
if (action == Qt::IgnoreAction)
return true;
else if (action != Qt::MoveAction)
return false;
QByteArray encodedData = data->data("application/edglbl.text.list");
QDataStream stream(&encodedData, QIODevice::ReadOnly);
QStringList newItems;
int rows = 0;
while (!stream.atEnd()) {
QString text;
stream >> text;
newItems << text;
++rows;
}
/*insertRows(row, rows, QModelIndex());
for (const QString &text : qAsConst(newItems))
{
QModelIndex idx = index(row, 0, QModelIndex());
row++;
}*/
return true;
}
bool LabelsModel::insertRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
return false;
// Find a New Number
for (int i = 0; i < count; i++) {
int newno=0;
QString newstr;
do {
newstr = QString(tr("New%1").arg(newno));
if(newno == 0)
newstr = QString(tr("New"));
newno++;
} while(radioData->labels.contains(newstr));
// Add it to radioData
radioData->labels.insert(row+i, newstr);
}
buildLabelsList();
return true;
}
bool LabelsModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
return false;
bool deleted=false;
beginRemoveRows(parent, row, row + count - 1);
for (int i = 0; i != count; ++i)
if(radioData->deleteLabel(row+i)) {
deleted = true;
}
endRemoveRows();
// Refresh all
if(deleted)
emit modelChanged(-1);
buildLabelsList();
return true;
}
void LabelsModel::buildLabelsList()
{
labels.clear();
int i=0;
foreach(QString lbl, radioData->labels) {
LabelItem itm;
itm.label = lbl;
itm.radioLabelIndex = i++;
labels.append(itm);
}
if (i) {
emit dataChanged(index(0,0),
index(i-1,0));
}
}
void LabelsModel::modelsSelectionChanged()
{
QModelIndex index = modelsSelection->currentIndex();
if (index.isValid()) {
int mi = modelsSelection->currentIndex().row();
if(mi < (int)radioData->models.size()) {
selectedModel = mi;
buildLabelsList();
}
}
else
selectedModel = -1;
}