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