fix(cpn): Model and labels lists sync (#3967)
* labels use proxy model mapping to source * cosmetics * Fix model list focus * fix model focus on change to labels
This commit is contained in:
+44
-38
@@ -7,6 +7,7 @@
|
||||
#include <QValidator>
|
||||
#include <QLineEdit>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "radiodata.h"
|
||||
|
||||
@@ -21,58 +22,63 @@ 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;
|
||||
bool insertRows(int row, int count, const QModelIndex &parent) override;
|
||||
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
||||
public:
|
||||
LabelsModel(QSortFilterProxyModel * modelsListProxyModel, QItemSelectionModel *selectionModel, RadioData *radioData, QObject *parent = nullptr);
|
||||
virtual ~LabelsModel();
|
||||
|
||||
public slots:
|
||||
void buildLabelsList();
|
||||
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;
|
||||
bool insertRows(int row, int count, const QModelIndex &parent) override;
|
||||
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
||||
|
||||
private slots:
|
||||
void modelsSelectionChanged();
|
||||
public slots:
|
||||
void buildLabelsList();
|
||||
|
||||
signals:
|
||||
void modelChanged(int index);
|
||||
void labelsFault(QString msg);
|
||||
private slots:
|
||||
void modelsSelectionChanged();
|
||||
|
||||
private:
|
||||
QItemSelectionModel *modelsSelection;
|
||||
RadioData *radioData;
|
||||
int selectedModel;
|
||||
QList<QModelIndex> modelIndices;
|
||||
QList<LabelItem> labels;
|
||||
signals:
|
||||
void modelChanged(int index);
|
||||
void labelsFault(QString msg);
|
||||
|
||||
private:
|
||||
QSortFilterProxyModel * modelsListProxyModel;
|
||||
QItemSelectionModel *modelsSelection;
|
||||
RadioData *radioData;
|
||||
int selectedModel;
|
||||
QList<QModelIndex> modelIndices;
|
||||
QList<LabelItem> labels;
|
||||
|
||||
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;
|
||||
|
||||
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) {}
|
||||
public:
|
||||
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
|
||||
{
|
||||
QLineEdit *editor = new QLineEdit(parent);
|
||||
editor->setValidator(new LabelValidator);
|
||||
return editor;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user