mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-01-12 11:39:58 +01:00
new feature: changing the name of modes
This commit is contained in:
parent
6b81b307b7
commit
0cdc4b138a
|
|
@ -179,10 +179,14 @@ void ModeHandler::setStatusBarMessageChanged(const QString &msg)
|
|||
}
|
||||
}
|
||||
|
||||
bool ModeHandler::nameAllowed(const QString &name)
|
||||
bool ModeHandler::nameAllowed(const QString &name, unsigned int ignoreIndex)
|
||||
{
|
||||
for(auto m : modes) {
|
||||
if(m->getName() == name) {
|
||||
for(unsigned int i=0;i<modes.size();i++) {
|
||||
if(i == ignoreIndex) {
|
||||
// ignore possible collision at this index
|
||||
continue;
|
||||
}
|
||||
if(modes[i]->getName() == name) {
|
||||
/* name already taken, no duplicates allowed
|
||||
* when importing, name is used as value
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public:
|
|||
Mode* getMode(int index);
|
||||
std::vector<Mode*> getModes();
|
||||
|
||||
bool nameAllowed(const QString &name);
|
||||
bool nameAllowed(const QString &name, unsigned int ignoreIndex=-1);
|
||||
int findIndex(Mode *targetMode);
|
||||
Mode* findFirstOfType(Mode::Type t);
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ void ModeWindow::SetupUi()
|
|||
tabBar->setStyleSheet("QTabBar::tab { height: " + QString::number(aw->menuBar()->height()) + "px;}");
|
||||
tabBar->setTabsClosable(true);
|
||||
cornerWidget->layout()->addWidget(tabBar);
|
||||
connect(tabBar, &QTabBar::tabBarDoubleClicked, this, [=](int index) {
|
||||
renameMode(index);
|
||||
});
|
||||
|
||||
auto bAdd = new QPushButton();
|
||||
QIcon icon;
|
||||
|
|
@ -94,6 +97,11 @@ void ModeWindow::SetupUi()
|
|||
menu->addSeparator();
|
||||
auto submenuAdd = new QMenu("Create new");
|
||||
menu->addMenu(submenuAdd);
|
||||
auto rename = new QAction("Rename active mode");
|
||||
connect(rename, &QAction::triggered, this, [=](){
|
||||
renameMode(handler->getCurrentIndex());
|
||||
});
|
||||
menu->addAction(rename);
|
||||
|
||||
auto mAdd = new QMenu();
|
||||
for(unsigned int i=0;i<(int) Mode::Type::Last;i++) {
|
||||
|
|
@ -180,3 +188,19 @@ void ModeWindow::CurrentModeChanged(int modeIndex)
|
|||
}
|
||||
menuActions[modeIndex]->setChecked(true);
|
||||
}
|
||||
|
||||
void ModeWindow::renameMode(int modeIndex)
|
||||
{
|
||||
auto mode = handler->getMode(modeIndex);
|
||||
auto newName = QInputDialog::getText(this, "Rename", "Enter new name for mode \""+mode->getName()+"\":");
|
||||
if(newName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if(handler->nameAllowed(newName, modeIndex)) {
|
||||
mode->setName(newName);
|
||||
tabBar->setTabText(modeIndex, newName);
|
||||
menu->actions()[modeIndex]->setText(newName);
|
||||
} else {
|
||||
InformationBox::ShowError("Error", "Unable to set name. Mode names must be unique.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ private slots:
|
|||
void ModeCreated(int modeIndex);
|
||||
void ModeClosed(int modeIndex);
|
||||
void CurrentModeChanged(int modeIndex);
|
||||
void renameMode(int modeIndex);
|
||||
};
|
||||
|
||||
#endif // MODEWINDOW_H
|
||||
|
|
|
|||
Loading…
Reference in a new issue