Browse Source

well defined ui loading order

using boost exceptions
cl-refactor
arkpar 10 years ago
parent
commit
abc6d1d749
  1. 31
      mix/AppContext.cpp
  2. 2
      mix/AppContext.h
  3. 31
      mix/Exceptions.cpp
  4. 45
      mix/Exceptions.h
  5. 1
      mix/FileIo.cpp
  6. 5
      mix/MixApplication.cpp
  7. 17
      mix/main.cpp
  8. 2
      mix/qml/ProjectModel.qml

31
mix/AppContext.cpp

@ -22,7 +22,6 @@
* - KeyEventManager * - KeyEventManager
*/ */
#include <stdexcept>
#include <QDebug> #include <QDebug>
#include <QMessageBox> #include <QMessageBox>
#include <QQmlComponent> #include <QQmlComponent>
@ -32,6 +31,8 @@
#include "CodeModel.h" #include "CodeModel.h"
#include "FileIo.h" #include "FileIo.h"
#include "ClientModel.h" #include "ClientModel.h"
#include "CodeEditorExtensionManager.h"
#include "Exceptions.h"
#include "AppContext.h" #include "AppContext.h"
using namespace dev; using namespace dev;
@ -47,21 +48,31 @@ AppContext::AppContext(QQmlApplicationEngine* _engine)
m_codeModel.reset(new CodeModel(this)); m_codeModel.reset(new CodeModel(this));
m_clientModel.reset(new ClientModel(this)); m_clientModel.reset(new ClientModel(this));
m_fileIo.reset(new FileIo()); m_fileIo.reset(new FileIo());
}
AppContext::~AppContext()
{
}
void AppContext::load()
{
m_applicationEngine->rootContext()->setContextProperty("appContext", this); m_applicationEngine->rootContext()->setContextProperty("appContext", this);
qmlRegisterType<FileIo>("org.ethereum.qml", 1, 0, "FileIo"); qmlRegisterType<FileIo>("org.ethereum.qml", 1, 0, "FileIo");
m_applicationEngine->rootContext()->setContextProperty("codeModel", m_codeModel.get());
m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get());
QQmlComponent projectModelComponent(m_applicationEngine, QUrl("qrc:/qml/ProjectModel.qml")); QQmlComponent projectModelComponent(m_applicationEngine, QUrl("qrc:/qml/ProjectModel.qml"));
QObject* projectModel = projectModelComponent.create(); QObject* projectModel = projectModelComponent.create();
if (projectModelComponent.isError()) if (projectModelComponent.isError())
throw std::runtime_error("Error loading ProjectModel: " + projectModelComponent.errorString().toStdString()); {
QQmlEngine::setObjectOwnership(projectModel, QQmlEngine::JavaScriptOwnership); QmlLoadException exception;
for (auto const& e : projectModelComponent.errors())
exception << QmlErrorInfo(e);
BOOST_THROW_EXCEPTION(exception);
}
m_applicationEngine->rootContext()->setContextProperty("projectModel", projectModel); m_applicationEngine->rootContext()->setContextProperty("projectModel", projectModel);
m_applicationEngine->rootContext()->setContextProperty("codeModel", m_codeModel.get()); qmlRegisterType<CodeEditorExtensionManager>("CodeEditorExtensionManager", 1, 0, "CodeEditorExtensionManager");
m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get()); m_applicationEngine->load(QUrl("qrc:/qml/main.qml"));
appLoaded();
}
AppContext::~AppContext()
{
} }
QQmlApplicationEngine* AppContext::appEngine() QQmlApplicationEngine* AppContext::appEngine()

2
mix/AppContext.h

@ -60,6 +60,8 @@ class AppContext: public QObject
public: public:
AppContext(QQmlApplicationEngine* _engine); AppContext(QQmlApplicationEngine* _engine);
virtual ~AppContext(); virtual ~AppContext();
/// Load the UI from qml files
void load();
/// Get the current QQMLApplicationEngine instance. /// Get the current QQMLApplicationEngine instance.
QQmlApplicationEngine* appEngine(); QQmlApplicationEngine* appEngine();
/// Get code model /// Get code model

31
mix/Exceptions.cpp

@ -0,0 +1,31 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Exceptions.cpp
* @author Arkadiy Paronyan arkadiy@ethdev.com
* @date 2015
* Ethereum IDE client.
*/
#include <ostream>
#include <QQmlError>
#include "Exceptions.h"
std::ostream& operator<<(std::ostream& _out, QQmlError const& _error)
{
_out << _error.toString().toStdString();
return _out;
}

45
mix/Exceptions.h

@ -0,0 +1,45 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Exceptions.h
* @author Arkadiy Paronyan arkadiy@ethdev.com
* @date 2015
* Ethereum IDE client.
*/
#pragma once
#include <iosfwd>
#include <libdevcore/Exceptions.h>
class QTextDocument;
class QQmlError;
namespace dev
{
namespace mix
{
struct QmlLoadException: virtual Exception {};
struct FileIoException: virtual Exception {};
typedef boost::error_info<struct tagQmlError, QQmlError> QmlErrorInfo;
typedef boost::error_info<struct tagFileError, std::string> FileError;
}
}
std::ostream& operator<<(std::ostream& _out, QQmlError const& _error);

1
mix/FileIo.cpp

@ -20,7 +20,6 @@
* Ethereum IDE client. * Ethereum IDE client.
*/ */
#include <stdexcept>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>

5
mix/MixApplication.cpp

@ -21,7 +21,6 @@
#include <QDebug> #include <QDebug>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include "CodeEditorExtensionManager.h"
#include "MixApplication.h" #include "MixApplication.h"
#include "AppContext.h" #include "AppContext.h"
@ -32,10 +31,8 @@ using namespace dev::mix;
MixApplication::MixApplication(int _argc, char* _argv[]): MixApplication::MixApplication(int _argc, char* _argv[]):
QApplication(_argc, _argv), m_engine(new QQmlApplicationEngine()), m_appContext(new AppContext(m_engine.get())) QApplication(_argc, _argv), m_engine(new QQmlApplicationEngine()), m_appContext(new AppContext(m_engine.get()))
{ {
qmlRegisterType<CodeEditorExtensionManager>("CodeEditorExtensionManager", 1, 0, "CodeEditorExtensionManager");
QObject::connect(this, SIGNAL(lastWindowClosed()), context(), SLOT(quitApplication())); //use to kill ApplicationContext and other stuff QObject::connect(this, SIGNAL(lastWindowClosed()), context(), SLOT(quitApplication())); //use to kill ApplicationContext and other stuff
m_engine->load(QUrl("qrc:/qml/main.qml")); m_appContext->load();
m_appContext->appLoaded();
} }
MixApplication::~MixApplication() MixApplication::~MixApplication()

17
mix/main.cpp

@ -20,11 +20,24 @@
* Ethereum IDE client. * Ethereum IDE client.
*/ */
#include <iostream>
#include "MixApplication.h" #include "MixApplication.h"
#include "Exceptions.h"
using namespace dev::mix; using namespace dev::mix;
int main(int _argc, char* _argv[]) int main(int _argc, char* _argv[])
{ {
MixApplication app(_argc, _argv); try
return app.exec(); {
MixApplication app(_argc, _argv);
return app.exec();
}
catch (boost::exception const& _e)
{
std::cerr << boost::diagnostic_information(_e);
}
catch (std::exception const& _e)
{
std::cerr << _e.what();
}
} }

2
mix/qml/ProjectModel.qml

@ -44,7 +44,7 @@ Item {
target: appContext target: appContext
onAppLoaded: { onAppLoaded: {
if (projectSettings.lastProjectPath) if (projectSettings.lastProjectPath)
loadProject(projectSettings.lastProjectPath) projectModel.loadProject(projectSettings.lastProjectPath)
} }
} }

Loading…
Cancel
Save