From 1460620483feca53e455e019d243eb2e2711844c Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 18 Jan 2017 18:43:12 +0100 Subject: [PATCH] [Companion] Rename category function added --- companion/src/eeprominterface.h | 4 ++-- companion/src/mdichild.cpp | 21 +++++++++++++++++++-- companion/src/mdichild.h | 3 ++- companion/src/modelslist.cpp | 5 +++-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 93a97a010..493b81fb6 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -340,9 +340,9 @@ class Firmware { return board; } - void setEEpromInterface(EEPROMInterface * interface) + void setEEpromInterface(EEPROMInterface * eeprom) { - eepromInterface = interface; + eepromInterface = eeprom; } EEPROMInterface * getEEpromInterface() diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index d13407123..e01f98e89 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -51,7 +51,7 @@ MdiChild::MdiChild(MainWindow * parent): setWindowIcon(CompanionIcon("open.png")); ui->simulateButton->setIcon(CompanionIcon("simulate.png")); setAttribute(Qt::WA_DeleteOnClose); - onFirmwareChanged(); + initModelsList(); connect(parent, SIGNAL(FirmwareChanged()), this, SLOT(onFirmwareChanged())); connect(ui->modelsList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openModelEditWindow())); connect(ui->modelsList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showModelsListContextMenu(const QPoint &))); @@ -154,11 +154,18 @@ void MdiChild::onFirmwareChanged() { Firmware * previous = firmware; firmware = getCurrentFirmware(); - BoardEnum board = firmware->getBoard(); qDebug() << "onFirmwareChanged" << previous->getName() << "=>" << firmware->getName(); radioData.convert(previous, firmware); + initModelsList(); +} + +void MdiChild::initModelsList() +{ + BoardEnum board = firmware->getBoard(); + delete modelsListModel; modelsListModel = new TreeModel(&radioData, this); + connect(modelsListModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(onDataChanged(const QModelIndex &))); ui->modelsList->setModel(modelsListModel); ui->modelsList->header()->setVisible(!IS_HORUS(board)); if (IS_HORUS(board)) { @@ -371,6 +378,16 @@ void MdiChild::categoryDelete() setModified(); } +void MdiChild::onDataChanged(const QModelIndex & index) +{ + int categoryIndex = modelsListModel->getCategoryIndex(index); + if (categoryIndex < 0 || categoryIndex >= (int)radioData.categories.size()) { + return; + } + strcpy(radioData.categories[categoryIndex].name, modelsListModel->data(index, 0).toString().left(sizeof(CategoryData::name)-1).toStdString().c_str()); + setModified(); +} + void MdiChild::modelAdd() { int categoryIndex = modelsListModel->getCategoryIndex(ui->modelsList->currentIndex()); diff --git a/companion/src/mdichild.h b/companion/src/mdichild.h index 6022989b9..5a31b54cc 100644 --- a/companion/src/mdichild.h +++ b/companion/src/mdichild.h @@ -81,6 +81,7 @@ class MdiChild : public QWidget bool loadBackup(); void confirmDelete(); void deleteSelectedModels(); + void onDataChanged(const QModelIndex & index); void cut(); void copy(); @@ -97,7 +98,7 @@ class MdiChild : public QWidget void setCurrentFile(const QString & fileName); void doCopy(QByteArray * gmData); void doPaste(QByteArray * gmData, int index); - + void initModelsList(); Ui::MdiChild * ui; TreeModel * modelsListModel; diff --git a/companion/src/modelslist.cpp b/companion/src/modelslist.cpp index ccc528af5..38f6e847e 100644 --- a/companion/src/modelslist.cpp +++ b/companion/src/modelslist.cpp @@ -223,7 +223,7 @@ int TreeModel::rowCount(const QModelIndex &parent) const return parentItem->childCount(); } -bool TreeModel::setData(const QModelIndex &index, const QVariant & value, int role) +bool TreeModel::setData(const QModelIndex & index, const QVariant & value, int role) { if (role != Qt::EditRole) return false; @@ -231,8 +231,9 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant & value, int ro TreeItem * item = getItem(index); bool result = item->setData(index.column(), value); - if (result) + if (result) { emit dataChanged(index, index); + } return result; }