1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 17:55:19 +03:00

[Companion] Rename category function added

This commit is contained in:
Bertrand Songis 2017-01-18 18:43:12 +01:00
parent c707715f3d
commit 1460620483
4 changed files with 26 additions and 7 deletions

View file

@ -340,9 +340,9 @@ class Firmware {
return board;
}
void setEEpromInterface(EEPROMInterface * interface)
void setEEpromInterface(EEPROMInterface * eeprom)
{
eepromInterface = interface;
eepromInterface = eeprom;
}
EEPROMInterface * getEEpromInterface()

View file

@ -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());

View file

@ -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;

View file

@ -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;
}