11 : QAbstractTableModel(parent)
23 return _tableData.count();
28 return _tableViewColCount;
33 if (!index.isValid()) {
37 if (index.row() < 0 || index.row() >= _tableData.count()) {
40 if (index.column() < 0 || index.column() >= _tableViewColCount) {
46 return QVariant::fromValue(_tableData[index.row()][index.column()]);
48 return QVariant::fromValue(_tableData[index.row()][
ValueColumn]);
57 {Qt::DisplayRole,
"display"},
77 qWarning() <<
"Invalid row row:rowCount" << row <<
rowCount() << Q_FUNC_INFO;
78 row = qMax(qMin(row,
rowCount()), 0);
81 ColumnData colData(_tableViewColCount, QString());
86 if (!_isResetting()) {
87 beginInsertRows(QModelIndex(), row, row);
89 _tableData.insert(row, colData);
90 if (!_isResetting()) {
100 if (_resetNestingCount == 1) {
107 if (_resetNestingCount == 0) {
108 qWarning() <<
"ParameterTableModel::endReset called without prior beginReset";
111 _resetNestingCount--;
112 if (_resetNestingCount == 0) {
120 if (row < 0 || row >= _tableData.count()) {
121 qWarning() <<
"Invalid row row:rowCount" << row << _tableData.count() << Q_FUNC_INFO;
135ParameterEditorController::ParameterEditorController(QObject *parent)
137 , _parameterMgr(_vehicle->parameterManager())
143 _searchTimer.setSingleShot(
true);
144 _searchTimer.setInterval(300);
150 connect(&_searchTimer, &QTimer::timeout,
this, &ParameterEditorController::_performSearch);
154 setCurrentCategory(category);
157ParameterEditorController::~ParameterEditorController()
162void ParameterEditorController::_buildListsForComponent(
int compId)
164 for (
const QString& factName: _parameterMgr->parameterNames(compId)) {
168 if (_mapCategoryName2Category.contains(fact->category())) {
169 category = _mapCategoryName2Category[fact->category()];
172 category->
name = fact->category();
173 _mapCategoryName2Category[fact->category()] = category;
174 _categories.
append(category);
183 group->
name = fact->group();
192void ParameterEditorController::_buildLists(
void)
195 _buildListsForComponent(MAV_COMP_ID_AUTOPILOT1);
198 for (
int i=0; i<_categories.
count(); i++) {
200 if (category->
name ==
"Standard" && i != 0) {
202 _categories.
insert(0, category);
208 for (
int i=0; i<_categories.
count(); i++) {
211 if (i != _categories.
count() - 1) {
213 _categories.
append(category);
220 for (
int compId: _parameterMgr->componentIds()) {
221 if (compId != MAV_COMP_ID_AUTOPILOT1) {
222 _buildListsForComponent(compId);
227 for (
int i=0; i<_categories.
count(); i++) {
232 if (j != _categories.
count() - 1) {
242void ParameterEditorController::_factAdded(
int compId,
Fact* fact)
244 bool inserted =
false;
247 if (_mapCategoryName2Category.contains(fact->category())) {
248 category = _mapCategoryName2Category[fact->category()];
251 category->
name = fact->category();
252 _mapCategoryName2Category[fact->category()] = category;
256 for (
int i=0; i<_categories.
count(); i++) {
258 _categories.
insert(i, category);
264 _categories.
append(category);
274 group->
name = fact->group();
280 for (
int i=0; i<groups.
count(); i++) {
293 auto& facts = group->
facts;
294 for (
int i=0; i<facts.rowCount(); i++) {
295 if (facts.factAt(i)->name() > fact->name()) {
303void ParameterEditorController::saveToFile(
const QString& filename)
305 if (!filename.isEmpty()) {
306 QString parameterFilename = filename;
307 if (!QFileInfo(filename).fileName().contains(
".")) {
311 QFile file(parameterFilename);
313 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
314 qgcApp()->showAppMessage(tr(
"Unable to create file: %1").arg(parameterFilename));
318 QTextStream stream(&file);
324void ParameterEditorController::clearDiff(
void)
327 _diffOtherVehicle =
false;
328 _diffMultipleComponents =
false;
334void ParameterEditorController::sendDiff(
void)
336 for (
int i=0; i<_diffList.
count(); i++) {
339 if (paramDiff->
load) {
350bool ParameterEditorController::buildDiffFromFile(
const QString& filename)
352 QFile file(filename);
354 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
355 qgcApp()->showAppMessage(tr(
"Unable to open file: %1").arg(filename));
361 QTextStream stream(&file);
363 int firstComponentId = -1;
364 while (!stream.atEnd()) {
365 QString line = stream.readLine();
366 if (!line.startsWith(
"#")) {
367 QStringList wpParams = line.split(
"\t");
368 if (wpParams.size() == 5) {
369 int vehicleId = wpParams.at(0).toInt();
370 int componentId = wpParams.at(1).toInt();
371 QString paramName = wpParams.at(2);
372 QString fileValueStr = wpParams.at(3);
373 int mavParamType = wpParams.at(4).toInt();
374 QString vehicleValueStr;
376 QVariant fileValueVar = fileValueStr;
377 bool noVehicleValue =
false;
378 bool readOnly =
false;
381 _diffOtherVehicle =
true;
383 if (firstComponentId == -1) {
384 firstComponentId = componentId;
385 }
else if (firstComponentId != componentId) {
386 _diffMultipleComponents =
true;
391 FactMetaData* vehicleFactMetaData = vehicleFact->metaData();
392 Fact* fileFact =
new Fact(vehicleFact->componentId(), vehicleFact->name(), vehicleFact->type(),
this);
397 fileFact->setMetaData(vehicleFact->metaData());
398 fileFact->setRawValue(fileValueStr);
400 readOnly = vehicleFact->readOnly();
402 if (vehicleFact->rawValue() == fileFact->rawValue()) {
405 fileValueStr = fileFact->enumOrValueString();
406 fileValueVar = fileFact->rawValue();
407 vehicleValueStr = vehicleFact->enumOrValueString();
408 units = vehicleFact->cookedUnits();
410 noVehicleValue =
true;
416 paramDiff->componentId = componentId;
417 paramDiff->
name = paramName;
423 paramDiff->
units = units;
425 _diffList.
append(paramDiff);
439void ParameterEditorController::refresh(
void)
444void ParameterEditorController::resetAllToDefaults(
void)
450void ParameterEditorController::resetAllToVehicleConfiguration(
void)
456bool ParameterEditorController::_shouldShow(
Fact* fact)
const
458 if (!_showModifiedOnly) {
462 return fact->defaultValueAvailable() && !fact->valueEqualsDefault();
465void ParameterEditorController::_searchTextChanged(
void)
467 _searchTimer.start();
470void ParameterEditorController::_performSearch(
void)
472 QObjectList newParameterList;
474 QStringList rgSearchStrings = _searchText.split(
' ', Qt::SkipEmptyParts);
476 if (rgSearchStrings.isEmpty() && !_showModifiedOnly) {
478 setCurrentCategory(category);
479 _searchParameters.
clear();
481 QVector<QRegularExpression> regexList;
482 regexList.reserve(rgSearchStrings.size());
483 for (
const QString &searchItem : rgSearchStrings) {
484 QRegularExpression re(searchItem, QRegularExpression::CaseInsensitiveOption);
485 regexList.append(re.isValid() ? re : QRegularExpression());
489 _searchParameters.
clear();
491 for (
const QString ¶Name: _parameterMgr->parameterNames(
_vehicle->defaultComponentId())) {
493 bool matched = _shouldShow(fact);
496 for (
int i = 0; i < rgSearchStrings.size(); ++i) {
497 const QRegularExpression &re = regexList.at(i);
499 if (!fact->name().contains(re) &&
500 !fact->shortDescription().contains(re) &&
501 !fact->longDescription().contains(re)) {
505 const QString &searchItem = rgSearchStrings.at(i);
506 if (!fact->name().contains(searchItem, Qt::CaseInsensitive) &&
507 !fact->shortDescription().contains(searchItem, Qt::CaseInsensitive) &&
508 !fact->longDescription().contains(searchItem, Qt::CaseInsensitive)) {
515 _searchParameters.
append(fact);
521 if (_parameters != &_searchParameters) {
522 _parameters = &_searchParameters;
525 _currentCategory =
nullptr;
526 _currentGroup =
nullptr;
531void ParameterEditorController::_currentCategoryChanged(
void)
534 if (_currentCategory) {
540 setCurrentGroup(group);
543void ParameterEditorController::_currentGroupChanged(
void)
545 _parameters = _currentGroup ? &_currentGroup->
facts :
nullptr;
549void ParameterEditorController::setCurrentCategory(QObject* currentCategory)
552 if (category != _currentCategory) {
553 _currentCategory = category;
558void ParameterEditorController::setCurrentGroup(QObject* currentGroup)
561 if (group != _currentGroup) {
562 _currentGroup = group;
#define QGC_LOGGING_CATEGORY(name, categoryStr)
static constexpr const char * parameterFileExtension
Used for handling missing Facts from C++ code.
A Fact is used to hold a single value within the system.
QMap< QString, ParameterEditorGroup * > mapGroupName2Group
QmlObjectListModel groups
void parametersChanged(void)
void currentGroupChanged(void)
void diffMultipleComponentsChanged(bool diffMultipleComponents)
void searchTextChanged(QString searchText)
void currentCategoryChanged(void)
void diffOtherVehicleChanged(bool diffOtherVehicle)
void showModifiedOnlyChanged(void)
FactMetaData::ValueType_t valueType
ParameterEditorGroup(QObject *parent)
ParameterTableModel facts
bool parameterExists(int componentId, const QString ¶mName) const
Fact * getParameter(int componentId, const QString ¶mName)
void factAdded(int componentId, Fact *fact)
static FactMetaData::ValueType_t mavTypeToFactType(MAV_PARAM_TYPE mavType)
void resetAllParametersToDefaults()
void refreshAllParameters(uint8_t componentID=MAV_COMP_ID_ALL)
Re-request the full set of parameters from the autopilot.
void resetAllToVehicleConfiguration()
void writeParametersToStream(QTextStream &stream) const
QVector< QVariant > ColumnData
void insert(int row, Fact *fact)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int rowCount READ rowCount NOTIFY rowCountChanged void append(Fact *fact)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QHash< int, QByteArray > roleNames(void) const override
~ParameterTableModel() override
void rowCountChanged(int count)
void endReset()
Supports nesting - only outermost call has effect.
void beginReset()
Supports nesting - only outermost call has effect.
Fact * factAt(int row) const
void append(QObject *object)
Caller maintains responsibility for object ownership and deletion.
QObject * removeAt(int index)
int count() const override final
void clearAndDeleteContents() override final
Clears the list and calls deleteLater on each entry.
void insert(int index, QObject *object)
int defaultComponentId() const