Files
edgetx-gx12/companion/src/modelslist.h
T
c8693569b0 feat(color): New label based Model Selector (#1374)
* Model Labels Selector

* Portrait Layout

* Receiver ID Check

* Fix Labels .yml format

* Companion Initial Commit

commit 967ddf3979b4954402fe62c858faba4b7a416bba
Author: dlktdr <cblackburn320@gmail.com>
Date:   Mon Aug 29 01:49:15 2022 -0700

    Fix Labels .yml format

commit 534221cad9e01146c47a9ac1080a655e04f1f6c8
Author: dlktdr <cblackburn320@gmail.com>
Date:   Mon Aug 29 01:20:57 2022 -0700

    Receiver ID Check

commit f32c0939d44e9ae60bc0705a9176354c23fec198
Author: dlktdr <cblackburn320@gmail.com>
Date:   Sun Aug 28 23:13:25 2022 -0700

    Portrait Layout

commit 961181217c7841ff3f21299ac6aa419b810f80e9
Author: dlktdr <cblackburn320@gmail.com>
Date:   Sat Dec 11 16:56:13 2021 -0800

    Model Labels Selector

commit dc99dd40d2
Author: David PHAM-VAN <1387855+DavBfr@users.noreply.github.com>
Date:   Fri Aug 26 03:04:34 2022 -0300

    feat: Allow Lua widget to override built-in widget with same name (#2208)

    * Allow CPP Widgets Override with LUA

    * Reset a widget option it the type differs

commit 4b747caff9
Author: eshifri <46511024+eshifri@users.noreply.github.com>
Date:   Thu Aug 25 19:47:53 2022 -0700

    fix: Write model name into models.yml when duplicating model (#2224)

    * Update model name in the models.yml file (#2214)

    * Fix the length of the name.

commit e97f23a305
Author: eshifri <46511024+eshifri@users.noreply.github.com>
Date:   Wed Aug 24 21:19:52 2022 -0700

    fix(cpn): Fix full path to model notes for Simulator (#2223)

* Correct Highlighted Column

* labels .yml indentation

* Update da.h

New defines translated to Danish

* Update dataconstants.h

Omit warnings due to difference of LEN_MODEL_FILENAME and LEN_MODEL_NAME in modellist.cpp

* Update modelslist.cpp

Wonder if this are the right file in PR #1374 (?), seems a lot are changed to the better in #1374

* Update dataconstants.h

Restore #define for LEN_MODEL_FILENAME to 16

* Rebase, Correct Issues

Delete now deletes instead of select
New model stores correct information
Duplicate save all information in cell
Rework items to use cell over button
Reword function variables

* CMPN: Add context menu

Fix output not functional. Removed Yaml::null at some point :)
Fix some compiler warnings

* CMPN: Compiler warning, replace ,->_ in list

* FW: Various Changes

Change view to a grid
Don't allow comma in label name
Add scroll indicators
Save sort order

Co-authored-by: HThuren <99370924+HThuren@users.noreply.github.com>
2022-09-03 09:01:19 +10:00

157 lines
6.5 KiB
C++

/*
* Copyright (C) OpenTX
*
* Based on code named
* 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 "eeprominterface.h"
#include <QAbstractItemModel>
#include <QMimeData>
#include <QUuid>
class ModelListItem
{
public:
enum ModelListItemFlags { MarkedForCut = 0x01 };
explicit ModelListItem(const QVector<QVariant> & itemData);
explicit ModelListItem(ModelListItem * parent, int categoryIndex, int modelIndex);
~ModelListItem();
ModelListItem * child(int number);
int childCount() const;
int columnCount() const;
QVariant data(int column) const;
ModelListItem * appendChild(int categoryIndex, int modelIndex);
ModelListItem * insertChild(const int row, int categoryIndex, int modelIndex);
bool removeChildren(int position, int count);
bool insertChildren(int row, int count);
int childNumber() const;
bool setData(int column, const QVariant &value);
ModelListItem * parent() { return parentItem; }
void setParent(ModelListItem * p) { parentItem = p; }
int getModelIndex() const { return modelIndex; }
void setModelIndex(int value) { modelIndex = value; }
int getCategoryIndex() const { return categoryIndex; }
void setCategoryIndex(int value) { categoryIndex = value; }
void setHighlightRX(int value) { highlightRX = value; }
bool isHighlightRX() const { return highlightRX; }
quint16 getFlags() const { return flags; }
void setFlags(const quint16 & value) { flags = value; }
void setFlag(const quint16 & flag, const bool on = true);
bool isCategory() const;
bool isModel() const;
private:
QList<ModelListItem*> childItems;
QVector<QVariant> itemData;
ModelListItem * parentItem;
int categoryIndex;
int modelIndex;
quint16 flags;
bool highlightRX;
};
class ModelsListModel : public QAbstractItemModel
{
Q_OBJECT
public:
struct MimeHeaderData {
QUuid instanceId;
quint16 dataVersion;
};
ModelsListModel(RadioData * radioData, QObject *parent = 0);
virtual ~ModelsListModel();
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
virtual QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
virtual Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
virtual bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
//virtual bool insertRows(int row, int count, const QModelIndex & parent) Q_DECL_OVERRIDE;
virtual QStringList mimeTypes() const Q_DECL_OVERRIDE;
virtual Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
virtual Qt::DropActions supportedDragActions() const Q_DECL_OVERRIDE;
virtual QMimeData * mimeData(const QModelIndexList & indexes) const Q_DECL_OVERRIDE;
virtual bool canDropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) const Q_DECL_OVERRIDE;
virtual bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) Q_DECL_OVERRIDE;
void encodeModelsData(const QModelIndexList & indexes, QByteArray * data) const;
void encodeGeneralData(QByteArray * data) const;
void encodeHeaderData(QByteArray * data) const;
QMimeData * getModelsMimeData(const QModelIndexList & indexes, QMimeData * mimeData = NULL) const;
QMimeData * getGeneralMimeData(QMimeData * mimeData = NULL) const;
QMimeData * getHeaderMimeData(QMimeData * mimeData = NULL) const;
QUuid getMimeDataSourceId(const QMimeData * mimeData) const;
bool hasSupportedMimeData(const QMimeData * mimeData) const;
bool hasModelsMimeData(const QMimeData * mimeData) const;
bool hasGenralMimeData(const QMimeData * mimeData) const;
bool hasHeaderMimeData(const QMimeData * mimeData) const;
bool hasOwnMimeData(const QMimeData * mimeData) const;
static bool decodeHeaderData(const QMimeData * mimeData, MimeHeaderData * header);
static bool decodeMimeData(const QMimeData * mimeData, QVector<ModelData> * models = NULL, GeneralSettings * gs = NULL, bool * hasGenSet = NULL);
static int countModelsInMimeData(const QMimeData * mimeData);
QModelIndex getIndexForModel(const int modelIndex, QModelIndex parent = QModelIndex());
QModelIndex getIndexForCategory(const int categoryIndex);
int getModelIndex(const QModelIndex & index) const;
int getCategoryIndex(const QModelIndex & index) const;
int rowNumber(const QModelIndex & index = QModelIndex()) const;
bool isCategoryType(const QModelIndex & index) const;
bool isModelType(const QModelIndex & index) const;
public slots:
void markItemForCut(const QModelIndex & index, bool on = true);
void markItemsForCut(const QModelIndexList & indexes, bool on = true);
void refresh();
signals:
void modelsDropped(const QMimeData * mimeData, const QModelIndex toRowIdx, const bool insert, const bool move);
void modelsRemoved(const QVector<int> modelIndices);
void refreshRequested();
private slots:
//void onRowsAboutToBeRemoved(const QModelIndex & parent, int first, int last);
void onRowsRemoved(const QModelIndex & parent, int first, int last);
private:
ModelListItem * getItem(const QModelIndex & index) const;
bool isModelIdUnique(unsigned modelId, unsigned module, unsigned protocol);
ModelListItem * rootItem;
RadioData * radioData;
MimeHeaderData mimeHeaderData;
bool hasLabels;
};