13 : QAbstractTableModel(parent)
25 return _tableData.count();
30 return _tableViewColCount;
35 if (!index.isValid()) {
39 if (index.row() < 0 || index.row() >= _tableData.count()) {
42 if (index.column() < 0 || index.column() >= _tableViewColCount) {
48 return QVariant::fromValue(_tableData[index.row()][index.column()]);
50 return QVariant::fromValue(_tableData[index.row()][
ValueColumn]);
58 if (orientation != Qt::Horizontal || role != Qt::DisplayRole) {
67 default:
return QVariant();
74 {Qt::DisplayRole,
"display"},
94 qWarning() <<
"Invalid row row:rowCount" << row <<
rowCount() << Q_FUNC_INFO;
95 row = qMax(qMin(row,
rowCount()), 0);
98 ColumnData colData(_tableViewColCount, QString());
104 if (!_isResetting()) {
105 beginInsertRows(QModelIndex(), row, row);
107 _tableData.insert(row, colData);
108 if (!_isResetting()) {
116 _resetNestingCount++;
118 if (_resetNestingCount == 1) {
125 if (_resetNestingCount == 0) {
126 qWarning() <<
"ParameterTableModel::endReset called without prior beginReset";
129 _resetNestingCount--;
130 if (_resetNestingCount == 0) {
138 if (row < 0 || row >= _tableData.count()) {
139 qWarning() <<
"Invalid row row:rowCount" << row << _tableData.count() << Q_FUNC_INFO;
155 , _parameterMgr(_vehicle->parameterManager())
161 _searchTimer.setSingleShot(
true);
162 _searchTimer.setInterval(300);
170 connect(&_searchTimer, &QTimer::timeout,
this, &ParameterEditorController::_performSearch);
184void ParameterEditorController::_buildListsForComponent(
int compId)
186 for (
const QString& factName: _parameterMgr->parameterNames(compId)) {
189 if (_hideReadOnly && fact->
readOnly()) {
194 if (_mapCategoryName2Category.contains(fact->
category())) {
195 category = _mapCategoryName2Category[fact->
category()];
199 _mapCategoryName2Category[fact->
category()] = category;
200 _categories.
append(category);
218void ParameterEditorController::_buildLists(
void)
220 _currentCategory =
nullptr;
221 _currentGroup =
nullptr;
222 _parameters =
nullptr;
223 _mapCategoryName2Category.clear();
228 _buildListsForComponent(MAV_COMP_ID_AUTOPILOT1);
231 for (
int i=0; i<_categories.
count(); i++) {
233 if (category->
name ==
"Standard" && i != 0) {
235 _categories.
insert(0, category);
241 for (
int i=0; i<_categories.
count(); i++) {
244 if (i != _categories.
count() - 1) {
246 _categories.
append(category);
253 for (
int compId: _parameterMgr->componentIds()) {
254 if (compId != MAV_COMP_ID_AUTOPILOT1) {
255 _buildListsForComponent(compId);
260 for (
int i=0; i<_categories.
count(); i++) {
265 if (j != _categories.
count() - 1) {
275void ParameterEditorController::_factAdded(
int compId,
Fact* fact)
277 if (_hideReadOnly && fact->
readOnly()) {
281 bool inserted =
false;
284 if (_mapCategoryName2Category.contains(fact->
category())) {
285 category = _mapCategoryName2Category[fact->
category()];
289 _mapCategoryName2Category[fact->
category()] = category;
293 for (
int i=0; i<_categories.
count(); i++) {
295 _categories.
insert(i, category);
301 _categories.
append(category);
317 for (
int i=0; i<groups.
count(); i++) {
330 auto& facts = group->
facts;
331 for (
int i=0; i<facts.rowCount(); i++) {
332 if (facts.factAt(i)->name() > fact->
name()) {
342 if (!filename.isEmpty()) {
343 QString parameterFilename = filename;
344 if (!QFileInfo(filename).fileName().contains(
".")) {
348 QFile file(parameterFilename);
350 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
355 QTextStream stream(&file);
364 _diffOtherVehicle =
false;
365 _diffMultipleComponents =
false;
366 _diffMissingParams.clear();
374 for (
int i=0; i<_diffList.
count(); i++) {
377 if (paramDiff->
load) {
390 QFile file(filename);
392 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
399 QTextStream stream(&file);
401 int parsedLineCount = 0;
402 int firstComponentId = -1;
403 while (!stream.atEnd()) {
404 QString line = stream.readLine();
405 if (!line.startsWith(
"#") && !line.trimmed().isEmpty()) {
406 QStringList wpParams = line.trimmed().split(QRegularExpression(
"[\\t ,]+"));
408 int componentId = -1;
410 QString fileValueStr;
411 int mavParamType = -1;
412 bool isMPFormat =
false;
414 if (wpParams.size() == 5) {
416 int vehicleId = wpParams.at(0).toInt();
417 componentId = wpParams.at(1).toInt();
418 paramName = wpParams.at(2);
419 fileValueStr = wpParams.at(3);
420 mavParamType = wpParams.at(4).toInt();
423 _diffOtherVehicle =
true;
425 if (firstComponentId == -1) {
426 firstComponentId = componentId;
427 }
else if (firstComponentId != componentId) {
428 _diffMultipleComponents =
true;
430 }
else if (wpParams.size() == 2) {
432 paramName = wpParams.at(0);
433 fileValueStr = wpParams.at(1);
442 QString vehicleValueStr;
444 QVariant fileValueVar = fileValueStr;
445 bool noVehicleValue =
false;
446 bool readOnly =
false;
453 if (mavParamType == -1) {
469 fileValueVar = fileFact->
rawValue();
472 }
else if (isMPFormat) {
474 _diffMissingParams.append(paramName);
477 noVehicleValue =
true;
484 paramDiff->
name = paramName;
490 paramDiff->
units = units;
492 _diffList.
append(paramDiff);
499 if (parsedLineCount == 0) {
500 QGC::showAppMessage(tr(
"No valid parameters found in file. Check that the file is in QGC or Mission Planner format."));
506 if (!_diffMissingParams.isEmpty()) {
530bool ParameterEditorController::_shouldShow(
Fact* fact)
const
532 if (_hideReadOnly && fact->
readOnly()) {
535 if (_showModifiedOnly) {
540 if (_showFavoritesOnly) {
541 if (!_favoriteNames.contains(fact->
name())) {
548void ParameterEditorController::_searchTextChanged(
void)
550 _searchTimer.start();
553void ParameterEditorController::_hideReadOnlyChanged(
void)
561 if (!_searchText.isEmpty() || _showModifiedOnly) {
566void ParameterEditorController::_performSearch(
void)
568 QObjectList newParameterList;
570 QStringList rgSearchStrings = _searchText.split(
' ', Qt::SkipEmptyParts);
572 if (rgSearchStrings.isEmpty() && !_showModifiedOnly && !_showFavoritesOnly) {
575 _searchParameters.
clear();
577 QVector<QRegularExpression> regexList;
578 regexList.reserve(rgSearchStrings.size());
579 for (
const QString &searchItem : rgSearchStrings) {
580 QRegularExpression re(searchItem, QRegularExpression::CaseInsensitiveOption);
581 regexList.append(re.isValid() ? re : QRegularExpression());
585 _searchParameters.
clear();
587 for (
int compId : _parameterMgr->componentIds()) {
588 for (
const QString ¶Name: _parameterMgr->parameterNames(compId)) {
590 bool matched = _shouldShow(fact);
593 for (
int i = 0; i < rgSearchStrings.size(); ++i) {
594 const QRegularExpression &re = regexList.at(i);
596 if (!fact->
name().contains(re) &&
602 const QString &searchItem = rgSearchStrings.at(i);
603 if (!fact->
name().contains(searchItem, Qt::CaseInsensitive) &&
612 _searchParameters.
append(fact);
619 if (_parameters != &_searchParameters) {
620 _parameters = &_searchParameters;
623 _currentCategory =
nullptr;
624 _currentGroup =
nullptr;
629void ParameterEditorController::_currentCategoryChanged(
void)
632 if (_currentCategory) {
641void ParameterEditorController::_currentGroupChanged(
void)
643 _parameters = _currentGroup ? &_currentGroup->
facts :
nullptr;
650 if (category != _currentCategory) {
651 _currentCategory = category;
659 if (group != _currentGroup) {
660 _currentGroup = group;
667 QStringList list(_favoriteNames.begin(), _favoriteNames.end());
674 if (_favoriteNames.contains(paramName)) {
675 _favoriteNames.remove(paramName);
677 _favoriteNames.insert(paramName);
682 if (_showFavoritesOnly) {
689 return _favoriteNames.contains(paramName);
694 _favoriteNames.clear();
698 if (_showFavoritesOnly) {
703void ParameterEditorController::_loadFavorites()
706 const QStringList list = fact->
rawValue().toString().split(
",", Qt::SkipEmptyParts);
707 _favoriteNames = QSet<QString>(list.begin(), list.end());
710void ParameterEditorController::_saveFavorites()
712 QStringList list(_favoriteNames.begin(), _favoriteNames.end());
#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.
QString enumOrValueString()
void setMetaData(FactMetaData *metaData, bool setDefaultFromMetaData=false)
QString cookedUnits() const
QString longDescription() const
QString shortDescription() const
FactMetaData * metaData()
bool valueEqualsDefault() const
FactMetaData::ValueType_t type() const
void setRawValue(const QVariant &value)
bool defaultValueAvailable() const
QVariant rawValue() const
Value after translation.
QMap< QString, ParameterEditorGroup * > mapGroupName2Group
QmlObjectListModel groups
Q_INVOKABLE void resetAllToVehicleConfiguration(void)
void showFavoritesOnlyChanged(void)
Q_INVOKABLE bool buildDiffFromFile(const QString &filename)
void parametersChanged(void)
Q_INVOKABLE void refresh(void)
void currentGroupChanged(void)
void diffMultipleComponentsChanged(bool diffMultipleComponents)
Q_INVOKABLE void toggleFavorite(const QString ¶mName)
QObject * currentCategory(void)
Q_INVOKABLE void clearAllFavorites(void)
~ParameterEditorController()
QStringList favoriteParameterNames(void) const
void setCurrentGroup(QObject *currentGroup)
Q_INVOKABLE void saveToFile(const QString &filename)
ParameterEditorController(QObject *parent=nullptr)
void searchTextChanged(QString searchText)
Q_INVOKABLE void sendDiff(void)
void currentCategoryChanged(void)
void diffOtherVehicleChanged(bool diffOtherVehicle)
void setCurrentCategory(QObject *currentCategory)
void favoritesChanged(void)
Q_INVOKABLE bool isFavorite(const QString ¶mName) const
Q_INVOKABLE void clearDiff(void)
void showModifiedOnlyChanged(void)
QObject * currentGroup(void)
void missingParamsFromFile(const QStringList &missingParams)
Q_INVOKABLE void resetAllToDefaults(void)
void hideReadOnlyChanged(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)
static constexpr int defaultComponentId
void resetAllParametersToDefaults()
void refreshAllParameters(uint8_t componentID)
Re-request the full set of parameters from the autopilot.
static MAV_PARAM_TYPE factTypeToMavType(FactMetaData::ValueType_t factType)
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 columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) 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)
static SettingsManager * instance()
AppSettings * appSettings() const
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.