From e2722509f70fd4d27db3c7514d9b2fdbeee5e82d Mon Sep 17 00:00:00 2001 From: 3djc Date: Fri, 31 Mar 2017 16:14:00 +0200 Subject: [PATCH] Instead of copying current profile, start from a blank one (#4714) * Instead of copying current profile, start from a blank one * Handle both add profile (which add a new (ie blank) one) and copy current profile which behaves like before (but says it) * Avoid duplicate code --- companion/src/mainwindow.cpp | 17 +++++++++++++++-- companion/src/mainwindow.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index c857a86fe..36e0286ba 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -1059,6 +1059,7 @@ void MainWindow::createActions() readFlashAct = addAct("read_flash.png", tr("Read Firmware from Radio"),tr("Read firmware from Radio"), SLOT(readFlash())); writeFlashAct = addAct("write_flash.png", tr("Write Firmware to Radio"), tr("Write firmware to Radio"), SLOT(writeFlash())); createProfileAct = addAct("", tr("Add Radio Profile"), tr("Create a new Radio Setting Profile"), SLOT(createProfile())); + copyProfileAct = addAct("", tr("Copy Current Radio Profile"), tr("Duplicate current Radio Setting Profile"), SLOT(copyProfile())); openDocURLAct = addAct("", tr("Manuals and other Documents"), tr("Open the OpenTX document page in a web browser"), SLOT(openDocURL())); writeEepromAct = addAct("write_eeprom.png", tr("Write Models and Settings To Radio"), tr("Write Models and Settings to Radio"), SLOT(writeEeprom())); readEepromAct = addAct("read_eeprom.png", tr("Read Models and Settings From Radio"), tr("Read Models and Settings from Radio"), SLOT(readEeprom())); @@ -1218,6 +1219,7 @@ QMenu *MainWindow::createProfilesMenu() profilesMenu->addSeparator(); profilesMenu->addAction(createProfileAct); + profilesMenu->addAction(copyProfileAct); profilesMenu->setIcon(CompanionIcon("profiles.png")); return profilesMenu; } @@ -1398,6 +1400,18 @@ void MainWindow::updateProfilesActions() } } + +void MainWindow::copyProfile() +{ + int previous = g.id(); + + createProfile(); + if (g.id() == previous) //Failed to find free slot + return; + g.profile[g.id()] = g.profile[previous]; + updateMenus(); +} + void MainWindow::createProfile() { int i; @@ -1405,8 +1419,7 @@ void MainWindow::createProfile() if (i==MAX_PROFILES) //Failed to find free slot return; - // Copy current profile to new and give it a new name - g.profile[i] = g.profile[g.id()]; + g.profile[i].init(i); g.profile[i].name(tr("New Radio")); g.id(i); diff --git a/companion/src/mainwindow.h b/companion/src/mainwindow.h index fa43cdb6a..90b199887 100644 --- a/companion/src/mainwindow.h +++ b/companion/src/mainwindow.h @@ -123,6 +123,7 @@ class MainWindow : public QMainWindow void fwPrefs(); void updateMenus(); void createProfile(); + void copyProfile(); void setActiveSubWindow(QWidget *window); void autoClose(); @@ -213,6 +214,7 @@ class MainWindow : public QMainWindow QAction *recentFileActs[MAX_RECENT]; QAction *profileActs[MAX_PROFILES]; QAction *createProfileAct; + QAction *copyProfileAct; QAction *openDocURLAct; };