mirror of https://github.com/CGAL/cgal
Merge pull request #4857 from lrineau/Polyhedron-demo__fix_runtime_warning-GF
3D demo MainWindow.cpp: Reimplement addActionToMenu with standard algorithms
This commit is contained in:
commit
71368f3d0b
|
|
@ -409,32 +409,18 @@ MainWindow::MainWindow(const QStringList &keywords, bool verbose, QWidget* paren
|
||||||
|
|
||||||
void addActionToMenu(QAction* action, QMenu* menu)
|
void addActionToMenu(QAction* action, QMenu* menu)
|
||||||
{
|
{
|
||||||
bool added = false;
|
auto actions = menu->actions();
|
||||||
QString atxt = action->text().remove("&");
|
auto it = std::lower_bound(actions.begin(), actions.end(),
|
||||||
if(atxt.isEmpty())
|
action->text().remove("&"),
|
||||||
return;
|
[](QAction* a, QString text) {
|
||||||
for(QAction* it : menu->actions())
|
return a->text().remove("&").compare(text) < 0;
|
||||||
{
|
});
|
||||||
QString btxt = it->text().remove("&");
|
if(it == actions.end()) {
|
||||||
int i = 0;
|
|
||||||
if(btxt.isEmpty())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
while(i < atxt.size()
|
|
||||||
&& i < btxt.size()
|
|
||||||
&& atxt[i] == btxt[i])
|
|
||||||
++i;
|
|
||||||
bool res = (i == atxt.size() || i == btxt.size() || atxt[i] < btxt[i]);
|
|
||||||
if (res)
|
|
||||||
{
|
|
||||||
menu->insertAction(it, action);
|
|
||||||
added = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!added)
|
|
||||||
menu->addAction(action);
|
menu->addAction(action);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
menu->insertAction(*it, action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Recursive function that do a pass over a menu and its sub-menus(etc.) and hide them when they are empty
|
//Recursive function that do a pass over a menu and its sub-menus(etc.) and hide them when they are empty
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue