Commit 16196c0f authored by Emmanuel Promayon's avatar Emmanuel Promayon

FIXED code cleaning

parent 5e46fc97
......@@ -473,7 +473,7 @@ void ImpMainWindow::updateViewMenu() {
// change the central viewer if there is more than one viewer in the central area
if (qobject_cast<QStackedWidget*>(centralWidget())->count() > 1) {
viewMenu->addSeparator()->setText(tr("Toggle Central Viewers"));
// add a toggle action for each widget stacked inside the central widget
for (int i = 0; i < qobject_cast<QStackedWidget*>(centralWidget())->count(); i++) {
QWidget* cWidget = qobject_cast<QStackedWidget*>(centralWidget())->widget(i);
......@@ -488,15 +488,15 @@ void ImpMainWindow::updateViewMenu() {
});
Viewer* cViewer = (*it);
// viewerAction is own by viewMenu, viewMenu->clear() will delete it
QAction *viewerAction = viewMenu->addAction(cViewer->objectName());
QAction* viewerAction = viewMenu->addAction(cViewer->objectName());
viewerAction->setCheckable(true);
viewerAction->setChecked(cViewer == centralViewer);
QString tipString = "Hide/show the " + cViewer->objectName() + " central viewer";
viewerAction->setStatusTip(tr(tipString.toStdString().c_str()));
viewerAction->setWhatsThis(tr(tipString.toStdString().c_str()));
// add the toggle action slot using C++11 lambda so that everything is contained inside viewMenu
connect(viewerAction, &QAction::toggled, [=](bool) {
setCentralViewer(cViewer);
connect(viewerAction, &QAction::toggled, [ = ](bool) {
setCentralViewer(cViewer);
});
}
}
......@@ -600,63 +600,65 @@ void ImpMainWindow::saveHistoryAsSCXML() {
// ------------------------- openDataDirectoryMenuBuilder ---------------------------
void ImpMainWindow::openDataDirectoryMenuBuilder() {
QStringList dirExt = ExtensionManager::getDataDirectoryExtNames();
QString dirExtName;
if (dirExt.size() > 1) {
if (fileOpenDataDirectoryMenu == nullptr){
if (fileOpenDataDirectoryMenu == nullptr) {
fileOpenDataDirectoryMenu = new QMenu("Open Data Directory");
fileMenu->addMenu(fileOpenDataDirectoryMenu);
} else {
disconnect(fileOpenDataDirectoryMenu,0,0,0);
}
else {
disconnect(fileOpenDataDirectoryMenu, 0, 0, 0);
fileOpenDataDirectoryMenu->clear();
}
fileOpenDataDirectoryMenu->setIcon(QPixmap(":/fileOpen"));
foreach (dirExtName, dirExt) {
for (QString dirExtName : dirExt) {
QAction* openDirectory = new QAction(dirExtName, this);
openDirectory->setStatusTip(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
openDirectory->setWhatsThis(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
connect(openDirectory, &QAction::triggered, this, [=]() {this->openDataDirectory(dirExtName);});
connect(openDirectory, &QAction::triggered, this, [ = ]() {
this->openDataDirectory(dirExtName);
});
fileOpenDataDirectoryMenu->addAction(openDirectory);
}
} else if (dirExt.size() == 1) {
QAction* openDirectoryAct;
dirExtName = dirExt.at(0);
int indexAction = 0;
bool updateAction = false;
bool IDidntFindWhatImLookingFor = true;
QList<QAction *> actions = fileMenu->actions();
int size = actions.size();
while (IDidntFindWhatImLookingFor && indexAction < actions.size() ) {
if (actions.at(indexAction)->text().contains(" Directory")) {
actions.at(indexAction)->destroyed();
updateAction = true;
IDidntFindWhatImLookingFor = false;
}
else
if (dirExt.size() == 1) {
// if it exists, remove the default directory extension menu (that has only one submenu)
// from the file "open" action list
bool updateAction = false;
QList<QAction*> menuActions = fileMenu->actions();
int indexAction = 0;
while (indexAction < menuActions.size() && !updateAction) {
if (menuActions.at(indexAction)->text().contains(" Directory")) {
menuActions.at(indexAction)->destroyed();
updateAction = true;
}
indexAction++;
}
// create the single open directory action
QString dirExtName = dirExt.at(0);
QAction* openDirectoryAction = new QAction("Open " + dirExtName + " Directory", this);
if (!updateAction) {
// there was no specific menu, just add the single "open directory" action in the file menu
fileMenu->addAction(openDirectoryAction);
}
indexAction++;
};
if (!updateAction) {
openDirectoryAct = new QAction("Open " + dirExtName + " Directory", this);
fileMenu->addAction(openDirectoryAct);
} else {
openDirectoryAct = new QAction("Open " + dirExtName + " Directory", this);
}
openDirectoryAct->setStatusTip(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
openDirectoryAct->setWhatsThis(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
openDirectoryAction->setStatusTip(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
openDirectoryAction->setWhatsThis(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
connect(openDirectoryAct, &QAction::triggered, this, [=]() {this->openDataDirectory(dirExtName);});
connect(openDirectoryAction, &QAction::triggered, this, [ = ]() {
this->openDataDirectory(dirExtName);
});
openDirectoryAct->setIcon(QPixmap(":/fileOpen"));
} else {
fileOpenDataDirectoryMenu = new QMenu("No plugins loaded to Open Data Directory");
fileOpenDataDirectoryMenu->setIcon(QPixmap(":/fileOpen"));
fileOpenDataDirectoryMenu->setEnabled(false);
fileMenu->addMenu(fileOpenDataDirectoryMenu);
}
openDirectoryAction->setIcon(QPixmap(":/fileOpen"));
}
else {
fileOpenDataDirectoryMenu = new QMenu("No plugins loaded to Open Data Directory");
fileOpenDataDirectoryMenu->setIcon(QPixmap(":/fileOpen"));
fileOpenDataDirectoryMenu->setEnabled(false);
fileMenu->addMenu(fileOpenDataDirectoryMenu);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment