ui: load project via MenuBar
This change adds a MenuBar to QtMainWindow and adds an action for opening a different project settings XML file. The message MessageLoadProject is thereon used to load a new project in the Application and clearing the Storage.
This commit is contained in:
+1
-1
@@ -12,7 +12,7 @@ int main(int argc, char *argv[])
|
||||
QtGuiFactory guiFactory;
|
||||
|
||||
std::shared_ptr<Application> app = Application::create(&guiFactory);
|
||||
app->loadProject();
|
||||
app->loadProject("data/ProjectSettings.xml");
|
||||
|
||||
return qtApp.exec();
|
||||
}
|
||||
|
||||
@@ -1,26 +1,69 @@
|
||||
#include "qt/element/QtMainWindow.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QFileDialog>
|
||||
#include <QDockWidget>
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "component/view/View.h"
|
||||
#include "qt/QtWidgetWrapper.h"
|
||||
#include "utility/messaging/type/MessageLoadProject.h"
|
||||
|
||||
QtMainWindow::QtMainWindow()
|
||||
{
|
||||
setObjectName("QtMainWindow");
|
||||
setCentralWidget(nullptr);
|
||||
|
||||
setupProjectMenu();
|
||||
setupHelpMenu();
|
||||
}
|
||||
|
||||
QtMainWindow::~QtMainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMainWindow::about()
|
||||
{
|
||||
QMessageBox::about(
|
||||
this,
|
||||
tr("About"),
|
||||
tr(
|
||||
"Developed by:\n\n"
|
||||
"Manuel Dobusch\n"
|
||||
"Eberhard Gräther\n"
|
||||
"Malte Langkabel\n"
|
||||
"Victoria Pfausler\n"
|
||||
"Andreas Stallinger\n"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void QtMainWindow::openProject(const QString &path)
|
||||
{
|
||||
QString fileName = path;
|
||||
|
||||
if (fileName.isNull())
|
||||
{
|
||||
fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", "XML Files (*.xml)");
|
||||
}
|
||||
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
std::cout << fileName.toStdString() << std::endl;
|
||||
MessageLoadProject message(fileName.toStdString());
|
||||
message.dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void QtMainWindow::addView(View* view)
|
||||
{
|
||||
QDockWidget* dock = new QDockWidget(tr(view->getName().c_str()), this);
|
||||
dock->setWidget(QtWidgetWrapper::getWidgetOfView(view));
|
||||
addDockWidget(Qt::TopDockWidgetArea, dock);
|
||||
m_dockWidgets.push_back(std::make_pair(view, dock));
|
||||
QDockWidget* dock = new QDockWidget(tr(view->getName().c_str()), this);
|
||||
dock->setWidget(QtWidgetWrapper::getWidgetOfView(view));
|
||||
addDockWidget(Qt::TopDockWidgetArea, dock);
|
||||
m_dockWidgets.push_back(std::make_pair(view, dock));
|
||||
}
|
||||
|
||||
void QtMainWindow::removeView(View* view)
|
||||
@@ -35,3 +78,21 @@ void QtMainWindow::removeView(View* view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtMainWindow::setupProjectMenu()
|
||||
{
|
||||
QMenu *fileMenu = new QMenu(tr("&Project"), this);
|
||||
menuBar()->addMenu(fileMenu);
|
||||
|
||||
fileMenu->addAction(tr("&Open..."), this, SLOT(openProject()), QKeySequence::Open);
|
||||
fileMenu->addAction(tr("E&xit"), QCoreApplication::instance(), SLOT(quit()), QKeySequence::Quit);
|
||||
}
|
||||
|
||||
void QtMainWindow::setupHelpMenu()
|
||||
{
|
||||
QMenu *helpMenu = new QMenu(tr("&Help"), this);
|
||||
menuBar()->addMenu(helpMenu);
|
||||
|
||||
helpMenu->addAction(tr("&About"), this, SLOT(about()));
|
||||
helpMenu->addAction(tr("About &Qt"), QCoreApplication::instance(), SLOT(aboutQt()));
|
||||
}
|
||||
|
||||
@@ -20,7 +20,14 @@ public:
|
||||
void addView(View* view);
|
||||
void removeView(View* view);
|
||||
|
||||
public slots:
|
||||
void about();
|
||||
void openProject(const QString &path = QString());
|
||||
|
||||
private:
|
||||
void setupProjectMenu();
|
||||
void setupHelpMenu();
|
||||
|
||||
std::vector<std::pair<View*, QDockWidget*> > m_dockWidgets;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user