mirror of
https://github.com/EdgeTX/edgetx.git
synced 2025-07-26 17:55:12 +03:00
Added Q_OBJECT to TreeModel and some cosmetics
This commit is contained in:
parent
cc12601a01
commit
f40e64c2aa
4 changed files with 46 additions and 45 deletions
|
@ -197,6 +197,7 @@ set(companion_MOC_HDRS
|
||||||
wizarddialog.h
|
wizarddialog.h
|
||||||
modelprinter.h
|
modelprinter.h
|
||||||
multimodelprinter.h
|
multimodelprinter.h
|
||||||
|
modelslist.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(companion_UIS
|
set(companion_UIS
|
||||||
|
|
|
@ -56,7 +56,7 @@ class AppPreferencesDialog : public QDialog
|
||||||
bool displayImage(const QString & fileName);
|
bool displayImage(const QString & fileName);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void shrink();
|
void shrink();
|
||||||
void baseFirmwareChanged();
|
void baseFirmwareChanged();
|
||||||
void firmwareOptionChanged(bool state);
|
void firmwareOptionChanged(bool state);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ class AppPreferencesDialog : public QDialog
|
||||||
void on_backupPathButton_clicked();
|
void on_backupPathButton_clicked();
|
||||||
void on_ProfilebackupPathButton_clicked();
|
void on_ProfilebackupPathButton_clicked();
|
||||||
void on_ge_pathButton_clicked();
|
void on_ge_pathButton_clicked();
|
||||||
|
|
||||||
void on_sdPathButton_clicked();
|
void on_sdPathButton_clicked();
|
||||||
void on_removeProfileButton_clicked();
|
void on_removeProfileButton_clicked();
|
||||||
void on_SplashSelect_clicked();
|
void on_SplashSelect_clicked();
|
||||||
|
|
|
@ -55,7 +55,7 @@ int TreeItem::childNumber() const
|
||||||
{
|
{
|
||||||
if (parentItem)
|
if (parentItem)
|
||||||
return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
|
return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,10 +85,10 @@ bool TreeItem::removeChildren(int position, int count)
|
||||||
{
|
{
|
||||||
if (position < 0 || position + count > childItems.size())
|
if (position < 0 || position + count > childItems.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (int row = 0; row < count; ++row)
|
for (int row = 0; row < count; ++row)
|
||||||
delete childItems.takeAt(position);
|
delete childItems.takeAt(position);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ bool TreeItem::setData(int column, const QVariant & value)
|
||||||
{
|
{
|
||||||
if (column < 0 || column >= itemData.size())
|
if (column < 0 || column >= itemData.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
itemData[column] = value;
|
itemData[column] = value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -132,13 +132,13 @@ QVariant TreeModel::data(const QModelIndex & index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::FontRole) {
|
if (role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::FontRole) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeItem * item = getItem(index);
|
TreeItem * item = getItem(index);
|
||||||
|
|
||||||
if (role == Qt::FontRole) {
|
if (role == Qt::FontRole) {
|
||||||
if (item->getModelIndex() == (int)radioData->generalSettings.currModelIndex) {
|
if (item->getModelIndex() == (int)radioData->generalSettings.currModelIndex) {
|
||||||
QFont font;
|
QFont font;
|
||||||
|
@ -153,7 +153,7 @@ Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return Qt::ItemIsEditable | QAbstractItemModel::flags(index);
|
return Qt::ItemIsEditable | QAbstractItemModel::flags(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int rol
|
||||||
{
|
{
|
||||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||||
return rootItem->data(section);
|
return rootItem->data(section);
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ QModelIndex TreeModel::index(int row, int column, const QModelIndex & parent) co
|
||||||
{
|
{
|
||||||
if (parent.isValid() && parent.column() != 0)
|
if (parent.isValid() && parent.column() != 0)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
TreeItem * parentItem = getItem(parent);
|
TreeItem * parentItem = getItem(parent);
|
||||||
TreeItem * childItem = parentItem->child(row);
|
TreeItem * childItem = parentItem->child(row);
|
||||||
if (childItem)
|
if (childItem)
|
||||||
|
@ -193,13 +193,13 @@ QModelIndex TreeModel::parent(const QModelIndex & index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
TreeItem * childItem = getItem(index);
|
TreeItem * childItem = getItem(index);
|
||||||
TreeItem * parentItem = childItem->parent();
|
TreeItem * parentItem = childItem->parent();
|
||||||
|
|
||||||
if (parentItem == rootItem)
|
if (parentItem == rootItem)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
return createIndex(parentItem->childNumber(), 0, parentItem);
|
return createIndex(parentItem->childNumber(), 0, parentItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,13 +207,13 @@ bool TreeModel::removeRows(int position, int rows, const QModelIndex & parent)
|
||||||
{
|
{
|
||||||
TreeItem * parentItem = getItem(parent);
|
TreeItem * parentItem = getItem(parent);
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
if (position >= 0 && rows > 0) {
|
if (position >= 0 && rows > 0) {
|
||||||
beginRemoveRows(parent, position, position + rows - 1);
|
beginRemoveRows(parent, position, position + rows - 1);
|
||||||
success = parentItem->removeChildren(position, rows);
|
success = parentItem->removeChildren(position, rows);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,17 +227,17 @@ bool TreeModel::setData(const QModelIndex & index, const QVariant & value, int r
|
||||||
{
|
{
|
||||||
if (role != Qt::EditRole)
|
if (role != Qt::EditRole)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
TreeItem * item = getItem(index);
|
TreeItem * item = getItem(index);
|
||||||
bool result = item->setData(index.column(), value);
|
bool result = item->setData(index.column(), value);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,23 +245,23 @@ void TreeModel::refresh()
|
||||||
{
|
{
|
||||||
EEPROMInterface * eepromInterface = getCurrentEEpromInterface();
|
EEPROMInterface * eepromInterface = getCurrentEEpromInterface();
|
||||||
Board::Type board = eepromInterface->getBoard();
|
Board::Type board = eepromInterface->getBoard();
|
||||||
|
|
||||||
if (!IS_SKY9X(board) && !IS_HORUS(board)) {
|
if (!IS_SKY9X(board) && !IS_HORUS(board)) {
|
||||||
availableEEpromSize = getEEpromSize(board) - 64; // let's consider fat
|
availableEEpromSize = getEEpromSize(board) - 64; // let's consider fat
|
||||||
availableEEpromSize -= 16 * ((eepromInterface->getSize(radioData->generalSettings) + 14) / 15);
|
availableEEpromSize -= 16 * ((eepromInterface->getSize(radioData->generalSettings) + 14) / 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeRows(0, rowCount());
|
removeRows(0, rowCount());
|
||||||
|
|
||||||
TreeItem * defaultCategoryItem = NULL;
|
TreeItem * defaultCategoryItem = NULL;
|
||||||
|
|
||||||
if (IS_HORUS(board)) {
|
if (IS_HORUS(board)) {
|
||||||
for (unsigned i = 0; i < radioData->categories.size(); i++) {
|
for (unsigned i = 0; i < radioData->categories.size(); i++) {
|
||||||
TreeItem * current = rootItem->appendChild(i, -1);
|
TreeItem * current = rootItem->appendChild(i, -1);
|
||||||
current->setData(0, QString(radioData->categories[i].name));
|
current->setData(0, QString(radioData->categories[i].name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i=0; i<radioData->models.size(); i++) {
|
for (unsigned i=0; i<radioData->models.size(); i++) {
|
||||||
ModelData & model = radioData->models[i];
|
ModelData & model = radioData->models[i];
|
||||||
int currentColumn = 0;
|
int currentColumn = 0;
|
||||||
|
@ -288,7 +288,7 @@ void TreeModel::refresh()
|
||||||
current = rootItem->appendChild(0, i);
|
current = rootItem->appendChild(0, i);
|
||||||
current->setData(currentColumn++, QString().sprintf("%02d", i + 1));
|
current->setData(currentColumn++, QString().sprintf("%02d", i + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!model.isEmpty()) {
|
if (!model.isEmpty()) {
|
||||||
QString modelName;
|
QString modelName;
|
||||||
if (strlen(model.name) > 0)
|
if (strlen(model.name) > 0)
|
||||||
|
@ -308,7 +308,7 @@ void TreeModel::refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IS_SKY9X(board) && !IS_HORUS(board)) {
|
if (!IS_SKY9X(board) && !IS_HORUS(board)) {
|
||||||
availableEEpromSize = (availableEEpromSize / 16) * 15;
|
availableEEpromSize = (availableEEpromSize / 16) * 15;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ class TreeItem
|
||||||
explicit TreeItem(const QVector<QVariant> & itemData);
|
explicit TreeItem(const QVector<QVariant> & itemData);
|
||||||
explicit TreeItem(TreeItem * parent, int categoryIndex, int modelIndex);
|
explicit TreeItem(TreeItem * parent, int categoryIndex, int modelIndex);
|
||||||
~TreeItem();
|
~TreeItem();
|
||||||
|
|
||||||
TreeItem * child(int number);
|
TreeItem * child(int number);
|
||||||
int childCount() const;
|
int childCount() const;
|
||||||
int columnCount() const;
|
int columnCount() const;
|
||||||
|
@ -44,13 +44,13 @@ class TreeItem
|
||||||
TreeItem * appendChild(int categoryIndex, int modelIndex);
|
TreeItem * appendChild(int categoryIndex, int modelIndex);
|
||||||
TreeItem * parent();
|
TreeItem * parent();
|
||||||
bool removeChildren(int position, int count);
|
bool removeChildren(int position, int count);
|
||||||
|
|
||||||
int childNumber() const;
|
int childNumber() const;
|
||||||
bool setData(int column, const QVariant &value);
|
bool setData(int column, const QVariant &value);
|
||||||
|
|
||||||
int getModelIndex() const { return modelIndex; }
|
int getModelIndex() const { return modelIndex; }
|
||||||
int getCategoryIndex() const { return categoryIndex; }
|
int getCategoryIndex() const { return categoryIndex; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<TreeItem*> childItems;
|
QList<TreeItem*> childItems;
|
||||||
QVector<QVariant> itemData;
|
QVector<QVariant> itemData;
|
||||||
|
@ -62,42 +62,42 @@ class TreeItem
|
||||||
|
|
||||||
class TreeModel : public QAbstractItemModel
|
class TreeModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
// Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TreeModel(RadioData * radioData, QObject *parent = 0);
|
TreeModel(RadioData * radioData, QObject *parent = 0);
|
||||||
~TreeModel();
|
virtual ~TreeModel();
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
|
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation,
|
QVariant headerData(int section, Qt::Orientation orientation,
|
||||||
int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
QModelIndex index(int row, int column,
|
QModelIndex index(int row, int column,
|
||||||
const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||||
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
|
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
|
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
|
||||||
bool setData(const QModelIndex &index, const QVariant &value,
|
bool setData(const QModelIndex &index, const QVariant &value,
|
||||||
int role = Qt::EditRole) Q_DECL_OVERRIDE;
|
int role = Qt::EditRole) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
bool removeRows(int position, int rows,
|
bool removeRows(int position, int rows,
|
||||||
const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
|
const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
int getAvailableEEpromSize() { return availableEEpromSize; }
|
int getAvailableEEpromSize() { return availableEEpromSize; }
|
||||||
|
|
||||||
int getModelIndex(const QModelIndex & index) const {
|
int getModelIndex(const QModelIndex & index) const {
|
||||||
return getItem(index)->getModelIndex();
|
return getItem(index)->getModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
int getCategoryIndex(const QModelIndex & index) const {
|
int getCategoryIndex(const QModelIndex & index) const {
|
||||||
return getItem(index)->getCategoryIndex();
|
return getItem(index)->getCategoryIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TreeItem * getItem(const QModelIndex & index) const;
|
TreeItem * getItem(const QModelIndex & index) const;
|
||||||
TreeItem * rootItem;
|
TreeItem * rootItem;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue