Commit 79542953 authored by heretiK's avatar heretiK
Browse files

first commit

parents
CMakeLists.txt.user
cmake_minimum_required( VERSION 3.6 )
project( prototypator )
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" )
# translation files
set( ${PROJECT_NAME}_TS
en_GB
fr_FR
)
list( TRANSFORM ${PROJECT_NAME}_TS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/translation/${PROJECT_NAME}_" )
list( TRANSFORM ${PROJECT_NAME}_TS APPEND ".ts" )
# compilation
set( CMAKE_CXX_STANDARD 17 )
set( CXX_STANDARD_REQUIRED ON )
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-Wall -Wextra -pedantic -Werror -Weffc++)
endif()
add_subdirectory(src)
This diff is collapsed.
Prototypator - Test Your C++ code
=================================
Prototypator is a graphical tool designed to quickly compile
and run C++ code.
How to Get Help
---------------
Report bugs in Prototypator by opening an issue in the
[issue tracker](https://framagit.org/grislours/Prototypator/issues).
Remember to search for existing issues before creating a new one.
Build Environment
-----------------
* C++17 compiler
* Linux - GCC >= 8.2
* CMake >= 3.13
* Ninja (optional)
Dependencies
------------
External dependencies can be satisfied by system libraries or installed
separately.
**External Dependencies**
* Qt (required >= 5.0)
* boost (required >= 1.18)
How to Build
------------
Linux:
git clone https://framagit.org/grislours/prototypator.git
mkdir -p build/prototypator_release
cd build/prototypator_release
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ../../prototypator
If you have Qt installed in a non-standard location, you may have to
specify the path to Qt by passing `-DCMAKE_PREFIX_PATH=<path-to-qt>`
where `<path-to-qt>` points to the Qt install directory that contains
`bin`, `lib`, etc.
**Build**
ninja
How to Contribute
-----------------
We welcome contributions of all kinds, including bug fixes, new features,
documentation and translations. By contributing, you agree to release
your contributions under the terms of the license.
Contribute by following the typical
[GitLab workflow](https://about.gitlab.com/2014/09/29/gitlab-flow)
for pull requests. Fork the repository and make changes on a new named
branch. Create pull requests against the `master` branch. Follow the
[seven guidelines](https://chris.beams.io/posts/git-commit/) to writing a
great commit message.
License
-------
Prototypator code is licensed as AGPLv3. See LICENSE.md for details.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="256px"
height="256px"
viewBox="0 0 256 256"
version="1.1"
id="SVGRoot"
inkscape:version="0.92.4 5da689c313, 2019-01-14"
sodipodi:docname="icon.svg"
inkscape:export-filename="/home/hugo/workspace/qtcreator/prototypator/resources/icon-256.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96">
<defs
id="defs3725">
<linearGradient
inkscape:collect="always"
id="linearGradient2296">
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="0"
id="stop2292" />
<stop
style="stop-color:#000000;stop-opacity:0;"
offset="1"
id="stop2294" />
</linearGradient>
<linearGradient
id="linearGradient830"
osb:paint="solid">
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="0"
id="stop828" />
</linearGradient>
<linearGradient
id="linearGradient6015"
osb:paint="solid">
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="0"
id="stop6013" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient2296"
id="linearGradient2300"
x1="7.4284554"
y1="70.329491"
x2="248.25606"
y2="70.329491"
gradientUnits="userSpaceOnUse" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8284271"
inkscape:cx="-40.725424"
inkscape:cy="125.6515"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:window-width="1920"
inkscape:window-height="983"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:grid-bbox="true"
showguides="false"
inkscape:snap-text-baseline="false">
<inkscape:grid
type="xygrid"
id="grid3754"
empspacing="8" />
</sodipodi:namedview>
<metadata
id="metadata3728">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Calque 1"
inkscape:groupmode="layer"
id="layer1">
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:72.92785645px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;opacity:1;fill:#000000;fill-opacity:1;stroke:#fffffc;stroke-width:3.19003224;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;image-rendering:auto"
x="0.46343485"
y="153.48802"
id="text3740"
transform="scale(0.87703922,1.1401999)"><tspan
sodipodi:role="line"
id="tspan3738"
x="0.46343485"
y="153.48802"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:155.57922363px;line-height:1.25;font-family:'Liberation Serif';-inkscape-font-specification:'Liberation Serif, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke:#fffffc;stroke-width:3.19003224;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1">C++</tspan></text>
</g>
</svg>
add_subdirectory( prototypator )
add_subdirectory( utils )
project( prototypator )
set( CMAKE_AUTOMOC ON )
set( CMAKE_AUTOUIC ON )
set( CMAKE_AUTORCC ON )
set( CMAKE_INCLUDE_CURRENT_DIR ON )
find_package( Boost REQUIRED program_options regex )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5LinguistTools REQUIRED )
# source files
set( ${PROJECT_NAME}_SOURCES
main.cpp
mainwindow.cpp
mainwindow.ui
main.qrc
)
qt5_create_translation( QM_FILES ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_TS} )
# executable
include_directories( ${Boost_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/src )
add_executable( ${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES} ${QM_FILES} )
target_link_libraries( ${PROJECT_NAME} ${Boost_LIBRARIES} Qt5::Widgets )
#include "mainwindow.hpp"
#include "utils/qt/translator.hpp"
#include <QApplication>
#include <QLibraryInfo>
int main( int argc, char **argv ) {
// global settings
QCoreApplication::setOrganizationName( "gamasoft" );
QCoreApplication::setOrganizationDomain( "gamasoft.fr" );
QCoreApplication::setApplicationName( "prototypator" );
// start application
auto app = QApplication{ argc, argv };
auto qt_translator = qt::Translator{ app, "qt_", QLibraryInfo::location( QLibraryInfo::TranslationsPath ) };
auto app_translator = qt::Translator{ app, "prototypator_" };
auto mainWin = MainWindow{};
mainWin.show();
return QApplication::exec();
}
<RCC>
<qresource prefix="/">
<file>../../resources/icon-256.png</file>
</qresource>
</RCC>
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
#include <QSettings>
MainWindow::MainWindow( QWidget *parent )
: QMainWindow( parent )
, ui_ptr_{ new Ui::MainWindow }
{
ui_ptr_->setupUi( this );
restore_settings();
}
MainWindow::~MainWindow() = default;
void MainWindow::closeEvent( QCloseEvent *event )
{
auto settings = QSettings{};
settings.beginGroup( "main_window" );
settings.setValue( "geometry", saveGeometry() );
settings.setValue( "windowState", saveState() );
settings.endGroup();
QMainWindow::closeEvent( event );
}
void MainWindow::restore_settings()
{
auto settings = QSettings{};
settings.beginGroup( "main_window" );
restoreGeometry( settings.value( "geometry" ).toByteArray() );
restoreState( settings.value( "windowState" ).toByteArray() );
settings.endGroup();
}
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include <memory>
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow
: public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow( QWidget *parent = nullptr );
~MainWindow() override;
protected:
void closeEvent( QCloseEvent *event ) override;
private:
void restore_settings();
private:
std::unique_ptr<Ui::MainWindow> ui_ptr_;
};
#endif // MAINWINDOW_HPP
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="windowTitle">
<string>Prototypator</string>
</property>
<property name="windowIcon">
<iconset resource="main.qrc">
<normaloff>:/resources/icon-256.png</normaloff>:/resources/icon-256.png</iconset>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>C++ code:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTextEdit" name="textEdit_code"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_run">
<property name="text">
<string>Run</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Result:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="plainTextEdit_result">
<property name="palette">
<palette>
<active>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>208</red>
<green>208</green>
<blue>208</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>208</red>
<green>208</green>
<blue>208</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>68</red>
<green>68</green>
<blue>68</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources>
<include location="main.qrc"/>
</resources>
<connections/>
</ui>
project( utils )
include_directories()
#ifndef UTILS_EXCEPTION_HPP
#define UTILS_EXCEPTION_HPP
#include <iostream>
namespace utils {
template<typename Lambda_>
void ignore_exceptions( const Lambda_ &lambda ) {
try {
lambda();
} catch( const std::exception &e ) {
try {
std::cerr << std::string{ e.what() } + '\n';
} catch( ... ) {
// ignore
}
} catch( ... ) {
try {
std::cerr << "unknown error\n";
} catch( ... ) {
// ignore
}
}
}
}
#endif
#ifndef UTILS_OSTREAM_HPP
#define UTILS_OSTREAM_HPP
#include <array>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
namespace utils {
template<typename First_, typename Second_>
std::ostream &operator<<(
std::ostream &os,
const std::pair<First_, Second_> &pair
) {
os << pair.first << " : " << pair.second;
return os;
}
template<typename Iterator_>
std::ostream &operator<<(
std::ostream &os,
const std::tuple<Iterator_, Iterator_, const char *> &begin_end_separator
) {
os << '(';
bool is_first = true;
for(
Iterator_ it = std::get<0>( begin_end_separator );
it != std::get<1>( begin_end_separator );
++it
) {
if( not is_first ) {
os << std::get<2>( begin_end_separator );
}
os << *it;
is_first = false;
}
os << ')';
return os;
}
template<typename Type_>
std::ostream &operator<<( std::ostream &os, const std::set<Type_> &container ) {
return operator<<( os, std::make_tuple( container.begin(), container.end(), ", " ) );
}
template<typename Type_>
std::ostream &operator<<( std::ostream &os, const std::vector<Type_> &container ) {
return operator<<( os, std::make_tuple( container.begin(), container.end(), ", " ) );
}
template<typename Key_, typename Elt_>
std::ostream &operator<<( std::ostream &os, const std::map<Key_, Elt_> &container ) {
return operator<<( os, std::make_tuple( container.begin(), container.end(), "; " ) );
}
}
#endif
#ifndef QT_TRANSLATOR_HPP
#define QT_TRANSLATOR_HPP
#include <QApplication>
#include <QTranslator>
namespace qt {
class Translator {
public:
Translator(
QApplication &app,
const QString &prefix,
const QString &directory = QString{}
);
private:
QTranslator translator_;
};
}
qt::Translator::Translator( QApplication &app, const QString &prefix, const QString &directory )
: translator_{}
{
translator_.load( prefix + QLocale::system().name(), directory );
app.installTranslator( &translator_ );
}
#endif
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_GB">
<context>
<name>MainWindow</name>
<message>
<location filename="../src/prototypator/mainwindow.ui" line="14"/>
<source>Prototypator</source>
<translation></translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.ui" line="25"/>
<source>C++ code:</source>
<translation></translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.ui" line="52"/>
<source>Run</source>
<translation></translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.ui" line="63"/>
<source>Result:</source>
<translation></translation>
</message>