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 commitdc99dd40d2Author: 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 commit4b747caff9Author: 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. commite97f23a305Author: 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:
@@ -211,6 +211,7 @@ set(companion_SRCS
|
||||
helpers_html.cpp
|
||||
mdichild.cpp
|
||||
modelslist.cpp
|
||||
labels.cpp
|
||||
apppreferencesdialog.cpp
|
||||
fwpreferencesdialog.cpp
|
||||
burnconfigdialog.cpp
|
||||
@@ -269,6 +270,7 @@ set(companion_MOC_HDRS
|
||||
modelprinter.h
|
||||
multimodelprinter.h
|
||||
modelslist.h
|
||||
labels.h
|
||||
styleeditdialog.h
|
||||
helpers_html.h
|
||||
dialogs/filesyncdialog.h
|
||||
|
||||
@@ -75,7 +75,7 @@ bool CompareDialog::handleMimeData(const QMimeData * mimeData)
|
||||
{
|
||||
QVector<ModelData> mList;
|
||||
GeneralSettings gs;
|
||||
if (!TreeModel::decodeMimeData(mimeData, &mList, &gs) || mList.isEmpty())
|
||||
if (!ModelsListModel::decodeMimeData(mimeData, &mList, &gs) || mList.isEmpty())
|
||||
return false;
|
||||
for (int i=0; i < mList.size(); ++i) {
|
||||
GMData data;
|
||||
|
||||
@@ -89,39 +89,23 @@ static void writeYamlToByteArray(const YAML::Node& node, QByteArray& data, bool
|
||||
qDebug() << data.toStdString().c_str();
|
||||
}
|
||||
|
||||
bool loadModelsListFromYaml(std::vector<CategoryData>& categories,
|
||||
bool loadLabelsListFromYaml(QStringList& labels,
|
||||
EtxModelfiles& modelFiles,
|
||||
const QByteArray& data)
|
||||
{
|
||||
labels.clear();
|
||||
if (data.size() == 0)
|
||||
return true;
|
||||
|
||||
YAML::Node node = loadYamlFromByteArray(data);
|
||||
if (!node.IsSequence()) return false;
|
||||
|
||||
int modelIdx = 0;
|
||||
for (const auto& cat : node) {
|
||||
if (!cat.IsMap()) continue;
|
||||
|
||||
for (const auto& cat_map : cat) {
|
||||
categories.push_back(cat_map.first.Scalar().c_str());
|
||||
|
||||
const auto& models = cat_map.second;
|
||||
if (!models.IsSequence()) continue;
|
||||
|
||||
for (const auto& model : models) {
|
||||
std::string filename, name;
|
||||
model["filename"] >> filename;
|
||||
model["name"] >> name;
|
||||
modelFiles.push_back(
|
||||
{filename, name, (int)categories.size() - 1, modelIdx++});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!node.IsMap()) return false; // Root Map (Labels, Models)
|
||||
for (const auto& lbl : node["Labels"]) {
|
||||
labels.append(QString::fromStdString(lbl.first.as<std::string>()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool loadModelFromYaml(ModelData& model, const QByteArray& data)
|
||||
{
|
||||
YAML::Node node = loadYamlFromByteArray(data);
|
||||
@@ -168,46 +152,12 @@ bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// 'modelFiles' should be ordered by Category index to avoid
|
||||
// turning the sequence into a map.
|
||||
//
|
||||
bool writeModelsListToYaml(const std::vector<CategoryData>& categories,
|
||||
const EtxModelfiles& modelFiles,
|
||||
QByteArray& data)
|
||||
bool writeLabelsListToYaml(const RadioData &radioData, QByteArray& data)
|
||||
{
|
||||
YAML::Node node;
|
||||
std::vector<CategoryData> cats = categories;
|
||||
std::vector<EtxModelMetadata> files = { modelFiles.begin(), modelFiles.end() };
|
||||
|
||||
std::stable_sort(files.begin(), files.end(),
|
||||
[](const EtxModelMetadata &a, const EtxModelMetadata &b) {
|
||||
return a.category < b.category;
|
||||
});
|
||||
|
||||
int catIdx = 0;
|
||||
for (const auto& cat : cats) {
|
||||
node[catIdx++][cat.name] = YAML::Node();
|
||||
foreach(QString label, radioData.labels) {
|
||||
node["Labels"][label.toStdString()] = YAML::Null;
|
||||
}
|
||||
|
||||
for (const auto& modelFile: modelFiles) {
|
||||
|
||||
YAML::Node cat_attrs;
|
||||
cat_attrs["filename"] = modelFile.filename;
|
||||
cat_attrs["name"] = modelFile.name;
|
||||
|
||||
catIdx = modelFile.category;
|
||||
if (catIdx >= (int)cats.size()) {
|
||||
catIdx = 0;
|
||||
if (cats.size() == 0) {
|
||||
cats.push_back("Models");
|
||||
}
|
||||
}
|
||||
|
||||
const std::string cat_name = cats[catIdx].name;
|
||||
node[catIdx][cat_name].push_back(cat_attrs);
|
||||
}
|
||||
|
||||
writeYamlToByteArray(node, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,22 +32,19 @@ constexpr unsigned int CPN_CURRENT_SETTINGS_VERSION = { 221 };
|
||||
struct EtxModelMetadata {
|
||||
std::string filename;
|
||||
std::string name;
|
||||
int category;
|
||||
int modelIdx;
|
||||
};
|
||||
|
||||
typedef std::list<EtxModelMetadata> EtxModelfiles;
|
||||
|
||||
bool loadModelsListFromYaml(std::vector<CategoryData>& categories,
|
||||
bool loadLabelsListFromYaml(QStringList& labels,
|
||||
EtxModelfiles& modelFiles,
|
||||
const QByteArray& data);
|
||||
|
||||
bool loadModelFromYaml(ModelData& model, const QByteArray& data);
|
||||
bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data);
|
||||
|
||||
bool writeModelsListToYaml(const std::vector<CategoryData>& categories,
|
||||
const EtxModelfiles& modelFiles,
|
||||
QByteArray& data);
|
||||
bool writeLabelsListToYaml(const RadioData &radioData, QByteArray& data);
|
||||
|
||||
bool writeModelToYaml(const ModelData& model, QByteArray& data);
|
||||
bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data);
|
||||
|
||||
@@ -743,6 +743,7 @@ Node convert<ModelData>::encode(const ModelData& rhs)
|
||||
Node header;
|
||||
header["name"] = rhs.name;
|
||||
header["bitmap"] = rhs.bitmap;
|
||||
header["labels"] = rhs.labels;
|
||||
|
||||
for (int i=0; i<CPN_MAX_MODULES; i++) {
|
||||
if (rhs.moduleData[i].protocol != PULSES_OFF) {
|
||||
@@ -986,6 +987,7 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
|
||||
if (header.IsMap()) {
|
||||
header["name"] >> rhs.name;
|
||||
header["bitmap"] >> rhs.bitmap;
|
||||
header["labels"] >> rhs.labels;
|
||||
header["modelId"] >> modelIds;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ enum Capability {
|
||||
HasMixerExpo,
|
||||
HasBatMeterRange,
|
||||
DangerousFunctions,
|
||||
HasModelCategories,
|
||||
HasModelLabels,
|
||||
HasSwitchableJack,
|
||||
HasSportConnector,
|
||||
PwrButtonPress,
|
||||
|
||||
@@ -111,9 +111,9 @@ class ModelData {
|
||||
|
||||
char semver[8 + 1];
|
||||
bool used;
|
||||
int category;
|
||||
char name[15+1];
|
||||
char filename[16+1];
|
||||
char labels[100];
|
||||
int modelIndex; // Companion only, temporary index position managed by data model.
|
||||
|
||||
TimerData timers[CPN_MAX_TIMERS];
|
||||
|
||||
@@ -742,7 +742,7 @@ int OpenTxFirmware::getCapability(::Capability capability)
|
||||
return (IS_HORUS_OR_TARANIS(board) ? true : id.contains("battgraph"));
|
||||
case DangerousFunctions:
|
||||
return id.contains("danger") ? 1 : 0;
|
||||
case HasModelCategories:
|
||||
case HasModelLabels:
|
||||
return IS_FAMILY_HORUS_OR_T16(board);
|
||||
case HasSwitchableJack:
|
||||
return IS_TARANIS_XLITES(board);
|
||||
|
||||
@@ -94,13 +94,6 @@ void RadioData::convert(RadioDataConversionState & cstate)
|
||||
models[i].convert(cstate.withModelIndex(i));
|
||||
}
|
||||
|
||||
if (categories.size() == 0) {
|
||||
categories.push_back(CategoryData(qPrintable(tr("Models"))));
|
||||
for (unsigned i=0; i<models.size(); i++) {
|
||||
models[i].category = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_FAMILY_HORUS_OR_T16(cstate.toType)) {
|
||||
fixModelFilenames();
|
||||
}
|
||||
@@ -110,3 +103,104 @@ void RadioData::convert(RadioDataConversionState & cstate)
|
||||
models.resize(getCurrentFirmware()->getCapability(Models));
|
||||
}
|
||||
}
|
||||
|
||||
void RadioData::addLabel(QString label)
|
||||
{
|
||||
if(!labels.contains(label))
|
||||
labels.append(label);
|
||||
}
|
||||
|
||||
bool RadioData::deleteLabel(QString label)
|
||||
{
|
||||
bool deleted = false;
|
||||
// Remove labels in the models
|
||||
for(auto& model : models) {
|
||||
QStringList modelLabels = QString(model.labels).split(',',QString::SkipEmptyParts);
|
||||
if(modelLabels.contains(label))
|
||||
deleted = true;
|
||||
modelLabels.removeAll(label);
|
||||
strcpy(model.labels, QString(modelLabels.join(',')).toLocal8Bit().data());
|
||||
}
|
||||
|
||||
// Remove the label from the global list
|
||||
labels.removeAll(label);
|
||||
|
||||
// If no labels remain, add a Favorites one
|
||||
if(!labels.size()) {
|
||||
addLabel(tr("Favorites"));
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
bool RadioData::deleteLabel(int index)
|
||||
{
|
||||
if(index >= labels.size()) return false;
|
||||
QString modelLabel = labels.at(index);
|
||||
return deleteLabel(modelLabel);
|
||||
}
|
||||
|
||||
bool RadioData::renameLabel(QString from, QString to)
|
||||
{
|
||||
bool success = true;
|
||||
int lengthdiff = to.size() - from.size();
|
||||
|
||||
// Check that rename is possible, not too long
|
||||
for(auto& model : models) {
|
||||
if((int)strlen(model.labels) + lengthdiff > (int)sizeof(model.labels) - 1) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if(success) {
|
||||
for(auto& model : models) {
|
||||
QStringList modelLabels = QString(model.labels).split(',',QString::SkipEmptyParts);
|
||||
int ind = modelLabels.indexOf(from); // TOOD: Make sure it will fit
|
||||
if(ind != -1) {
|
||||
modelLabels.replace(ind, to);
|
||||
strcpy(model.labels, QString(modelLabels.join(',')).toLocal8Bit().data());
|
||||
}
|
||||
}
|
||||
int ind = labels.indexOf(from);
|
||||
if(ind != -1) {
|
||||
labels.replace(ind, to);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool RadioData::renameLabel(int index, QString to)
|
||||
{
|
||||
if(index >= labels.size()) return false;
|
||||
QString from = labels.at(index);
|
||||
return renameLabel(from, to);
|
||||
}
|
||||
|
||||
bool RadioData::addLabelToModel(int index, QString label)
|
||||
{
|
||||
if(index >= models.size()) return false;
|
||||
|
||||
char *modelLabelCsv = models[index].labels;
|
||||
// Make sure it will fit
|
||||
if(strlen(modelLabelCsv) + label.size() + 1 < sizeof(models[index].labels)-1) {
|
||||
QStringList modelLabels = QString(modelLabelCsv).split(',',QString::SkipEmptyParts);
|
||||
if(!modelLabels.contains(label)) {
|
||||
modelLabels.append(label);
|
||||
strcpy(models[index].labels, QString(modelLabels.join(',')).toLocal8Bit().data());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RadioData::removeLabelFromModel(int index, QString label)
|
||||
{
|
||||
if(index >= models.size()) return false;
|
||||
|
||||
char *modelLabelCsv = models[index].labels;
|
||||
QStringList modelLabels = QString(modelLabelCsv).split(',',QString::SkipEmptyParts);
|
||||
if(modelLabels.contains(label)) {
|
||||
modelLabels.removeAll(label);
|
||||
strcpy(models[index].labels, QString(modelLabels.join(',')).toLocal8Bit().data());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "generalsettings.h"
|
||||
#include "modeldata.h"
|
||||
#include "labels.h"
|
||||
|
||||
#include "datahelpers.h" // required for getElementName
|
||||
|
||||
@@ -9,15 +10,6 @@
|
||||
|
||||
class RadioDataConversionState;
|
||||
|
||||
class CategoryData {
|
||||
public:
|
||||
CategoryData(const char * name) {
|
||||
memset(this->name, 0, sizeof(CategoryData::name));
|
||||
strncpy(this->name, name, sizeof(CategoryData::name)-1);
|
||||
}
|
||||
char name[15+1];
|
||||
};
|
||||
|
||||
class RadioData {
|
||||
Q_DECLARE_TR_FUNCTIONS(RadioData)
|
||||
|
||||
@@ -25,11 +17,19 @@ class RadioData {
|
||||
RadioData();
|
||||
|
||||
GeneralSettings generalSettings;
|
||||
std::vector<CategoryData> categories;
|
||||
QStringList labels;
|
||||
std::vector<ModelData> models;
|
||||
|
||||
void convert(RadioDataConversionState & cstate);
|
||||
|
||||
void addLabel(QString label);
|
||||
bool deleteLabel(QString label);
|
||||
bool deleteLabel(int index);
|
||||
bool renameLabel(QString from, QString to);
|
||||
bool renameLabel(int index, QString to);
|
||||
bool addLabelToModel(int index, QString label);
|
||||
bool removeLabelFromModel(int index, QString label);
|
||||
|
||||
void setCurrentModel(unsigned int index);
|
||||
void fixModelFilenames();
|
||||
QString getNextModelFilename();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QItemSelectionModel>
|
||||
|
||||
#include "radiodata.h"
|
||||
|
||||
class RadioData;
|
||||
|
||||
typedef struct {
|
||||
QString label;
|
||||
QModelIndex index;
|
||||
int radioLabelIndex;
|
||||
} LabelItem;
|
||||
|
||||
class LabelsModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LabelsModel(QItemSelectionModel *selectionModel, RadioData *radioData, QObject *parent = nullptr);
|
||||
~LabelsModel();
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex &index) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
Qt::DropActions supportedDropActions() const override;
|
||||
QStringList mimeTypes() const override;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
||||
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
||||
bool insertRows(int row, int count, const QModelIndex &parent) override;
|
||||
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
||||
|
||||
private slots:
|
||||
void buildLabelsList();
|
||||
void modelsSelectionChanged();
|
||||
|
||||
signals:
|
||||
void modelChanged(int index);
|
||||
|
||||
private:
|
||||
QItemSelectionModel *modelsSelection;
|
||||
RadioData *radioData;
|
||||
int selectedModel;
|
||||
QList<QModelIndex> modelIndices;
|
||||
QList<LabelItem> labels;
|
||||
};
|
||||
+124
-159
@@ -33,6 +33,7 @@
|
||||
#include "radiointerface.h"
|
||||
#include "radiodataconversionstate.h"
|
||||
#include "filtereditemmodels.h"
|
||||
#include "labels.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <ExportableTableView>
|
||||
@@ -41,14 +42,16 @@ MdiChild::MdiChild(QWidget * parent, QWidget * parentWin, Qt::WindowFlags f):
|
||||
QWidget(parent, f),
|
||||
ui(new Ui::MdiChild),
|
||||
modelsListModel(NULL),
|
||||
labelsListModel(NULL),
|
||||
parentWindow(parentWin),
|
||||
radioToolbar(NULL),
|
||||
categoriesToolbar(NULL),
|
||||
modelsToolbar(NULL),
|
||||
labelsToolbar(NULL),
|
||||
lblLabels(NULL),
|
||||
|
||||
firmware(getCurrentFirmware()),
|
||||
lastSelectedModel(-1),
|
||||
isUntitled(true),
|
||||
showCatToolbar(true),
|
||||
forceCloseFlag(false),
|
||||
stateDataVersion(1)
|
||||
{
|
||||
@@ -73,6 +76,7 @@ MdiChild::MdiChild(QWidget * parent, QWidget * parentWin, Qt::WindowFlags f):
|
||||
ui->modelsList->setDragDropMode(QAbstractItemView::DragDrop);
|
||||
ui->modelsList->setStyle(new ItemViewProxyStyle(ui->modelsList->style()));
|
||||
ui->modelsList->setStyleSheet("QTreeView::item {margin: 2px 0;}"); // a little more space for our drop indicators
|
||||
ui->lstLabels->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
retranslateUi();
|
||||
|
||||
@@ -82,6 +86,7 @@ MdiChild::MdiChild(QWidget * parent, QWidget * parentWin, Qt::WindowFlags f):
|
||||
connect(ui->modelsList, &QTreeView::pressed, this, &MdiChild::onItemSelected);
|
||||
connect(ui->modelsList->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &MdiChild::onCurrentItemChanged);
|
||||
connect(QGuiApplication::clipboard(), &QClipboard::dataChanged, this, &MdiChild::updateNavigation);
|
||||
connect(ui->lstLabels, &QTreeView::customContextMenuRequested, this, &MdiChild::showLabelsContextMenu);
|
||||
|
||||
if (!(isMaximized() || isMinimized())) {
|
||||
QByteArray geo = g.mdiWinGeo();
|
||||
@@ -103,8 +108,7 @@ MdiChild::MdiChild(QWidget * parent, QWidget * parentWin, Qt::WindowFlags f):
|
||||
stream >> ver;
|
||||
if (ver <= stateDataVersion) {
|
||||
bool visMdl, visGen;
|
||||
stream >> showCatToolbar >> visMdl >> visGen;
|
||||
categoriesToolbar->setVisible(showCatToolbar);
|
||||
stream >> showLabelToolbar >> visMdl >> visGen;
|
||||
modelsToolbar->setVisible(visMdl);
|
||||
radioToolbar->setVisible(visGen);
|
||||
}
|
||||
@@ -141,7 +145,7 @@ void MdiChild::closeEvent(QCloseEvent *event)
|
||||
QByteArray state;
|
||||
QDataStream stream(&state, QIODevice::WriteOnly);
|
||||
stream << stateDataVersion
|
||||
<< (firmware->getCapability(Capability::HasModelCategories) ? categoriesToolbar->isVisible() : showCatToolbar)
|
||||
<< false
|
||||
<< modelsToolbar->isVisible()
|
||||
<< radioToolbar->isVisible();
|
||||
g.mdiWinState(state);
|
||||
@@ -212,16 +216,13 @@ void MdiChild::setupNavigation()
|
||||
addAct(ACT_ITM_EDT, "edit.png", SLOT(edit()), Qt::Key_Enter);
|
||||
addAct(ACT_ITM_DEL, "clear.png", SLOT(confirmDelete()), QKeySequence::Delete);
|
||||
|
||||
addAct(ACT_CAT_ADD, "add.png", SLOT(categoryAdd()), tr("Alt+C"));
|
||||
//addAct(ACT_CAT_EDT, "edit.png", SLOT(edit()), Qt::Key_Enter);
|
||||
//addAct(ACT_CAT_DEL, "clear.png", SLOT(confirmDelete()), QKeySequence::Delete);
|
||||
action[ACT_CAT_SEP] = new QAction(this);
|
||||
action[ACT_CAT_SEP]->setSeparator(true);
|
||||
|
||||
addAct(ACT_MDL_ADD, "add.png", SLOT(modelAdd()), tr("Alt+A"));
|
||||
addAct(ACT_MDL_RTR, "open.png", SLOT(loadBackup()), tr("Alt+R"));
|
||||
addAct(ACT_MDL_WIZ, "wizard.png", SLOT(wizardEdit()), tr("Alt+W"));
|
||||
|
||||
addAct(ACT_LBL_ADD, "add.png", SLOT(labelAdd()), tr("Alt-L"));
|
||||
addAct(ACT_LBL_DEL, "clear.png", SLOT(labelDelete()), tr("Alt-L"));
|
||||
|
||||
addAct(ACT_MDL_DFT, "currentmodel.png", SLOT(setDefault()), tr("Alt+U"));
|
||||
addAct(ACT_MDL_PRT, "print.png", SLOT(print()), QKeySequence::Print);
|
||||
addAct(ACT_MDL_SIM, "simulate.png", SLOT(modelSimulate()), tr("Alt+S"));
|
||||
@@ -243,16 +244,24 @@ void MdiChild::setupNavigation()
|
||||
QSize tbIcnSz(16, 16);
|
||||
QString tbCss = "QToolBar {border: 1px solid palette(midlight);}";
|
||||
|
||||
if (categoriesToolbar)
|
||||
categoriesToolbar->deleteLater();
|
||||
categoriesToolbar = new QToolBar(this);
|
||||
categoriesToolbar->setObjectName("TB_CATEGORIES");
|
||||
categoriesToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
categoriesToolbar->setFloatable(false);
|
||||
categoriesToolbar->setIconSize(tbIcnSz);
|
||||
categoriesToolbar->setStyleSheet(tbCss);
|
||||
categoriesToolbar->addAction(getAction(ACT_CAT_ADD));
|
||||
ui->topToolbarLayout->addWidget(categoriesToolbar);
|
||||
// Add labels Label to bottom layout
|
||||
if(lblLabels)
|
||||
lblLabels->deleteLater();
|
||||
lblLabels = new QLabel(tr("Labels"));
|
||||
lblLabels->setStyleSheet("font-weight: bold");
|
||||
ui->bottomLayout->addWidget(lblLabels);
|
||||
|
||||
if(labelsToolbar)
|
||||
labelsToolbar->deleteLater();
|
||||
labelsToolbar = new QToolBar(this);
|
||||
labelsToolbar->setObjectName("TB_LABELS");
|
||||
labelsToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
labelsToolbar->setFloatable(false);
|
||||
labelsToolbar->setIconSize(tbIcnSz);
|
||||
labelsToolbar->setStyleSheet(tbCss);
|
||||
labelsToolbar->addAction(getAction(ACT_LBL_ADD));
|
||||
labelsToolbar->addAction(getAction(ACT_LBL_DEL));
|
||||
ui->bottomLayout->addWidget(labelsToolbar);
|
||||
|
||||
if (radioToolbar)
|
||||
radioToolbar->deleteLater();
|
||||
@@ -282,7 +291,7 @@ void MdiChild::setupNavigation()
|
||||
modelsToolbar->setFloatable(false);
|
||||
modelsToolbar->setIconSize(tbIcnSz);
|
||||
modelsToolbar->setStyleSheet(tbCss);
|
||||
modelsToolbar->addActions(getEditActions(false));
|
||||
modelsToolbar->addActions(getEditActions());
|
||||
modelsToolbar->addSeparator();
|
||||
modelsToolbar->addActions(getModelActions());
|
||||
if ((btn = qobject_cast<QToolButton *>(modelsToolbar->widgetForAction(action[ACT_MDL_ADD])))) {
|
||||
@@ -293,7 +302,6 @@ void MdiChild::setupNavigation()
|
||||
}
|
||||
ui->botToolbarLayout->addWidget(modelsToolbar);
|
||||
|
||||
connect(categoriesToolbar, &QToolBar::visibilityChanged, this, &MdiChild::adjustToolbarLayout);
|
||||
connect(radioToolbar, &QToolBar::visibilityChanged, this, &MdiChild::adjustToolbarLayout);
|
||||
connect(modelsToolbar, &QToolBar::visibilityChanged, this, &MdiChild::adjustToolbarLayout);
|
||||
}
|
||||
@@ -301,73 +309,32 @@ void MdiChild::setupNavigation()
|
||||
void MdiChild::updateNavigation()
|
||||
{
|
||||
const int modelsSelected = countSelectedModels();
|
||||
const int catsSelected = countSelectedCats();
|
||||
const bool singleModelSelected = (modelsSelected == 1);
|
||||
const bool hasModelSlotSelcted = (getCurrentModel() > -1);
|
||||
const bool hasCats = firmware->getCapability(Capability::HasModelCategories);
|
||||
const bool hasCatSelected = hasCats && modelsListModel->isCategoryType(getCurrentIndex());
|
||||
const bool hasLabels = firmware->getCapability(Capability::HasModelLabels);
|
||||
const int numOnClipbrd = modelsListModel->countModelsInMimeData(QApplication::clipboard()->mimeData());
|
||||
const QString modelsRemvTxt = tr("%n Model(s)", "As in \"Copy 3 Models\" or \"Cut 1 Model\" or \"Delete 3 Models\" action).", modelsSelected);
|
||||
const QString modelsAddTxt = tr("%n Model(s)", "As in \"Paste 3 Models\" or \"Insert 1 Model.\"", numOnClipbrd);
|
||||
const QString catsRemvTxt = tr("%n Category(ies)", "As in \"Delete 3 Categories\" or \"Delete 1 Category.\"", catsSelected);
|
||||
static const QString noSelection = tr("Nothing selected");
|
||||
static const QString sp = " ";
|
||||
static const QString ns;
|
||||
|
||||
categoriesToolbar->setVisible(hasCats && showCatToolbar);
|
||||
|
||||
labelsToolbar->setVisible(hasLabels);
|
||||
ui->lstLabels->setVisible(hasLabels);
|
||||
lblLabels->setVisible(hasLabels);
|
||||
action[ACT_GEN_PST]->setEnabled(hasClipboardData(1));
|
||||
|
||||
action[ACT_ITM_EDT]->setEnabled(singleModelSelected || catsSelected == 1);
|
||||
action[ACT_ITM_EDT]->setText((hasCatSelected ? tr("Rename Category") : modelsSelected ? tr("Edit Model") : noSelection));
|
||||
action[ACT_ITM_DEL]->setEnabled(modelsSelected || catsSelected);
|
||||
action[ACT_ITM_DEL]->setText((action[ACT_ITM_DEL]->isEnabled() ? tr("Delete") % " " % (hasCatSelected ? catsRemvTxt : modelsRemvTxt) : noSelection));
|
||||
|
||||
action[ACT_CAT_ADD]->setVisible(hasCats);
|
||||
action[ACT_CAT_SEP]->setVisible(hasCats);
|
||||
// action[ACT_CAT_EDT]->setVisible(hasCats);
|
||||
// action[ACT_CAT_EDT]->setEnabled(catsSelected == 1);
|
||||
// action[ACT_CAT_DEL]->setVisible(hasCats);
|
||||
// action[ACT_CAT_DEL]->setEnabled(catsSelected);
|
||||
// action[ACT_CAT_DEL]->setText((hasCatSelected ? tr("Delete") % " " % catsRemTxt : noSelection));
|
||||
|
||||
action[ACT_MDL_CUT]->setEnabled(modelsSelected);
|
||||
action[ACT_MDL_CUT]->setText(tr("Cut") % (modelsSelected ? sp % modelsRemvTxt : ns));
|
||||
action[ACT_MDL_CPY]->setEnabled(modelsSelected);
|
||||
action[ACT_MDL_CPY]->setText(tr("Copy") % (modelsSelected ? sp % modelsRemvTxt : ns));
|
||||
action[ACT_MDL_PST]->setEnabled(numOnClipbrd);
|
||||
action[ACT_MDL_PST]->setText(tr("Paste") % (numOnClipbrd ? sp % modelsAddTxt : ns));
|
||||
action[ACT_MDL_INS]->setEnabled(numOnClipbrd && (hasModelSlotSelcted || catsSelected));
|
||||
action[ACT_MDL_INS]->setEnabled(numOnClipbrd && hasModelSlotSelcted);
|
||||
action[ACT_MDL_INS]->setText(tr("Insert") % QString(action[ACT_MDL_INS]->isEnabled() ? sp % modelsAddTxt : ns));
|
||||
action[ACT_MDL_SAV]->setEnabled(modelsSelected);
|
||||
action[ACT_MDL_SAV]->setText(tr("Save") % (modelsSelected ? sp % modelsRemvTxt : ns));
|
||||
|
||||
if (hasCats && action[ACT_MDL_MOV]->menu()) {
|
||||
action[ACT_MDL_MOV]->setVisible(true);
|
||||
QModelIndex modelIndex = getCurrentIndex();
|
||||
QMenu * catsMenu = action[ACT_MDL_MOV]->menu();
|
||||
catsMenu->clear();
|
||||
if (modelsSelected && modelsListModel && radioData.categories.size() > 1) {
|
||||
action[ACT_MDL_MOV]->setEnabled(true);
|
||||
for (unsigned i=0; i < radioData.categories.size(); ++i) {
|
||||
QAction * act = catsMenu->addAction(QString(radioData.categories[i].name), this, SLOT(onModelMoveToCategory()));
|
||||
act->setProperty("categoryId", i);
|
||||
if ((int)i < modelsListModel->getCategoryIndex(modelIndex))
|
||||
act->setIcon(CompanionIcon("moveup.png"));
|
||||
else if ((int)i > modelsListModel->getCategoryIndex(modelIndex))
|
||||
act->setIcon(CompanionIcon("movedown.png"));
|
||||
else
|
||||
act->setEnabled(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
action[ACT_MDL_MOV]->setDisabled(true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
action[ACT_MDL_MOV]->setVisible(false);
|
||||
}
|
||||
|
||||
action[ACT_MDL_MOV]->setVisible(false);
|
||||
action[ACT_MDL_DUP]->setEnabled(singleModelSelected);
|
||||
action[ACT_MDL_RTR]->setEnabled(singleModelSelected);
|
||||
action[ACT_MDL_WIZ]->setEnabled(singleModelSelected);
|
||||
@@ -383,9 +350,11 @@ void MdiChild::retranslateUi()
|
||||
action[ACT_GEN_PST]->setText(tr("Paste Radio Settings"));
|
||||
action[ACT_GEN_SIM]->setText(tr("Simulate Radio"));
|
||||
|
||||
action[ACT_CAT_ADD]->setText(tr("Add Category"));
|
||||
action[ACT_CAT_ADD]->setIconText(tr("Category"));
|
||||
//action[ACT_CAT_EDT]->setText(tr("Rename Category"));
|
||||
action[ACT_ITM_EDT]->setText(tr("Edit Model"));
|
||||
action[ACT_ITM_DEL]->setText(tr("Delete"));
|
||||
|
||||
action[ACT_LBL_ADD]->setText(tr("Add Label"));
|
||||
action[ACT_LBL_DEL]->setText(tr("Delete Label"));
|
||||
|
||||
action[ACT_MDL_ADD]->setText(tr("Add Model"));
|
||||
action[ACT_MDL_ADD]->setIconText(tr("Model"));
|
||||
@@ -398,9 +367,6 @@ void MdiChild::retranslateUi()
|
||||
action[ACT_MDL_SIM]->setText(tr("Simulate Model"));
|
||||
action[ACT_MDL_DUP]->setText(tr("Duplicate Model"));
|
||||
|
||||
action[ACT_MDL_MOV]->setText(tr("Move to Category"));
|
||||
|
||||
categoriesToolbar->setWindowTitle(tr("Show Category Actions Toolbar"));
|
||||
radioToolbar->setWindowTitle(tr("Show Radio Actions Toolbar"));
|
||||
modelsToolbar->setWindowTitle(tr("Show Model Actions Toolbar"));
|
||||
}
|
||||
@@ -415,13 +381,9 @@ QList<QAction *> MdiChild::getGeneralActions()
|
||||
return actGrp;
|
||||
}
|
||||
|
||||
QList<QAction *> MdiChild::getEditActions(bool incCatNew)
|
||||
QList<QAction *> MdiChild::getEditActions()
|
||||
{
|
||||
QList<QAction *> actGrp;
|
||||
if (incCatNew) {
|
||||
actGrp.append(getAction(ACT_CAT_ADD));
|
||||
actGrp.append(getAction(ACT_CAT_SEP));
|
||||
}
|
||||
actGrp.append(action[ACT_MDL_ADD]);
|
||||
QAction * sep2 = new QAction(this);
|
||||
sep2->setSeparator(true);
|
||||
@@ -449,15 +411,13 @@ QList<QAction *> MdiChild::getModelActions()
|
||||
return actGrp;
|
||||
}
|
||||
|
||||
//QList<QAction *> MdiChild::getCategoryActions()
|
||||
//{
|
||||
// QList<QAction *> actGrp;
|
||||
// actGrp.append(getAction(ACT_CAT_ADD));
|
||||
// actGrp.append(getAction(ACT_CAT_EDT));
|
||||
// actGrp.append(getAction(ACT_CAT_DEL));
|
||||
// actGrp.append(getAction(ACT_CAT_SEP));
|
||||
// return actGrp;
|
||||
//}
|
||||
QList<QAction *> MdiChild::getLabelsActions()
|
||||
{
|
||||
QList<QAction *> actGrp;
|
||||
actGrp.append(getAction(ACT_LBL_ADD));
|
||||
actGrp.append(getAction(ACT_LBL_DEL));
|
||||
return actGrp;
|
||||
}
|
||||
|
||||
QAction * MdiChild::getAction(const MdiChild::Actions type)
|
||||
{
|
||||
@@ -474,15 +434,6 @@ void MdiChild::showModelsListContextMenu(const QPoint & pos)
|
||||
|
||||
updateNavigation();
|
||||
|
||||
if (firmware->getCapability(Capability::HasModelCategories)) {
|
||||
contextMenu.addAction(action[ACT_CAT_ADD]);
|
||||
if(modelsListModel->isCategoryType(modelIndex)) {
|
||||
contextMenu.addAction(action[ACT_ITM_EDT]);
|
||||
contextMenu.addAction(action[ACT_ITM_DEL]);
|
||||
}
|
||||
contextMenu.addSeparator();
|
||||
}
|
||||
|
||||
if (modelsListModel->isModelType(modelIndex)) {
|
||||
contextMenu.addActions(getEditActions());
|
||||
if (countSelectedModels() == 1) {
|
||||
@@ -500,11 +451,20 @@ void MdiChild::showModelsListContextMenu(const QPoint & pos)
|
||||
contextMenu.exec(ui->modelsList->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void MdiChild::showLabelsContextMenu(const QPoint &pos)
|
||||
{
|
||||
QMenu contextMenu;
|
||||
|
||||
contextMenu.addAction(action[ACT_LBL_ADD]);
|
||||
contextMenu.addAction(action[ACT_LBL_DEL]);
|
||||
|
||||
if (!contextMenu.isEmpty())
|
||||
contextMenu.exec(ui->lstLabels->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void MdiChild::showContextMenu(const QPoint & pos)
|
||||
{
|
||||
QMenu contextMenu;
|
||||
if (firmware->getCapability(Capability::HasModelCategories))
|
||||
contextMenu.addAction(categoriesToolbar->toggleViewAction());
|
||||
contextMenu.addAction(modelsToolbar->toggleViewAction());
|
||||
contextMenu.addAction(radioToolbar->toggleViewAction());
|
||||
if (!contextMenu.isEmpty())
|
||||
@@ -534,26 +494,39 @@ void MdiChild::initModelsList()
|
||||
if (modelsListModel)
|
||||
delete modelsListModel;
|
||||
|
||||
modelsListModel = new TreeModel(&radioData, this);
|
||||
connect(modelsListModel, &TreeModel::modelsDropped, this, &MdiChild::pasteModelData);
|
||||
connect(modelsListModel, &TreeModel::modelsRemoved, this, &MdiChild::deleteModels);
|
||||
connect(modelsListModel, &TreeModel::refreshRequested, this, &MdiChild::refresh);
|
||||
modelsListModel = new ModelsListModel(&radioData, this);
|
||||
connect(modelsListModel, &ModelsListModel::modelsDropped, this, &MdiChild::pasteModelData);
|
||||
connect(modelsListModel, &ModelsListModel::modelsRemoved, this, &MdiChild::deleteModels);
|
||||
connect(modelsListModel, &ModelsListModel::refreshRequested, this, &MdiChild::refresh);
|
||||
connect(modelsListModel, &QAbstractItemModel::dataChanged, this, &MdiChild::onDataChanged);
|
||||
|
||||
ui->modelsList->setModel(modelsListModel);
|
||||
if (IS_FAMILY_HORUS_OR_T16(board)) {
|
||||
ui->modelsList->setIndentation(20);
|
||||
// ui->modelsList->resetIndentation(); // introduced in next Qt versions ...
|
||||
}
|
||||
else {
|
||||
ui->modelsList->setIndentation(0);
|
||||
}
|
||||
ui->modelsList->selectionModel()->currentIndex().row();
|
||||
|
||||
// Labels Editor + Model
|
||||
if(labelsListModel)
|
||||
delete labelsListModel;
|
||||
labelsListModel = new LabelsModel(ui->modelsList->selectionModel(),
|
||||
&radioData, this);
|
||||
connect(labelsListModel, &LabelsModel::modelChanged, this, &MdiChild::refresh);
|
||||
ui->lstLabels->setModel(labelsListModel);
|
||||
ui->lstLabels->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
ui->lstLabels->setDragEnabled(true);
|
||||
ui->lstLabels->setAcceptDrops(true);
|
||||
ui->lstLabels->setDropIndicatorShown(true);
|
||||
ui->lstLabels->setDragDropOverwriteMode(false);
|
||||
ui->lstLabels->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
ui->lstLabels->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
|
||||
|
||||
ui->modelsList->setIndentation(0);
|
||||
|
||||
refresh();
|
||||
|
||||
if (firmware->getCapability(Capability::HasModelCategories)) {
|
||||
if (firmware->getCapability(Capability::HasModelLabels)) {
|
||||
ui->modelsList->header()->resizeSection(0, ui->modelsList->header()->sectionSize(0) * 2); // pad out categories and model names
|
||||
}
|
||||
else {
|
||||
} else if (firmware->getCapability(Capability::HasModelLabels)) {
|
||||
|
||||
} 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
|
||||
}
|
||||
@@ -602,7 +575,10 @@ void MdiChild::onCurrentItemChanged(const QModelIndex &, const QModelIndex &)
|
||||
|
||||
void MdiChild::onDataChanged(const QModelIndex & index)
|
||||
{
|
||||
if (!modelsListModel->isCategoryType(index))
|
||||
return;
|
||||
|
||||
// TODO ***
|
||||
/*if (!modelsListModel->isCategoryType(index))
|
||||
return;
|
||||
|
||||
int categoryIndex = modelsListModel->getCategoryIndex(index);
|
||||
@@ -612,7 +588,7 @@ void MdiChild::onDataChanged(const QModelIndex & index)
|
||||
strcpy(radioData.categories[categoryIndex].name, modelsListModel->data(index, 0).toString().left(sizeof(CategoryData::name)-1).toStdString().c_str());
|
||||
|
||||
setWindowModified(true);
|
||||
emit modified();
|
||||
emit modified();*/
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -624,7 +600,7 @@ QModelIndex MdiChild::getCurrentIndex() const
|
||||
return ui->modelsList->selectionModel()->currentIndex();
|
||||
}
|
||||
|
||||
int MdiChild::getCurrentCategory() const
|
||||
/*int MdiChild::getCurrentCategory() const
|
||||
{
|
||||
return modelsListModel->getCategoryIndex(getCurrentIndex());
|
||||
}
|
||||
@@ -653,7 +629,7 @@ QVector<int> MdiChild::getSelectedCategories() const
|
||||
cats.append(modelsListModel->getCategoryIndex(index));
|
||||
}
|
||||
return cats;
|
||||
}
|
||||
}*/
|
||||
|
||||
int MdiChild::getCurrentModel() const
|
||||
{
|
||||
@@ -736,9 +712,10 @@ void MdiChild::onFirmwareChanged()
|
||||
* Categories CRUD
|
||||
*/
|
||||
|
||||
/*
|
||||
void MdiChild::categoryAdd()
|
||||
{
|
||||
/*: Translators do NOT use accent for this, this is the default category name on Horus. */
|
||||
// Translators do NOT use accent for this, this is the default category name on Horus.
|
||||
CategoryData category(qPrintable(tr("New category")));
|
||||
radioData.categories.push_back(category);
|
||||
setModified();
|
||||
@@ -799,7 +776,7 @@ void MdiChild::deleteSelectedCats()
|
||||
}
|
||||
if (modified)
|
||||
setModified();
|
||||
}
|
||||
}*/
|
||||
|
||||
/*
|
||||
* Models CRUD
|
||||
@@ -827,8 +804,8 @@ void MdiChild::findNewDefaultModel(const unsigned startAt)
|
||||
radioData.setCurrentModel(0);
|
||||
}
|
||||
|
||||
// NOTE: insertModelRows() does not update the TreeModel, only modifies radioData.models[] array by inserting row(s) of blank model(s).
|
||||
// TreeModel::refresh() needs to be called at some point afterwards to sync the data.
|
||||
// NOTE: insertModelRows() does not update the ModelsListModel, only modifies radioData.models[] array by inserting row(s) of blank model(s).
|
||||
// ModelsListModel::refresh() needs to be called at some point afterwards to sync the data.
|
||||
// This invalidates any model indices stored previously.
|
||||
bool MdiChild::insertModelRows(int atModelIdx, int count)
|
||||
{
|
||||
@@ -859,7 +836,7 @@ bool MdiChild::insertModelRows(int atModelIdx, int count)
|
||||
|
||||
// Finds the first empty slot and inserts the model into it. In case of category-style models, will append to end of list.
|
||||
// Return -1 if no slot was found, otherwise new array index.
|
||||
// TreeModel::refresh() needs to be called at some point afterwards to sync the data.
|
||||
// ModelsListModel::refresh() needs to be called at some point afterwards to sync the data.
|
||||
int MdiChild::modelAppend(const ModelData model)
|
||||
{
|
||||
int newIdx = -1;
|
||||
@@ -895,12 +872,6 @@ int MdiChild::newModel(int modelIndex, int categoryIndex)
|
||||
|
||||
bool isNewModel = radioData.models[modelIndex].isEmpty();
|
||||
checkAndInitModel(modelIndex);
|
||||
if (isNewModel && firmware->getCapability(Capability::HasModelCategories) && categoryIndex > -1) {
|
||||
radioData.models[modelIndex].category = categoryIndex;
|
||||
strcpy(radioData.models[modelIndex].filename, radioData.getNextModelFilename().toStdString().c_str());
|
||||
/*: Translators: do NOT use accents here, this is a default model name. */
|
||||
strcpy(radioData.models[modelIndex].name, qPrintable(tr("New model"))); // TODO: Why not just use existing default model name?
|
||||
}
|
||||
// Only set the default model if we just added the first one.
|
||||
if (countUsedModels() == 1) {
|
||||
radioData.setCurrentModel(modelIndex);
|
||||
@@ -926,11 +897,11 @@ int MdiChild::newModel(int modelIndex, int categoryIndex)
|
||||
}
|
||||
|
||||
|
||||
// NOTE: deleteModelss() does not update the TreeModel, only modifies radioData.models[] array by clearing the model data.
|
||||
// NOTE: deleteModelss() does not update the ModelsListModel, only modifies radioData.models[] array by clearing the model data.
|
||||
// If (removeModelSlotsWhenDeleting == true) then removes array rows entirely (and pads w/blank model at the end if needed).
|
||||
// TreeModel::refresh() needs to be called at some point afterwards to sync the data
|
||||
// ModelsListModel::refresh() needs to be called at some point afterwards to sync the data
|
||||
// We delete using stored indexes because actual indexes may change during inserts/deletes.
|
||||
// Obviously this only works before the stored indexes get updated in TreeModel::refresh().
|
||||
// Obviously this only works before the stored indexes get updated in ModelsListModel::refresh().
|
||||
unsigned MdiChild::deleteModels(const QVector<int> modelIndices)
|
||||
{
|
||||
unsigned deletes = 0;
|
||||
@@ -975,6 +946,7 @@ void MdiChild::deleteSelectedModels()
|
||||
deleteModels(getSelectedModels());
|
||||
}
|
||||
|
||||
/*
|
||||
void MdiChild::moveModelsToCategory(const QVector<int> models, const int toCategoryId)
|
||||
{
|
||||
if (toCategoryId < 0 || !models.size())
|
||||
@@ -998,14 +970,14 @@ void MdiChild::moveModelsToCategory(const QVector<int> models, const int toCateg
|
||||
void MdiChild::moveSelectedModelsToCat(const int toCategoryId)
|
||||
{
|
||||
moveModelsToCategory(getSelectedModels(), toCategoryId);
|
||||
}
|
||||
}*/
|
||||
|
||||
unsigned MdiChild::countUsedModels(const int categoryId)
|
||||
{
|
||||
unsigned count = 0;
|
||||
for (unsigned i=0; i < radioData.models.size(); ++i) {
|
||||
ModelData & model = radioData.models.at(i);
|
||||
if (!model.isEmpty() && (categoryId < 0 || model.category == categoryId))
|
||||
if (!model.isEmpty())
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
@@ -1014,12 +986,12 @@ unsigned MdiChild::countUsedModels(const int categoryId)
|
||||
void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row, bool insert, bool move)
|
||||
{
|
||||
QVector<ModelData> modelsList;
|
||||
if (!TreeModel::decodeMimeData(mimeData, &modelsList))
|
||||
if (!ModelsListModel::decodeMimeData(mimeData, &modelsList))
|
||||
return;
|
||||
|
||||
bool modified = false;
|
||||
int modelIdx = modelsListModel->getModelIndex(row);
|
||||
int categoryIdx = modelsListModel->getCategoryIndex(row);
|
||||
// int categoryIdx = modelsListModel->getCategoryIndex(row);
|
||||
unsigned inserts = 0;
|
||||
QVector<int> deletesList;
|
||||
|
||||
@@ -1084,9 +1056,6 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row,
|
||||
// We don't want to create an index value conflict so use an invalid one (it will get updated after we're done here)
|
||||
// this is esp. important because otherwise we may delete this model during a move operation (eg. after a cut)
|
||||
radioData.models[modelIdx].modelIndex = -modelIdx;
|
||||
// Set the destination category, so a user can copy/paste across categories.
|
||||
if (categoryIdx > -1)
|
||||
radioData.models[modelIdx].category = categoryIdx;
|
||||
strcpy(radioData.models[modelIdx].filename, radioData.getNextModelFilename().toStdString().c_str());
|
||||
lastSelectedModel = modelIdx; // after refresh the last pasted model will be selected
|
||||
modified = true;
|
||||
@@ -1117,7 +1086,7 @@ void MdiChild::pasteGeneralData(const QMimeData * mimeData)
|
||||
GeneralSettings gs;
|
||||
bool hasGenSettings = false;
|
||||
|
||||
if (!TreeModel::decodeMimeData(mimeData, NULL, &gs, &hasGenSettings))
|
||||
if (!ModelsListModel::decodeMimeData(mimeData, NULL, &gs, &hasGenSettings))
|
||||
return;
|
||||
|
||||
if (hasGenSettings && askQuestion(tr("Do you want to overwrite radio general settings?")) == QMessageBox::Yes) {
|
||||
@@ -1225,11 +1194,6 @@ void MdiChild::confirmDelete()
|
||||
deleteSelectedModels();
|
||||
}
|
||||
}
|
||||
else if (hasSelectedCat()) {
|
||||
if (askQuestion(tr("Delete %n selected category(ies)?", 0, countSelectedCats())) == QMessageBox::Yes) {
|
||||
deleteSelectedCats();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MdiChild::modelAdd()
|
||||
@@ -1261,7 +1225,7 @@ void MdiChild::modelDuplicate()
|
||||
}
|
||||
}
|
||||
|
||||
void MdiChild::onModelMoveToCategory()
|
||||
/*void MdiChild::onModelMoveToCategory()
|
||||
{
|
||||
if (!sender()) {
|
||||
return;
|
||||
@@ -1271,7 +1235,7 @@ void MdiChild::onModelMoveToCategory()
|
||||
if (ok && toCatId >= 0) {
|
||||
moveSelectedModelsToCat(toCatId);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
void MdiChild::modelEdit()
|
||||
{
|
||||
@@ -1368,10 +1332,6 @@ void MdiChild::newFile(bool createDefaults)
|
||||
isUntitled = true;
|
||||
curFile = QString("document%1.etx").arg(sequenceNumber++);
|
||||
updateTitle();
|
||||
|
||||
if (createDefaults && firmware->getCapability(Capability::HasModelCategories)) {
|
||||
categoryAdd();
|
||||
}
|
||||
}
|
||||
|
||||
bool MdiChild::loadFile(const QString & filename, bool resetCurrentFile)
|
||||
@@ -1775,11 +1735,6 @@ void MdiChild::openModelTemplate(int row)
|
||||
for (int i = 0; i < CPN_MAX_MODULES; i++) {
|
||||
radioData.models[row].moduleData[i].modelId = row + 1;
|
||||
}
|
||||
|
||||
setModified();
|
||||
setSelectedModel(row);
|
||||
|
||||
openModelEditWindow(row);
|
||||
}
|
||||
|
||||
void MdiChild::openModelPrompt(int row)
|
||||
@@ -1826,6 +1781,17 @@ void MdiChild::modelSave()
|
||||
saveSelectedModels();
|
||||
}
|
||||
|
||||
void MdiChild::labelAdd()
|
||||
{
|
||||
labelsListModel->insertRow(0);
|
||||
}
|
||||
|
||||
void MdiChild::labelDelete()
|
||||
{
|
||||
int row = ui->lstLabels->selectionModel()->currentIndex().row();
|
||||
labelsListModel->removeRow(row);
|
||||
}
|
||||
|
||||
unsigned MdiChild::saveModels(const QVector<int> modelIndices)
|
||||
{
|
||||
unsigned saves = 0;
|
||||
@@ -1854,8 +1820,7 @@ unsigned MdiChild::saveModels(const QVector<int> modelIndices)
|
||||
|
||||
++saves;
|
||||
}
|
||||
|
||||
return saves;
|
||||
return saves;
|
||||
}
|
||||
|
||||
bool MdiChild::saveModel(const int modelIndex)
|
||||
|
||||
+18
-19
@@ -23,12 +23,15 @@
|
||||
|
||||
#include "eeprominterface.h"
|
||||
#include "modelslist.h"
|
||||
#include "labels.h"
|
||||
|
||||
#include <QActionGroup>
|
||||
#include <QtGui>
|
||||
#include <QMessageBox>
|
||||
#include <QProxyStyle>
|
||||
#include <QWidget>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QListWidget>
|
||||
|
||||
class QToolBar;
|
||||
|
||||
@@ -36,6 +39,9 @@ namespace Ui {
|
||||
class MdiChild;
|
||||
}
|
||||
|
||||
class LabelsDelegate;
|
||||
class LabelsProxy;
|
||||
|
||||
class MdiChild : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -48,10 +54,8 @@ class MdiChild : public QWidget
|
||||
ACT_GEN_SIM,
|
||||
ACT_ITM_EDT, // edit model/rename category
|
||||
ACT_ITM_DEL, // delete model or cat
|
||||
ACT_CAT_ADD, // category actions...
|
||||
//ACT_CAT_EDT, // not sure these are needed...
|
||||
//ACT_CAT_DEL, // the ACT_ITM_* actions do the same thing
|
||||
ACT_CAT_SEP, // convenience separator shown/hidden with category actions
|
||||
ACT_LBL_ADD,
|
||||
ACT_LBL_DEL,
|
||||
ACT_MDL_ADD, // model actions...
|
||||
ACT_MDL_CPY,
|
||||
ACT_MDL_CUT,
|
||||
@@ -76,9 +80,9 @@ class MdiChild : public QWidget
|
||||
QVector<int> getSelectedCategories() const;
|
||||
QVector<int> getSelectedModels() const;
|
||||
QList<QAction *> getGeneralActions();
|
||||
QList<QAction *> getEditActions(bool incCatNew = true);
|
||||
QList<QAction *> getEditActions();
|
||||
QList<QAction *> getModelActions();
|
||||
//QList<QAction *> getCategoryActions();
|
||||
QList<QAction *> getLabelsActions();
|
||||
QAction * getAction(const Actions type);
|
||||
|
||||
public slots:
|
||||
@@ -109,6 +113,7 @@ class MdiChild : public QWidget
|
||||
void setModified();
|
||||
void retranslateUi();
|
||||
void showModelsListContextMenu(const QPoint & pos);
|
||||
void showLabelsContextMenu(const QPoint & pos);
|
||||
void showContextMenu(const QPoint & pos);
|
||||
void adjustToolbarLayout();
|
||||
|
||||
@@ -130,13 +135,13 @@ class MdiChild : public QWidget
|
||||
void insert();
|
||||
void edit();
|
||||
void confirmDelete();
|
||||
void categoryAdd();
|
||||
void modelAdd();
|
||||
void modelEdit();
|
||||
void modelSave();
|
||||
void labelAdd();
|
||||
void labelDelete();
|
||||
void wizardEdit();
|
||||
void modelDuplicate();
|
||||
void onModelMoveToCategory();
|
||||
|
||||
void openModelWizard(int row = -1);
|
||||
void openModelEditWindow(int row = -1);
|
||||
@@ -159,12 +164,6 @@ class MdiChild : public QWidget
|
||||
int countSelectedModels() const;
|
||||
bool hasSelectedModel();
|
||||
bool setSelectedModel(const int modelIndex);
|
||||
int getCurrentCategory() const;
|
||||
int countSelectedCats() const;
|
||||
bool hasSelectedCat();
|
||||
|
||||
bool deleteCategory(int categoryIndex = -1, QString * error = NULL);
|
||||
void deleteSelectedCats();
|
||||
|
||||
void checkAndInitModel(int row);
|
||||
void findNewDefaultModel(const unsigned startAt = 0);
|
||||
@@ -174,8 +173,6 @@ class MdiChild : public QWidget
|
||||
unsigned deleteModels(const QVector<int> modelIndices);
|
||||
bool deleteModel(const int modelIndex);
|
||||
void deleteSelectedModels();
|
||||
void moveModelsToCategory(const QVector<int> models, const int toCategoryId);
|
||||
void moveSelectedModelsToCat(const int toCategoryId);
|
||||
unsigned countUsedModels(const int categoryId = -1);
|
||||
unsigned saveModels(const QVector<int> modelIndices);
|
||||
bool saveModel(const int modelIndex);
|
||||
@@ -197,22 +194,24 @@ class MdiChild : public QWidget
|
||||
QList<QDialog *> * getModelEditDialogsList();
|
||||
|
||||
Ui::MdiChild * ui;
|
||||
TreeModel * modelsListModel;
|
||||
ModelsListModel * modelsListModel;
|
||||
LabelsModel * labelsListModel;
|
||||
QWidget * parentWindow;
|
||||
|
||||
QString curFile;
|
||||
QVector<int> cutModels;
|
||||
QVector<QAction *> action;
|
||||
QToolBar * radioToolbar;
|
||||
QToolBar * categoriesToolbar;
|
||||
QToolBar * modelsToolbar;
|
||||
QToolBar * labelsToolbar;
|
||||
QLabel *lblLabels;
|
||||
|
||||
Firmware * firmware;
|
||||
RadioData radioData;
|
||||
|
||||
int lastSelectedModel;
|
||||
bool isUntitled;
|
||||
bool showCatToolbar;
|
||||
bool showLabelToolbar;
|
||||
bool forceCloseFlag;
|
||||
const quint16 stateDataVersion;
|
||||
};
|
||||
|
||||
@@ -10,10 +10,7 @@
|
||||
<height>575</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1">
|
||||
<property name="spacing">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="topToolbarLayout">
|
||||
<property name="spacing">
|
||||
@@ -35,6 +32,25 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="bottomLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListView" name="lstLabels">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>150</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
||||
+105
-126
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+19
-19
@@ -25,29 +25,29 @@
|
||||
#include <QMimeData>
|
||||
#include <QUuid>
|
||||
|
||||
class TreeItem
|
||||
class ModelListItem
|
||||
{
|
||||
public:
|
||||
enum TreeItemFlags { MarkedForCut = 0x01 };
|
||||
enum ModelListItemFlags { MarkedForCut = 0x01 };
|
||||
|
||||
explicit TreeItem(const QVector<QVariant> & itemData);
|
||||
explicit TreeItem(TreeItem * parent, int categoryIndex, int modelIndex);
|
||||
~TreeItem();
|
||||
explicit ModelListItem(const QVector<QVariant> & itemData);
|
||||
explicit ModelListItem(ModelListItem * parent, int categoryIndex, int modelIndex);
|
||||
~ModelListItem();
|
||||
|
||||
TreeItem * child(int number);
|
||||
ModelListItem * child(int number);
|
||||
int childCount() const;
|
||||
int columnCount() const;
|
||||
QVariant data(int column) const;
|
||||
TreeItem * appendChild(int categoryIndex, int modelIndex);
|
||||
TreeItem * insertChild(const int row, int categoryIndex, int modelIndex);
|
||||
ModelListItem * appendChild(int categoryIndex, int modelIndex);
|
||||
ModelListItem * insertChild(const int row, int categoryIndex, int modelIndex);
|
||||
bool removeChildren(int position, int count);
|
||||
bool insertChildren(int row, int count);
|
||||
|
||||
int childNumber() const;
|
||||
bool setData(int column, const QVariant &value);
|
||||
|
||||
TreeItem * parent() { return parentItem; }
|
||||
void setParent(TreeItem * p) { parentItem = p; }
|
||||
ModelListItem * parent() { return parentItem; }
|
||||
void setParent(ModelListItem * p) { parentItem = p; }
|
||||
int getModelIndex() const { return modelIndex; }
|
||||
void setModelIndex(int value) { modelIndex = value; }
|
||||
int getCategoryIndex() const { return categoryIndex; }
|
||||
@@ -63,9 +63,9 @@ class TreeItem
|
||||
bool isModel() const;
|
||||
|
||||
private:
|
||||
QList<TreeItem*> childItems;
|
||||
QList<ModelListItem*> childItems;
|
||||
QVector<QVariant> itemData;
|
||||
TreeItem * parentItem;
|
||||
ModelListItem * parentItem;
|
||||
int categoryIndex;
|
||||
int modelIndex;
|
||||
quint16 flags;
|
||||
@@ -73,7 +73,7 @@ class TreeItem
|
||||
};
|
||||
|
||||
|
||||
class TreeModel : public QAbstractItemModel
|
||||
class ModelsListModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -83,8 +83,8 @@ class TreeModel : public QAbstractItemModel
|
||||
quint16 dataVersion;
|
||||
};
|
||||
|
||||
TreeModel(RadioData * radioData, QObject *parent = 0);
|
||||
virtual ~TreeModel();
|
||||
ModelsListModel(RadioData * radioData, QObject *parent = 0);
|
||||
virtual ~ModelsListModel();
|
||||
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
||||
@@ -92,7 +92,7 @@ class TreeModel : public QAbstractItemModel
|
||||
|
||||
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||
virtual QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
|
||||
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||
@@ -146,11 +146,11 @@ class TreeModel : public QAbstractItemModel
|
||||
void onRowsRemoved(const QModelIndex & parent, int first, int last);
|
||||
|
||||
private:
|
||||
TreeItem * getItem(const QModelIndex & index) const;
|
||||
ModelListItem * getItem(const QModelIndex & index) const;
|
||||
bool isModelIdUnique(unsigned modelId, unsigned module, unsigned protocol);
|
||||
|
||||
TreeItem * rootItem;
|
||||
ModelListItem * rootItem;
|
||||
RadioData * radioData;
|
||||
MimeHeaderData mimeHeaderData;
|
||||
bool hasCategories;
|
||||
bool hasLabels;
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ set(storage_NAMES
|
||||
bineeprom
|
||||
eepe
|
||||
hexeeprom
|
||||
categorized
|
||||
labeled
|
||||
sdcard
|
||||
etx
|
||||
otx
|
||||
|
||||
@@ -43,7 +43,7 @@ bool EtxFormat::load(RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = CategorizedStorageFormat::load(radioData);
|
||||
bool result = LabelsStorageFormat::load(radioData);
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return result;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ bool EtxFormat::write(const RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = CategorizedStorageFormat::write(radioData);
|
||||
bool result = LabelsStorageFormat::write(radioData);
|
||||
if (result) {
|
||||
// finalize archive and get contents
|
||||
char * archiveContents;
|
||||
|
||||
@@ -20,17 +20,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "categorized.h"
|
||||
#include "labeled.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class EtxFormat : public CategorizedStorageFormat
|
||||
class EtxFormat : public LabelsStorageFormat
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(EtxFormat)
|
||||
|
||||
public:
|
||||
EtxFormat(const QString & filename):
|
||||
CategorizedStorageFormat(filename)
|
||||
LabelsStorageFormat(filename)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -18,14 +18,14 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "categorized.h"
|
||||
#include "labeled.h"
|
||||
#include "firmwares/opentx/opentxinterface.h"
|
||||
#include "firmwares/edgetx/edgetxinterface.h"
|
||||
#include "miniz.c" // Can only be included once!
|
||||
|
||||
#include <regex>
|
||||
|
||||
bool CategorizedStorageFormat::load(RadioData & radioData)
|
||||
bool LabelsStorageFormat::load(RadioData & radioData)
|
||||
{
|
||||
StorageType st = getStorageType(filename);
|
||||
if (st == STORAGE_TYPE_UNKNOWN) {
|
||||
@@ -39,7 +39,7 @@ bool CategorizedStorageFormat::load(RadioData & radioData)
|
||||
}
|
||||
}
|
||||
|
||||
bool CategorizedStorageFormat::write(const RadioData & radioData)
|
||||
bool LabelsStorageFormat::write(const RadioData & radioData)
|
||||
{
|
||||
StorageType st = getStorageType(filename);
|
||||
if (st == STORAGE_TYPE_ETX || st == STORAGE_TYPE_YML ||
|
||||
@@ -50,7 +50,7 @@ bool CategorizedStorageFormat::write(const RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
StorageType CategorizedStorageFormat::probeFormat()
|
||||
StorageType LabelsStorageFormat::probeFormat()
|
||||
{
|
||||
if (QFile(filename + "/RADIO/radio.yml").exists()) // converted
|
||||
return getStorageType("radio.yml");
|
||||
@@ -60,7 +60,7 @@ StorageType CategorizedStorageFormat::probeFormat()
|
||||
return getStorageType(filename);
|
||||
}
|
||||
|
||||
bool CategorizedStorageFormat::loadBin(RadioData & radioData)
|
||||
bool LabelsStorageFormat::loadBin(RadioData & radioData)
|
||||
{
|
||||
QByteArray radioSettingsBuffer;
|
||||
if (!loadFile(radioSettingsBuffer, "RADIO/radio.bin")) {
|
||||
@@ -82,24 +82,15 @@ bool CategorizedStorageFormat::loadBin(RadioData & radioData)
|
||||
}
|
||||
|
||||
QList<QByteArray> lines = modelsListBuffer.split('\n');
|
||||
int modelIndex = 0;
|
||||
int categoryIndex = -1;
|
||||
foreach (const QByteArray & lineArray, lines) {
|
||||
QString line = QString(lineArray).trimmed();
|
||||
if (line.isEmpty()) continue;
|
||||
// qDebug() << "parsing line" << line;
|
||||
int modelIndex = 0;
|
||||
foreach (const QByteArray & lineArray, lines) {
|
||||
QString line = QString(lineArray).trimmed();
|
||||
if (line.isEmpty()) continue;
|
||||
// qDebug() << "parsing line" << line;
|
||||
|
||||
if (line.startsWith('[') && line.endsWith(']')) {
|
||||
// ignore categories for boards that do not support them
|
||||
if (getCurrentFirmware()->getCapability(HasModelCategories)) {
|
||||
QString name = line.mid(1, line.size() - 2);
|
||||
CategoryData category(qPrintable(name));
|
||||
radioData.categories.push_back(category);
|
||||
categoryIndex++;
|
||||
qDebug() << "added category" << name;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith('[') && line.endsWith(']')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// determine if we have a model number
|
||||
QStringList parts = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
||||
@@ -136,9 +127,6 @@ bool CategorizedStorageFormat::loadBin(RadioData & radioData)
|
||||
radioData.generalSettings.currModelIndex = modelIndex;
|
||||
qDebug() << "currModelIndex =" << modelIndex;
|
||||
}
|
||||
if (getCurrentFirmware()->getCapability(HasModelCategories)) {
|
||||
radioData.models[modelIndex].category = categoryIndex;
|
||||
}
|
||||
radioData.models[modelIndex].used = true;
|
||||
modelIndex++;
|
||||
continue;
|
||||
@@ -152,12 +140,11 @@ bool CategorizedStorageFormat::loadBin(RadioData & radioData)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CategorizedStorageFormat::writeBin(const RadioData & radioData)
|
||||
bool LabelsStorageFormat::writeBin(const RadioData & radioData)
|
||||
{
|
||||
QByteArray modelsList; // models.txt
|
||||
QByteArray radioSettingsData; // radio.bin
|
||||
size_t numModels = radioData.models.size();
|
||||
size_t numCategories = radioData.categories.size();
|
||||
size_t numCategories = radioData.labels.size();
|
||||
std::vector<std::vector<QString>> sortedModels(numCategories);
|
||||
|
||||
writeRadioSettingsToByteArray(radioData.generalSettings, radioSettingsData);
|
||||
@@ -175,41 +162,12 @@ bool CategorizedStorageFormat::writeBin(const RadioData & radioData)
|
||||
if (!writeFile(modelData, modelFilename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// For firmware that doesn't support categories, we can just construct
|
||||
// models.txt as we iterate thru the models vector. For firmware that does
|
||||
// support categories, we have a bit of work to do in order to sort the
|
||||
// models first by category index, so we use the sortedModels data
|
||||
// structure to do that.
|
||||
if (!getCurrentFirmware()->getCapability(HasModelCategories)) {
|
||||
// Use format with model number and file name. This is needed because
|
||||
// radios without category support can have unused model slots
|
||||
modelsList.append(QString("%1 %2\n").arg(m).arg(model.filename).toLocal8Bit());
|
||||
} else {
|
||||
sortedModels[model.category].push_back(QString("%1\n").arg(model.filename));
|
||||
}
|
||||
}
|
||||
|
||||
if (getCurrentFirmware()->getCapability(HasModelCategories)) {
|
||||
for (size_t c=0; c<numCategories; c++) {
|
||||
modelsList.append(QString()
|
||||
.sprintf("[%s]\n", radioData.categories[c].name)
|
||||
.toLocal8Bit());
|
||||
numModels = sortedModels[c].size();
|
||||
for (size_t m=0; m<numModels; m++) {
|
||||
modelsList.append(sortedModels[c][m].toLocal8Bit());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!writeFile(modelsList, "RADIO/models.txt")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CategorizedStorageFormat::loadYaml(RadioData & radioData)
|
||||
bool LabelsStorageFormat::loadYaml(RadioData & radioData)
|
||||
{
|
||||
if (getStorageType(filename) == STORAGE_TYPE_UNKNOWN && probeFormat() == STORAGE_TYPE_ETX) {
|
||||
if (!QFile(filename + "/" + "RADIO/radio.yml").exists())
|
||||
@@ -250,43 +208,23 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData)
|
||||
// get models
|
||||
EtxModelfiles modelFiles;
|
||||
|
||||
QByteArray modelslistBuffer;
|
||||
if (loadFile(modelslistBuffer, "MODELS/models.yml")) {
|
||||
// Labels - Read the labels from labels.yml file
|
||||
// - Always scan for /MODELS/modelXX.yml
|
||||
// - Update possible labels with all found in models too
|
||||
|
||||
QByteArray labelslistBuffer;
|
||||
if (loadFile(labelslistBuffer, "MODELS/labels.yml")) {
|
||||
try {
|
||||
if (!loadModelsListFromYaml(radioData.categories, modelFiles, modelslistBuffer)) {
|
||||
setError(tr("Cannot load MODELS/models.yml"));
|
||||
return false;
|
||||
if (!loadLabelsListFromYaml(radioData.labels, modelFiles, labelslistBuffer)) {
|
||||
setError(tr("Can't load MODELS/labels.yml"));
|
||||
}
|
||||
} catch(const std::runtime_error& e) {
|
||||
setError(tr("Cannot load MODELS/models.yml") + ":\n" + QString(e.what()));
|
||||
//return false;
|
||||
|
||||
//TODO: fall back to directory scan
|
||||
std::list<std::string> filelist;
|
||||
if (!getFileList(filelist)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// push default category
|
||||
radioData.categories.push_back("Models");
|
||||
|
||||
const std::regex yml_regex("MODELS/(model([0-9]+)\\.yml)");
|
||||
for(const auto& f : filelist) {
|
||||
std::smatch match;
|
||||
if (std::regex_match(f, match, yml_regex)) {
|
||||
if (match.size() == 3) {
|
||||
std::ssub_match modelFile = match[1];
|
||||
std::ssub_match modelIdx = match[2];
|
||||
modelFiles.push_back({ modelFile.str(), "", 0, std::stoi(modelIdx.str()) });
|
||||
}
|
||||
}
|
||||
}
|
||||
setError(tr("Can't load MODELS/labels.yml") + ":\n" + QString(e.what()));
|
||||
}
|
||||
} else {
|
||||
// fetch "MODELS/modelXX.yml"
|
||||
|
||||
// Scan for all models
|
||||
std::list<std::string> filelist;
|
||||
if (!getFileList(filelist)) {
|
||||
setError(tr("Cannot list files"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -297,18 +235,18 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData)
|
||||
if (match.size() == 3) {
|
||||
std::ssub_match modelFile = match[1];
|
||||
std::ssub_match modelIdx = match[2];
|
||||
modelFiles.push_back({ modelFile.str(), "", 0, std::stoi(modelIdx.str()) });
|
||||
modelFiles.push_back({ modelFile.str(), "", std::stoi(modelIdx.str()) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int modelIdx = 0;
|
||||
bool hasCategories = getCurrentFirmware()->getCapability(HasModelCategories);
|
||||
bool hasLabels = getCurrentFirmware()->getCapability(HasModelLabels);
|
||||
|
||||
radioData.models.resize(modelFiles.size());
|
||||
for (const auto& mc : modelFiles) {
|
||||
qDebug() << "Filename: " << mc.filename.c_str() << " / Category: " << mc.category;
|
||||
qDebug() << "Filename: " << mc.filename.c_str();
|
||||
|
||||
QByteArray modelBuffer;
|
||||
QString filename = "MODELS/" + QString::fromStdString(mc.filename);
|
||||
@@ -332,24 +270,34 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
model.category = mc.category;
|
||||
model.modelIndex = modelIdx;
|
||||
strncpy(model.filename, mc.filename.c_str(), sizeof(model.filename)-1);
|
||||
|
||||
if (hasCategories && !strncmp(radioData.generalSettings.currModelFilename,
|
||||
if (hasLabels && !strncmp(radioData.generalSettings.currModelFilename,
|
||||
model.filename, sizeof(model.filename))) {
|
||||
radioData.generalSettings.currModelIndex = modelIdx;
|
||||
qDebug() << "currModelIndex =" << modelIdx;
|
||||
radioData.generalSettings.currModelIndex = modelIdx;
|
||||
}
|
||||
|
||||
if (hasLabels) {
|
||||
QStringList labels = QString(model.labels).split(',',QString::SkipEmptyParts);
|
||||
foreach(QString label, labels) {
|
||||
radioData.addLabel(label);
|
||||
}
|
||||
}
|
||||
|
||||
model.used = true;
|
||||
modelIdx++;
|
||||
}
|
||||
|
||||
// If no labels, add a Favorites
|
||||
if(hasLabels && !radioData.labels.size()) {
|
||||
radioData.labels.append(tr("Favorites"));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CategorizedStorageFormat::writeYaml(const RadioData & radioData)
|
||||
bool LabelsStorageFormat::writeYaml(const RadioData & radioData)
|
||||
{
|
||||
QByteArray radioSettingsBuffer;
|
||||
if (!writeRadioSettingsToYaml(radioData.generalSettings, radioSettingsBuffer)) {
|
||||
@@ -360,12 +308,12 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasCategories = getCurrentFirmware()->getCapability(HasModelCategories);
|
||||
bool hasLabels = getCurrentFirmware()->getCapability(HasModelLabels);
|
||||
|
||||
// B&W radios do not use the models.yml file and scan the MODELS folder for modelxx.yml files
|
||||
// models have been deleted or reordered in Companion so delete all old modelxx.yml and just in case models.yml files
|
||||
// from radio MODELS folder before writing new modelxx.yml files
|
||||
if (!hasCategories) {
|
||||
if (!hasLabels) {
|
||||
// fetch "MODELS/modelXX.yml"
|
||||
std::list<std::string> filelist;
|
||||
if (!getFileList(filelist)) {
|
||||
@@ -393,12 +341,12 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData)
|
||||
continue;
|
||||
|
||||
QString modelFilename;
|
||||
if (hasCategories) {
|
||||
if (hasLabels) {
|
||||
std::string ymlFilename = patchFilenameToYaml(model.filename);
|
||||
modelFilename =
|
||||
QString("MODELS/%1").arg(QString::fromStdString(ymlFilename));
|
||||
modelFiles.push_back(
|
||||
{ymlFilename, std::string(model.name), model.category});
|
||||
{ymlFilename, std::string(model.name)});
|
||||
} else {
|
||||
modelFilename = QString("MODELS/model%1.yml")
|
||||
.arg(model.modelIndex, 2, 10, QLatin1Char('0'));
|
||||
@@ -411,11 +359,10 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData)
|
||||
}
|
||||
}
|
||||
|
||||
if (hasCategories) {
|
||||
// TODO: sort 'modelFiles' by category index
|
||||
QByteArray modelslistBuffer;
|
||||
if (!writeModelsListToYaml(radioData.categories, modelFiles, modelslistBuffer)
|
||||
|| !writeFile(modelslistBuffer, "MODELS/models.yml")) {
|
||||
if (hasLabels) {
|
||||
QByteArray labelsListBuffer;
|
||||
if (!writeLabelsListToYaml(radioData, labelsListBuffer)
|
||||
|| !writeFile(labelsListBuffer, "MODELS/labels.yml")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -27,12 +27,12 @@
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
class CategorizedStorageFormat : public StorageFormat
|
||||
class LabelsStorageFormat : public StorageFormat
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(CategorizedStorageFormat)
|
||||
Q_DECLARE_TR_FUNCTIONS(LabelsStorageFormat)
|
||||
|
||||
public:
|
||||
CategorizedStorageFormat(const QString & filename):
|
||||
LabelsStorageFormat(const QString & filename):
|
||||
StorageFormat(filename)
|
||||
{
|
||||
}
|
||||
@@ -43,7 +43,7 @@ bool OtxFormat::load(RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = CategorizedStorageFormat::load(radioData);
|
||||
bool result = LabelsStorageFormat::load(radioData);
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return result;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ bool OtxFormat::write(const RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = CategorizedStorageFormat::write(radioData);
|
||||
bool result = LabelsStorageFormat::write(radioData);
|
||||
if (result) {
|
||||
// finalize archive and get contents
|
||||
char * archiveContents;
|
||||
|
||||
@@ -20,17 +20,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "categorized.h"
|
||||
#include "labeled.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class OtxFormat : public CategorizedStorageFormat
|
||||
class OtxFormat : public LabelsStorageFormat
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(OtxFormat)
|
||||
|
||||
public:
|
||||
OtxFormat(const QString & filename):
|
||||
CategorizedStorageFormat(filename)
|
||||
LabelsStorageFormat(filename)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ bool SdcardFormat::write(const RadioData & radioData)
|
||||
QDir dir(filename);
|
||||
dir.mkdir("RADIO");
|
||||
dir.mkdir("MODELS");
|
||||
return CategorizedStorageFormat::write(radioData);
|
||||
return LabelsStorageFormat::write(radioData);
|
||||
}
|
||||
|
||||
bool SdcardFormat::loadFile(QByteArray & filedata, const QString & filename)
|
||||
|
||||
@@ -21,17 +21,17 @@
|
||||
#ifndef _SDCARD_H2_
|
||||
#define _SDCARD_H2_
|
||||
|
||||
#include "categorized.h"
|
||||
#include "labeled.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class SdcardFormat : public CategorizedStorageFormat
|
||||
class SdcardFormat : public LabelsStorageFormat
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(SdcardFormat)
|
||||
|
||||
public:
|
||||
SdcardFormat(const QString & filename):
|
||||
CategorizedStorageFormat(filename)
|
||||
LabelsStorageFormat(filename)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ bool YamlFormat::writeFile(const QByteArray & filedata)
|
||||
}
|
||||
|
||||
bool YamlFormat::load(RadioData & radioData)
|
||||
{
|
||||
bool hasCategories = getCurrentFirmware()->getCapability(HasModelCategories);
|
||||
{
|
||||
//bool hasLabels = getCurrentFirmware()->getCapability(HasModelLabels);
|
||||
int modelIdx = 0;
|
||||
|
||||
QByteArray data;
|
||||
@@ -78,10 +78,10 @@ bool YamlFormat::load(RadioData & radioData)
|
||||
if (node["header"].IsMap()) {
|
||||
qDebug() << "File" << filename << "appears to contain model data";
|
||||
|
||||
if (hasCategories) {
|
||||
/*if (hasLabels) {
|
||||
CategoryData category(qPrintable(tr("New category")));
|
||||
radioData.categories.push_back(category);
|
||||
}
|
||||
}*/
|
||||
|
||||
radioData.models.resize(1);
|
||||
|
||||
@@ -97,7 +97,7 @@ bool YamlFormat::load(RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
model.category = 0;
|
||||
/*model.category = 0;*/
|
||||
model.modelIndex = modelIdx;
|
||||
strncpy(model.filename, qPrintable(filename), sizeof(model.filename) - 1);
|
||||
model.used = true;
|
||||
|
||||
@@ -92,7 +92,7 @@ WizMix::operator ModelData()
|
||||
int throttleChannel = -1;
|
||||
|
||||
ModelData model;
|
||||
model.category = originalModelData.category;
|
||||
model.labels[0] = '\0';
|
||||
model.used = true;
|
||||
model.moduleData[0].modelId = modelId;
|
||||
model.setDefaultInputs(settings);
|
||||
|
||||
Reference in New Issue
Block a user