fix(cpn): radio specific name and label validators (#4670)
Only allows valid characters in names, drops invalid characters if present
This commit is contained in:
+25
-20
@@ -1,16 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "labelvalidator.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QValidator>
|
||||
#include <QLineEdit>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "radiodata.h"
|
||||
|
||||
class RadioData;
|
||||
|
||||
typedef struct {
|
||||
@@ -58,27 +78,12 @@ class LabelsModel : public QAbstractItemModel
|
||||
QModelIndex getDataIndex(QModelIndex viewIndex) const;
|
||||
};
|
||||
|
||||
class LabelValidator : public QValidator
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QValidator::State validate(QString &label, int &pos) const;
|
||||
void fixup(QString &input) const;
|
||||
};
|
||||
|
||||
class LabelEditTextDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LabelEditTextDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {}
|
||||
LabelEditTextDelegate(QObject * parent = nullptr) : QStyledItemDelegate(parent) {}
|
||||
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QLineEdit *editor = new QLineEdit(parent);
|
||||
editor->setValidator(new LabelValidator);
|
||||
return editor;
|
||||
}
|
||||
QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user