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;
|
||||
};
|
||||
|
||||
|
||||
+10
-3
@@ -23,6 +23,8 @@ std::shared_ptr<Application> Application::create(GuiFactory* guiFactory)
|
||||
ptr->m_componentManager =
|
||||
ComponentManager::create(guiFactory, ptr->m_mainView.get(), ptr->m_storage, ptr->m_storage);
|
||||
|
||||
ptr->m_componentManager->setup();
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -36,14 +38,19 @@ Application::~Application()
|
||||
MessageQueue::getInstance()->stopMessageLoop();
|
||||
}
|
||||
|
||||
void Application::loadProject()
|
||||
void Application::loadProject(const std::string& projectSettingsFilePath)
|
||||
{
|
||||
m_componentManager->setup();
|
||||
m_storage->clear();
|
||||
m_project = Project::create(m_storage);
|
||||
|
||||
m_project->loadProjectSettings("data/ProjectSettings.xml");
|
||||
m_project->loadProjectSettings(projectSettingsFilePath);
|
||||
m_project->parseCode();
|
||||
|
||||
MessageActivateToken message(1);
|
||||
message.dispatch();
|
||||
}
|
||||
|
||||
void Application::handleMessage(MessageLoadProject* message)
|
||||
{
|
||||
loadProject(message->projectSettingsFilePath);
|
||||
}
|
||||
|
||||
@@ -5,23 +5,27 @@
|
||||
|
||||
#include "component/ComponentManager.h"
|
||||
#include "Project.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageLoadProject.h"
|
||||
|
||||
class GuiFactory;
|
||||
class MainView;
|
||||
class Storage;
|
||||
|
||||
class Application
|
||||
class Application: public MessageListener<MessageLoadProject>
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<Application> create(GuiFactory* guiFactory);
|
||||
|
||||
~Application();
|
||||
|
||||
void loadProject();
|
||||
void loadProject(const std::string& projectSettingsFilePath);
|
||||
|
||||
private:
|
||||
Application();
|
||||
|
||||
virtual void handleMessage(MessageLoadProject* message);
|
||||
|
||||
std::shared_ptr<Project> m_project;
|
||||
std::shared_ptr<Storage> m_storage;
|
||||
|
||||
|
||||
@@ -130,6 +130,8 @@ add_files(
|
||||
utility/math/VectorBase.h
|
||||
|
||||
utility/messaging/type/MessageActivateToken.h
|
||||
utility/messaging/type/MessageFinishedParsing.h
|
||||
utility/messaging/type/MessageLoadProject.h
|
||||
|
||||
utility/messaging/Message.h
|
||||
utility/messaging/MessageBase.h
|
||||
|
||||
+21
-14
@@ -18,6 +18,27 @@ Storage::~Storage()
|
||||
{
|
||||
}
|
||||
|
||||
void Storage::clear()
|
||||
{
|
||||
m_graph.clear();
|
||||
m_locationCollection.clear();
|
||||
}
|
||||
|
||||
void Storage::logGraph() const
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "\n" << m_graph;
|
||||
LOG_INFO(str.str());
|
||||
}
|
||||
|
||||
void Storage::logLocations() const
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "\n" << m_locationCollection;
|
||||
LOG_INFO(str.str());
|
||||
}
|
||||
|
||||
|
||||
void Storage::onTypedefParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const std::string& underlyingFullName,
|
||||
AccessType access
|
||||
@@ -188,20 +209,6 @@ void Storage::onCallParsed(const ParseLocation& location, const std::string& cal
|
||||
addTokenLocation(edge, location);
|
||||
}
|
||||
|
||||
void Storage::logGraph() const
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "\n" << m_graph;
|
||||
LOG_INFO(str.str());
|
||||
}
|
||||
|
||||
void Storage::logLocations() const
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "\n" << m_locationCollection;
|
||||
LOG_INFO(str.str());
|
||||
}
|
||||
|
||||
|
||||
Id Storage::getIdForNodeWithName(const std::string& name) const
|
||||
{
|
||||
|
||||
@@ -19,6 +19,12 @@ public:
|
||||
Storage();
|
||||
virtual ~Storage();
|
||||
|
||||
void clear();
|
||||
|
||||
void logGraph() const;
|
||||
void logLocations() const;
|
||||
|
||||
// ParserClient implementation
|
||||
virtual void onTypedefParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const std::string& underlyingFullName,
|
||||
AccessType access
|
||||
@@ -47,9 +53,6 @@ public:
|
||||
virtual void onCallParsed(
|
||||
const ParseLocation& location, const std::string& callerName, const std::string& calleeName);
|
||||
|
||||
void logGraph() const;
|
||||
void logLocations() const;
|
||||
|
||||
// GraphAccess implementation
|
||||
virtual Id getIdForNodeWithName(const std::string& name) const;
|
||||
virtual std::string getNameForNodeWithId(Id id) const;
|
||||
|
||||
@@ -223,6 +223,12 @@ void Graph::forEachToken(std::function<void(Token*)> func) const
|
||||
forEachEdge(func);
|
||||
}
|
||||
|
||||
void Graph::clear()
|
||||
{
|
||||
m_edges.clear();
|
||||
m_nodes.clear();
|
||||
}
|
||||
|
||||
const std::vector<std::shared_ptr<Node> >& Graph::getNodes() const
|
||||
{
|
||||
return m_nodes;
|
||||
|
||||
@@ -38,6 +38,8 @@ public:
|
||||
Node* addNodeAsPlainCopy(Node* node);
|
||||
Edge* addEdgeAsPlainCopy(Edge* edge);
|
||||
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
const std::vector<std::shared_ptr<Node> >& getNodes() const;
|
||||
const std::vector<std::shared_ptr<Edge> >& getEdges() const;
|
||||
|
||||
@@ -129,6 +129,12 @@ TokenLocation* TokenLocationCollection::addTokenLocationAsPlainCopy(const TokenL
|
||||
return copy;
|
||||
}
|
||||
|
||||
void TokenLocationCollection::clear()
|
||||
{
|
||||
m_locations.clear();
|
||||
m_files.clear();
|
||||
}
|
||||
|
||||
TokenLocationFile* TokenLocationCollection::createTokenLocationFile(const std::string& filePath)
|
||||
{
|
||||
TokenLocationFile* file = findTokenLocationFileByPath(filePath);
|
||||
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
|
||||
TokenLocation* addTokenLocationAsPlainCopy(const TokenLocation* location);
|
||||
|
||||
void clear();
|
||||
|
||||
private:
|
||||
TokenLocationFile* createTokenLocationFile(const std::string& filePath);
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef MESSAGE_LOAD_PROJECT_H
|
||||
#define MESSAGE_LOAD_PROJECT_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
class MessageLoadProject: public Message<MessageLoadProject>
|
||||
{
|
||||
public:
|
||||
MessageLoadProject(const std::string& filePath)
|
||||
: projectSettingsFilePath(filePath)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageLoadProject";
|
||||
}
|
||||
|
||||
const std::string projectSettingsFilePath;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_LOAD_PROJECT_H
|
||||
Reference in New Issue
Block a user