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

Separate context menu for "General Settings", cosmetics

This commit is contained in:
Damjan Adamic 2015-08-16 09:28:43 +02:00
parent 3469fa5c93
commit 154572e547
3 changed files with 99 additions and 87 deletions

View file

@ -170,7 +170,7 @@ void MdiChild::generalEdit()
void MdiChild::modelEdit() void MdiChild::modelEdit()
{ {
int row = ui->modelsList->currentRow(); int row = getCurrentRow();
if (row == 0){ if (row == 0){
generalEdit(); generalEdit();
@ -189,7 +189,7 @@ void MdiChild::modelEdit()
void MdiChild::wizardEdit() void MdiChild::wizardEdit()
{ {
int row = ui->modelsList->currentRow(); int row = getCurrentRow();
if (row > 0) { if (row > 0) {
checkAndInitModel(row); checkAndInitModel(row);
WizardDialog * wizard = new WizardDialog(radioData.generalSettings, row, this); WizardDialog * wizard = new WizardDialog(radioData.generalSettings, row, this);
@ -203,7 +203,7 @@ void MdiChild::wizardEdit()
void MdiChild::openEditWindow() void MdiChild::openEditWindow()
{ {
int row = ui->modelsList->currentRow(); int row = getCurrentRow();
if (row == 0){ if (row == 0){
generalEdit(); generalEdit();
} }
@ -388,32 +388,32 @@ bool MdiChild::saveAs(bool isNew)
bool MdiChild::saveFile(const QString &fileName, bool setCurrent) bool MdiChild::saveFile(const QString &fileName, bool setCurrent)
{ {
QString myFile; QString myFile;
myFile = fileName; myFile = fileName;
if (IS_SKY9X(GetEepromInterface()->getBoard())) { if (IS_SKY9X(GetEepromInterface()->getBoard())) {
myFile.replace(".eepe", ".bin"); myFile.replace(".eepe", ".bin");
} }
QFile file(myFile); QFile file(myFile);
int fileType = getFileType(myFile); int fileType = getFileType(myFile);
uint8_t *eeprom = (uint8_t*)malloc(GetEepromInterface()->getEEpromSize()); uint8_t *eeprom = (uint8_t*)malloc(GetEepromInterface()->getEEpromSize());
int eeprom_size = 0; int eeprom_size = 0;
if (fileType != FILE_TYPE_XML) { if (fileType != FILE_TYPE_XML) {
eeprom_size = GetEepromInterface()->save(eeprom, radioData, GetCurrentFirmware()->getVariantNumber(), 0/*last version*/); eeprom_size = GetEepromInterface()->save(eeprom, radioData, GetCurrentFirmware()->getVariantNumber(), 0/*last version*/);
if (!eeprom_size) { if (!eeprom_size) {
QMessageBox::warning(this, tr("Error"),tr("Cannot write file %1:\n%2.").arg(myFile).arg(file.errorString()));
return false;
}
}
if (!file.open(fileType == FILE_TYPE_BIN ? QIODevice::WriteOnly : (QIODevice::WriteOnly | QIODevice::Text))) {
QMessageBox::warning(this, tr("Error"),tr("Cannot write file %1:\n%2.").arg(myFile).arg(file.errorString())); QMessageBox::warning(this, tr("Error"),tr("Cannot write file %1:\n%2.").arg(myFile).arg(file.errorString()));
return false; return false;
} }
}
QTextStream outputStream(&file); if (!file.open(fileType == FILE_TYPE_BIN ? QIODevice::WriteOnly : (QIODevice::WriteOnly | QIODevice::Text))) {
QMessageBox::warning(this, tr("Error"),tr("Cannot write file %1:\n%2.").arg(myFile).arg(file.errorString()));
return false;
}
QTextStream outputStream(&file);
#if 0 #if 0
if (fileType==FILE_TYPE_XML) { if (fileType==FILE_TYPE_XML) {
@ -425,34 +425,34 @@ bool MdiChild::saveFile(const QString &fileName, bool setCurrent)
} }
else else
#endif #endif
if (fileType==FILE_TYPE_HEX || fileType==FILE_TYPE_EEPE) { // write hex if (fileType==FILE_TYPE_HEX || fileType==FILE_TYPE_EEPE) { // write hex
if (fileType==FILE_TYPE_EEPE) if (fileType==FILE_TYPE_EEPE)
outputStream << EEPE_EEPROM_FILE_HEADER << "\n"; outputStream << EEPE_EEPROM_FILE_HEADER << "\n";
if (!HexInterface(outputStream).save(eeprom, eeprom_size)) { if (!HexInterface(outputStream).save(eeprom, eeprom_size)) {
QMessageBox::warning(this, tr("Error"),tr("Cannot write file %1:\n%2.").arg(myFile).arg(file.errorString())); QMessageBox::warning(this, tr("Error"),tr("Cannot write file %1:\n%2.").arg(myFile).arg(file.errorString()));
file.close(); file.close();
return false;
}
}
else if (fileType==FILE_TYPE_BIN) // write binary
{
long result = file.write((char*)eeprom, eeprom_size);
if(result!=eeprom_size) {
QMessageBox::warning(this, tr("Error"),tr("Error writing file %1:\n%2.").arg(myFile).arg(file.errorString()));
return false; return false;
}
} }
else { }
QMessageBox::warning(this, tr("Error"),tr("Error writing file %1:\n%2.").arg(myFile).arg("Unknown format")); else if (fileType==FILE_TYPE_BIN) // write binary
{
long result = file.write((char*)eeprom, eeprom_size);
if(result!=eeprom_size) {
QMessageBox::warning(this, tr("Error"),tr("Error writing file %1:\n%2.").arg(myFile).arg(file.errorString()));
return false; return false;
} }
}
else {
QMessageBox::warning(this, tr("Error"),tr("Error writing file %1:\n%2.").arg(myFile).arg("Unknown format"));
return false;
}
free(eeprom); // TODO free in all cases ... free(eeprom); // TODO free in all cases ...
file.close(); file.close();
if(setCurrent) setCurrentFile(myFile); if(setCurrent) setCurrentFile(myFile);
return true; return true;
} }
QString MdiChild::userFriendlyCurrentFile() QString MdiChild::userFriendlyCurrentFile()
@ -529,8 +529,8 @@ void MdiChild::writeEeprom() // write to Tx
void MdiChild::simulate() void MdiChild::simulate()
{ {
if (ui->modelsList->currentRow() >= 1) { if (getCurrentRow() > 0) {
startSimulation(this, radioData, ui->modelsList->currentRow()-1); startSimulation(this, radioData, getCurrentRow()-1);
} }
} }
@ -541,8 +541,8 @@ void MdiChild::print(int model, QString filename)
if (model>=0 && !filename.isEmpty()) { if (model>=0 && !filename.isEmpty()) {
pd = new PrintDialog(this, GetCurrentFirmware()/*firmware*/, &radioData.generalSettings, &radioData.models[model], filename); pd = new PrintDialog(this, GetCurrentFirmware()/*firmware*/, &radioData.generalSettings, &radioData.models[model], filename);
} }
else if (ui->modelsList->currentRow() > 0) { else if (getCurrentRow() > 0) {
pd = new PrintDialog(this, GetCurrentFirmware()/*firmware*/, &radioData.generalSettings, &radioData.models[ui->modelsList->currentRow()-1]); pd = new PrintDialog(this, GetCurrentFirmware()/*firmware*/, &radioData.generalSettings, &radioData.models[getCurrentRow()-1]);
} }
if (pd) { if (pd) {
@ -561,49 +561,54 @@ void MdiChild::setEEpromAvail(int eavail)
EEPromAvail=eavail; EEPromAvail=eavail;
} }
int MdiChild::getCurrentRow() const
{
return ui->modelsList->currentRow();
}
bool MdiChild::loadBackup() bool MdiChild::loadBackup()
{ {
QString fileName = QFileDialog::getOpenFileName(this, tr("Open backup Models and Settings file"), g.eepromDir(),tr(EEPROM_FILES_FILTER)); QString fileName = QFileDialog::getOpenFileName(this, tr("Open backup Models and Settings file"), g.eepromDir(),tr(EEPROM_FILES_FILTER));
if (fileName.isEmpty()) if (fileName.isEmpty())
return false; return false;
QFile file(fileName); QFile file(fileName);
if (!file.exists()) { if (!file.exists()) {
QMessageBox::critical(this, tr("Error"), tr("Unable to find file %1!").arg(fileName)); QMessageBox::critical(this, tr("Error"), tr("Unable to find file %1!").arg(fileName));
return false; return false;
} }
if(ui->modelsList->currentRow()<1) return false; if(getCurrentRow() < 1) return false;
int index=ui->modelsList->currentRow()-1; int index = getCurrentRow() - 1;
int eeprom_size = file.size(); int eeprom_size = file.size();
if (!file.open(QFile::ReadOnly)) { //reading binary file - TODO HEX support if (!file.open(QFile::ReadOnly)) { //reading binary file - TODO HEX support
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"),
tr("Error opening file %1:\n%2.") tr("Error opening file %1:\n%2.")
.arg(fileName) .arg(fileName)
.arg(file.errorString())); .arg(file.errorString()));
return false; return false;
} }
QByteArray eeprom(eeprom_size, 0); QByteArray eeprom(eeprom_size, 0);
long result = file.read((char*)eeprom.data(), eeprom_size); long result = file.read((char*)eeprom.data(), eeprom_size);
file.close(); file.close();
if (result != eeprom_size) { if (result != eeprom_size) {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"),
tr("Error reading file %1:\n%2.") tr("Error reading file %1:\n%2.")
.arg(fileName) .arg(fileName)
.arg(file.errorString())); .arg(file.errorString()));
return false; return false;
} }
if (!::loadBackup(radioData, (uint8_t *)eeprom.data(), eeprom_size, index)) { if (!::loadBackup(radioData, (uint8_t *)eeprom.data(), eeprom_size, index)) {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"),
tr("Invalid binary backup File %1") tr("Invalid binary backup File %1")
.arg(fileName)); .arg(fileName));
return false; return false;
} }
ui->modelsList->refreshList(); ui->modelsList->refreshList();
return true; return true;
} }

View file

@ -77,6 +77,7 @@ class MdiChild : public QWidget
void viableModelSelected(bool viable); void viableModelSelected(bool viable);
void eepromInterfaceChanged(); void eepromInterfaceChanged();
void setEEpromAvail(int eavail); void setEEpromAvail(int eavail);
int getCurrentRow() const;
signals: signals:
void copyAvailable(bool val); void copyAvailable(bool val);

View file

@ -78,13 +78,14 @@ ModelsListWidget::ModelsListWidget(QWidget *parent):
void ModelsListWidget::ShowContextMenu(const QPoint& pos) void ModelsListWidget::ShowContextMenu(const QPoint& pos)
{ {
QPoint globalPos = this->mapToGlobal(pos); QPoint globalPos = this->mapToGlobal(pos);
QMenu contextMenu;
if (((MdiChild *)parent())->getCurrentRow() > 0) {
// context menu for model
const QClipboard *clipboard = QApplication::clipboard(); const QClipboard *clipboard = QApplication::clipboard();
const QMimeData *mimeData = clipboard->mimeData(); const QMimeData *mimeData = clipboard->mimeData();
bool hasData = mimeData->hasFormat("application/x-companion"); bool hasData = mimeData->hasFormat("application/x-companion");
QMenu contextMenu;
contextMenu.addAction(CompanionIcon("edit.png"), tr("&Edit"),this,SLOT(EditModel())); contextMenu.addAction(CompanionIcon("edit.png"), tr("&Edit"),this,SLOT(EditModel()));
contextMenu.addAction(CompanionIcon("open.png"), tr("&Restore from backup"),this,SLOT(LoadBackup())); contextMenu.addAction(CompanionIcon("open.png"), tr("&Restore from backup"),this,SLOT(LoadBackup()));
contextMenu.addAction(CompanionIcon("wizard.png"), tr("&Model Wizard"),this,SLOT(OpenWizard())); contextMenu.addAction(CompanionIcon("wizard.png"), tr("&Model Wizard"),this,SLOT(OpenWizard()));
@ -100,7 +101,12 @@ void ModelsListWidget::ShowContextMenu(const QPoint& pos)
contextMenu.addAction(CompanionIcon("print.png"), tr("P&rint model"),this, SLOT(print()),QKeySequence(tr("Ctrl+P"))); contextMenu.addAction(CompanionIcon("print.png"), tr("P&rint model"),this, SLOT(print()),QKeySequence(tr("Ctrl+P")));
contextMenu.addSeparator(); contextMenu.addSeparator();
contextMenu.addAction(CompanionIcon("simulate.png"), tr("&Simulate model"),this, SLOT(simulate()),tr("Alt+S")); contextMenu.addAction(CompanionIcon("simulate.png"), tr("&Simulate model"),this, SLOT(simulate()),tr("Alt+S"));
contextMenu.exec(globalPos); }
else {
// context menu for radio settings
contextMenu.addAction(CompanionIcon("edit.png"), tr("&Edit"),this,SLOT(EditModel()));
}
contextMenu.exec(globalPos);
} }
void ModelsListWidget::EditModel() void ModelsListWidget::EditModel()