Companion enhancements for checklist editor, model print and compare (2 3 branch) (#6434)
* Model print and compare include GFs enhancement * Model print and compare include checklist contents * Add missing brackets and code tidy up * Print message if cannot open or read checklist file * Missing GV label translation Move some checklist code to helpers * Refactor to use helpers and add cursor position * Move improved version of removeAccents to helpers and apply to checklist * Force fixed width font for edit window
This commit is contained in:
committed by
Bertrand Songis
parent
0544846dc3
commit
b4175eade3
@@ -24,37 +24,7 @@
|
||||
#include "generalsettings.h"
|
||||
#include "macros.h"
|
||||
#include "radiodataconversionstate.h"
|
||||
|
||||
|
||||
QString removeAccents(const QString & str)
|
||||
{
|
||||
// UTF-8 ASCII Table
|
||||
static const QHash<QString, QVariant> map = {
|
||||
{"a", QRegularExpression("[áâãàä]")},
|
||||
{"A", QRegularExpression("[ÁÂÃÀÄ]")},
|
||||
{"e", QRegularExpression("[éèêě]")},
|
||||
{"E", QRegularExpression("[ÉÈÊĚ]")},
|
||||
{"o", QRegularExpression("[óôõö]")},
|
||||
{"O", QRegularExpression("[ÓÔÕÖ]")},
|
||||
{"u", QRegularExpression("[úü]")},
|
||||
{"U", QRegularExpression("[ÚÜ]")},
|
||||
{"i", "í"}, {"I", "Í"},
|
||||
{"c", "ç"}, {"C", "Ç"},
|
||||
{"y", "ý"}, {"Y", "Ý"},
|
||||
{"s", "š"}, {"S", "Š"},
|
||||
{"r", "ř"}, {"R", "Ř"}
|
||||
};
|
||||
|
||||
QString result(str);
|
||||
for (QHash<QString, QVariant>::const_iterator it = map.cbegin(), en = map.cend(); it != en; ++it) {
|
||||
if (it.value().canConvert<QRegularExpression>())
|
||||
result.replace(it.value().toRegularExpression(), it.key());
|
||||
else
|
||||
result.replace(it.value().toString(), it.key());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
/*
|
||||
* TimerData
|
||||
@@ -251,7 +221,7 @@ void ModelData::setDefaultInputs(const GeneralSettings & settings)
|
||||
expo->mode = INPUT_MODE_BOTH;
|
||||
expo->srcRaw = settings.getDefaultSource(i);
|
||||
expo->weight = 100;
|
||||
strncpy(inputNames[i], removeAccents(expo->srcRaw.toString(this)).toLatin1().constData(), sizeof(inputNames[i])-1);
|
||||
strncpy(inputNames[i], Helpers::removeAccents(expo->srcRaw.toString(this)).toLatin1().constData(), sizeof(inputNames[i])-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <QFileDialog>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QDir>
|
||||
|
||||
using namespace Helpers;
|
||||
|
||||
@@ -809,3 +810,50 @@ void TableLayout::pushRowsUp(int row)
|
||||
// addDoubleSpring(gridLayout, 5, num_fsw+1);
|
||||
|
||||
}
|
||||
|
||||
QString Helpers::getChecklistsPath()
|
||||
{
|
||||
return QDir::toNativeSeparators(g.profile[g.id()].sdPath() + "/MODELS/"); // TODO : add sub folder to constants
|
||||
}
|
||||
|
||||
QString Helpers::getChecklistFilename(const ModelData * model)
|
||||
{
|
||||
QString name = model->name;
|
||||
name.replace(" ", "_");
|
||||
name.append(".txt"); // TODO : add to constants
|
||||
return name;
|
||||
}
|
||||
|
||||
QString Helpers::getChecklistFilePath(const ModelData * model)
|
||||
{
|
||||
return getChecklistsPath() + getChecklistFilename(model);
|
||||
}
|
||||
|
||||
QString Helpers::removeAccents(const QString & str)
|
||||
{
|
||||
// UTF-8 ASCII Table
|
||||
static const QHash<QString, QVariant> map = {
|
||||
{"a", QRegularExpression("[áâãàä]")},
|
||||
{"A", QRegularExpression("[ÁÂÃÀÄ]")},
|
||||
{"e", QRegularExpression("[éèêě]")},
|
||||
{"E", QRegularExpression("[ÉÈÊĚ]")},
|
||||
{"o", QRegularExpression("[óôõö]")},
|
||||
{"O", QRegularExpression("[ÓÔÕÖ]")},
|
||||
{"u", QRegularExpression("[úü]")},
|
||||
{"U", QRegularExpression("[ÚÜ]")},
|
||||
{"i", "í"}, {"I", "Í"},
|
||||
{"c", "ç"}, {"C", "Ç"},
|
||||
{"y", "ý"}, {"Y", "Ý"},
|
||||
{"s", "š"}, {"S", "Š"},
|
||||
{"r", "ř"}, {"R", "Ř"}
|
||||
};
|
||||
|
||||
QString result(str);
|
||||
for (QHash<QString, QVariant>::const_iterator it = map.cbegin(), en = map.cend(); it != en; ++it) {
|
||||
if (it.value().canConvert<QRegularExpression>())
|
||||
result.replace(it.value().toRegularExpression(), it.key());
|
||||
else
|
||||
result.replace(it.value().toString(), it.key());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -128,6 +128,11 @@ namespace Helpers
|
||||
|
||||
void exportAppSettings(QWidget * dlgParent = nullptr);
|
||||
|
||||
QString getChecklistsPath();
|
||||
QString getChecklistFilename(const ModelData * model);
|
||||
QString getChecklistFilePath(const ModelData * model);
|
||||
QString removeAccents(const QString & str);
|
||||
|
||||
} // namespace Helpers
|
||||
|
||||
// TODO : move globals to Helpers namespace
|
||||
|
||||
@@ -20,16 +20,12 @@
|
||||
|
||||
#include "checklistdialog.h"
|
||||
#include "ui_checklistdialog.h"
|
||||
|
||||
#include "appdata.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
extern AppData g;
|
||||
|
||||
ChecklistDialog::ChecklistDialog(QWidget *parent, const QString modelName):
|
||||
ChecklistDialog::ChecklistDialog(QWidget *parent, const ModelData * model):
|
||||
QDialog(parent),
|
||||
ui(new Ui::ChecklistDialog),
|
||||
mDirty(false)
|
||||
@@ -37,17 +33,21 @@ ChecklistDialog::ChecklistDialog(QWidget *parent, const QString modelName):
|
||||
ui->setupUi(this);
|
||||
setWindowIcon(CompanionIcon("edit.png"));
|
||||
|
||||
mChecklistFolder = g.profile[g.id()].sdPath() + "/MODELS/";
|
||||
QString name = modelName;
|
||||
name.replace(" ", "_");
|
||||
mModelChecklist = QDir::toNativeSeparators(mChecklistFolder + name + ".txt");
|
||||
mChecklistFolder = Helpers::getChecklistsPath();
|
||||
mModelChecklist = Helpers::getChecklistFilePath(model);
|
||||
ui->file->setText("File: " + mModelChecklist);
|
||||
ui->pteCheck->setPlainText(readFile(mModelChecklist,QFile::exists(mModelChecklist)));
|
||||
ui->pteCheck->setPlainText(readFile(mModelChecklist, QFile::exists(mModelChecklist)));
|
||||
|
||||
QFont f("Courier", 12, QFont::Normal); // fixed width font
|
||||
ui->pteCheck->setFont(f);
|
||||
|
||||
connect(ui->pteCheck, SIGNAL(textChanged()), this, SLOT(changed()));
|
||||
connect(ui->pteCheck, SIGNAL(cursorPositionChanged()), this, SLOT(cursorChanged()));
|
||||
connect(ui->pbImport, SIGNAL(clicked()), this, SLOT(import()));
|
||||
connect(ui->pbCancel, SIGNAL(clicked()), this, SLOT(reject()));
|
||||
connect(ui->pbOK, SIGNAL(clicked()), this, SLOT(update()));
|
||||
|
||||
cursorChanged(); // force label to update
|
||||
}
|
||||
|
||||
ChecklistDialog::~ChecklistDialog()
|
||||
@@ -78,7 +78,7 @@ void ChecklistDialog::update()
|
||||
else {
|
||||
QTextStream out(&file);
|
||||
if (out.status()==QTextStream::Ok) {
|
||||
out << ui->pteCheck->toPlainText();
|
||||
out << Helpers::removeAccents(ui->pteCheck->toPlainText());
|
||||
if (!(out.status()==QTextStream::Ok)) {
|
||||
QMessageBox::critical(this, tr("Model Checklist"), tr("Cannot write to file %1:\n%2.").arg(mModelChecklist, file.errorString()));
|
||||
if (!file.flush()) {
|
||||
@@ -105,7 +105,7 @@ QString ChecklistDialog::readFile(const QString & filepath, const bool exists)
|
||||
else {
|
||||
QTextStream in(&file);
|
||||
if (in.status()==QTextStream::Ok) {
|
||||
data = in.readAll();
|
||||
data = Helpers::removeAccents(in.readAll());
|
||||
if (!(in.status()==QTextStream::Ok)) {
|
||||
QMessageBox::critical(this, tr("Model Checklist"), tr("Cannot read file %1:\n%2.").arg(QDir::toNativeSeparators(filepath), file.errorString()));
|
||||
data = "";
|
||||
@@ -116,3 +116,9 @@ QString ChecklistDialog::readFile(const QString & filepath, const bool exists)
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void ChecklistDialog::cursorChanged()
|
||||
{
|
||||
QTextCursor tc = ui->pteCheck->textCursor();
|
||||
ui->lblCursorPos->setText(tr("Line %1, Col %2").arg(tc.blockNumber() + 1).arg(tc.positionInBlock() + 1));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#ifndef _CHECKLISTDIALOG_H_
|
||||
#define _CHECKLISTDIALOG_H_
|
||||
|
||||
#include "modeldata.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
namespace Ui {
|
||||
@@ -31,13 +33,14 @@ class ChecklistDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ChecklistDialog(QWidget *parent, const QString modelName);
|
||||
ChecklistDialog(QWidget *parent, const ModelData * model);
|
||||
~ChecklistDialog();
|
||||
|
||||
private slots:
|
||||
void import();
|
||||
void update();
|
||||
void changed();
|
||||
void cursorChanged();
|
||||
|
||||
private:
|
||||
Ui::ChecklistDialog *ui;
|
||||
|
||||
@@ -65,6 +65,13 @@
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblCursorPos">
|
||||
<property name="text">
|
||||
<string>Line nn, Col nn</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
|
||||
@@ -1355,6 +1355,6 @@ void SetupPanel::onBeepCenterToggled(bool checked)
|
||||
|
||||
void SetupPanel::on_editText_clicked()
|
||||
{
|
||||
ChecklistDialog *g = new ChecklistDialog(this, ui->name->text());
|
||||
ChecklistDialog *g = new ChecklistDialog(this, model);
|
||||
g->exec();
|
||||
}
|
||||
|
||||
@@ -24,11 +24,15 @@
|
||||
#include "boards.h"
|
||||
#include "helpers_html.h"
|
||||
#include "multiprotocols.h"
|
||||
#include "appdata.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QFile>
|
||||
#include <QUrl>
|
||||
#include <QTextStream>
|
||||
|
||||
extern AppData g;
|
||||
|
||||
QString changeColor(const QString & input, const QString & to, const QString & from)
|
||||
{
|
||||
@@ -649,10 +653,17 @@ QString ModelPrinter::printLogicalSwitchLine(int idx)
|
||||
return result;
|
||||
}
|
||||
|
||||
QString ModelPrinter::printCustomFunctionLine(int idx)
|
||||
QString ModelPrinter::printCustomFunctionLine(int idx, bool gfunc)
|
||||
{
|
||||
QString result;
|
||||
const CustomFunctionData & cf = model.customFn[idx];
|
||||
CustomFunctionData cf;
|
||||
if (gfunc) {
|
||||
if (model.noGlobalFunctions)
|
||||
return result;
|
||||
cf = generalSettings.customFn[idx];
|
||||
}
|
||||
else
|
||||
cf = model.customFn[idx];
|
||||
if (cf.swtch.type == SWITCH_TYPE_NONE)
|
||||
return result;
|
||||
|
||||
@@ -1445,3 +1456,21 @@ QString ModelPrinter::printTelemetryScreen(unsigned int idx, unsigned int line,
|
||||
}
|
||||
return (hd.count() > 1 ? doTableRow(hd, width / hd.count(), "left", "", true) : "" ) + doTableRow(strl, width / strl.count());
|
||||
}
|
||||
|
||||
QString ModelPrinter::printChecklist()
|
||||
{
|
||||
if (!model.displayChecklist)
|
||||
return "";
|
||||
QString str = tr("Error: Unable to open or read file!");
|
||||
QFile file(Helpers::getChecklistFilePath(&model));
|
||||
if (file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
QTextStream in(&file);
|
||||
if (in.status() == QTextStream::Ok) {
|
||||
str = in.readAll();
|
||||
str.replace("\n", "<br />");
|
||||
str.remove("\r");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class ModelPrinter: public QObject
|
||||
QString printInputLine(const ExpoData & ed);
|
||||
QString printMixerLine(const MixData & md, bool showMultiplex, int highlightedSource = 0);
|
||||
QString printLogicalSwitchLine(int idx);
|
||||
QString printCustomFunctionLine(int idx);
|
||||
QString printCustomFunctionLine(int idx, bool gfunc = false);
|
||||
QString printChannelName(int idx);
|
||||
QString printCurveName(int idx);
|
||||
QString printCurve(int idx);
|
||||
@@ -131,6 +131,7 @@ class ModelPrinter: public QObject
|
||||
QString printSensorDetails(unsigned int idx);
|
||||
QString printTelemetryScreenType(unsigned int val);
|
||||
QString printTelemetryScreen(unsigned int idx, unsigned int line, unsigned int width);
|
||||
QString printChecklist();
|
||||
|
||||
private:
|
||||
Firmware * firmware;
|
||||
|
||||
@@ -272,6 +272,8 @@ QString MultiModelPrinter::print(QTextDocument * document)
|
||||
document->setDefaultStyleSheet(css.text());
|
||||
QString str = "<table cellspacing='0' cellpadding='3' width='100%'>"; // attributes not settable via QT stylesheet
|
||||
str.append(printSetup());
|
||||
if (firmware->getCapability(HasDisplayText))
|
||||
str.append(printChecklist());
|
||||
if (firmware->getCapability(Timers)) {
|
||||
str.append(printTimers());
|
||||
}
|
||||
@@ -283,10 +285,12 @@ QString MultiModelPrinter::print(QTextDocument * document)
|
||||
str.append(printInputs());
|
||||
str.append(printMixers());
|
||||
str.append(printOutputs());
|
||||
str += printCurves(document);
|
||||
str.append(printCurves(document));
|
||||
if (firmware->getCapability(Gvars) && !firmware->getCapability(GvarsFlightModes))
|
||||
str.append(printGvars());
|
||||
str.append(printLogicalSwitches());
|
||||
if (firmware->getCapability(GlobalFunctions))
|
||||
str.append(printGlobalFunctions());
|
||||
str.append(printSpecialFunctions());
|
||||
if (firmware->getCapability(Telemetry) & TM_HASTELEMETRY) {
|
||||
str.append(printTelemetry());
|
||||
@@ -917,3 +921,59 @@ QString MultiModelPrinter::printTelemetryScreens()
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
QString MultiModelPrinter::printGlobalFunctions()
|
||||
{
|
||||
QString str;
|
||||
QString txt;
|
||||
int count = 0;
|
||||
int idx = -1;
|
||||
MultiColumns columns(modelPrinterMap.size());
|
||||
columns.appendSectionTableStart();
|
||||
|
||||
for (int k=0; k < modelPrinterMap.size(); k++) {
|
||||
if (!modelPrinterMap.value(k).first->noGlobalFunctions) {
|
||||
idx = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (idx > -1) {
|
||||
ModelPrinter * modelPrinter = modelPrinterMap.value(idx).second;
|
||||
(void)(modelPrinter);
|
||||
|
||||
for (int i=0; i < firmware->getCapability(GlobalFunctions); i++) {
|
||||
txt = modelPrinter->printCustomFunctionLine(i, true);
|
||||
if (!txt.isEmpty()) {
|
||||
count++;
|
||||
ROWLABELCOMPARECELL(tr("GF%1").arg(i+1), 20, modelPrinter->printCustomFunctionLine(i, true), 80);
|
||||
}
|
||||
}
|
||||
columns.appendTableEnd();
|
||||
if (count > 0) {
|
||||
str.append(printTitle(tr("Global Functions")));
|
||||
str.append(columns.print());
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
QString MultiModelPrinter::printChecklist()
|
||||
{
|
||||
QString str;
|
||||
MultiColumns columns(modelPrinterMap.size());
|
||||
bool isChecklist = false;
|
||||
for (int k=0; k < modelPrinterMap.size(); k++) {
|
||||
if (modelPrinterMap.value(k).first->displayChecklist) {
|
||||
isChecklist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isChecklist) {
|
||||
columns.appendSectionTableStart();
|
||||
ROWLABELCOMPARECELL(tr("Checklist"), 20, modelPrinter->printChecklist(), 80);
|
||||
columns.appendTableEnd();
|
||||
str.append(columns.print());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -93,6 +93,8 @@ class MultiModelPrinter: public QObject
|
||||
QString printTimers();
|
||||
QString printSensors();
|
||||
QString printTelemetryScreens();
|
||||
QString printGlobalFunctions();
|
||||
QString printChecklist();
|
||||
};
|
||||
|
||||
#endif // _MULTIMODELPRINTER_H_
|
||||
|
||||
Reference in New Issue
Block a user