From 0827de9ce02b9b72dba67760f6ebccfdfbcdbd22 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sat, 9 Apr 2016 20:47:44 +0100 Subject: [PATCH] R integration and Version in About .. integration fixups for cross platform .. RInside will need to be built with callbacks enabled .. R Version is shown in about version --- src/Charts/RChart.h | 49 +++++++++++++++++++++++++++++++++++++++ src/Core/main.cpp | 22 ++++++++++++++++++ src/Gui/GcCrashDialog.cpp | 2 ++ src/Gui/GcCrashDialog.h | 3 +++ src/src.pro | 4 +++- 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/Charts/RChart.h diff --git a/src/Charts/RChart.h b/src/Charts/RChart.h new file mode 100644 index 000000000..fc56ce429 --- /dev/null +++ b/src/Charts/RChart.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 Mark Liversedge (liversedge@gmail.com) + * + * This program 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 2 of the License, or (at your option) + * any later version. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _GC_RChart_h +#define _GC_RChart_h 1 + +#include +#include +#include +#include + +class RCallbacks : public Callbacks { + public: + // see inst/includes/Callbacks.h for a list of all overrideable methods + virtual void WriteConsole(const std::string& line, int type) { + //qDebug()<<"Console>>" < +#include // for RCallback RInside *gc_RInside; +RCallbacks *gc_RCallbacks; +QString gc_RVersion; #endif // @@ -269,6 +272,25 @@ main(int argc, char *argv[]) // will be shared by all athletes and all charts (!!) RInside R(argc,argv); gc_RInside = &R; +#if !defined(RINSIDE_CALLBACKS) +#error "GC_WANT_R: RInside must have callbacks enabled (see inst/RInsideConfig.h)" +#else + gc_RCallbacks = new RCallbacks; + gc_RInside->set_callbacks(gc_RCallbacks); + + // lets get the version early for the about dialog + gc_RInside->parseEvalNT("print(R.version.string)"); + QStringList &version = gc_RCallbacks->getConsoleOutput(); + if (version.count() == 3) { + QRegExp exp("^.*\([0-9]+\.[0-9]+\.[0-9]+\).*$"); + if (exp.exactMatch(version[1])) gc_RVersion = exp.cap(1); + else gc_RVersion = version[1]; + } + version.clear(); + +#endif +#else + gc_RVersion = "none"; #endif // create the application -- only ever ONE regardless of restarts diff --git a/src/Gui/GcCrashDialog.cpp b/src/Gui/GcCrashDialog.cpp index 365f27789..8942592b7 100644 --- a/src/Gui/GcCrashDialog.cpp +++ b/src/Gui/GcCrashDialog.cpp @@ -313,6 +313,7 @@ QString GcCrashDialog::versionHTML() "VIDEO%15" "SAMPLERATE%16" "SSL%17" + "R%18" "" ) .arg(QT_VERSION_STR) @@ -340,6 +341,7 @@ QString GcCrashDialog::versionHTML() #endif .arg(src) .arg(QSslSocket::supportsSsl() ? "yes" : "none") + .arg(gc_RVersion) ; diff --git a/src/Gui/GcCrashDialog.h b/src/Gui/GcCrashDialog.h index dc0959e54..2f9abb59d 100644 --- a/src/Gui/GcCrashDialog.h +++ b/src/Gui/GcCrashDialog.h @@ -31,6 +31,9 @@ #include "Athlete.h" +// declared in main.cpp +extern QString gc_RVersion; + class GcCrashDialog : public QDialog { Q_OBJECT diff --git a/src/src.pro b/src/src.pro index eee138170..487b45ea4 100644 --- a/src/src.pro +++ b/src/src.pro @@ -258,7 +258,9 @@ contains(DEFINES, "GC_WANT_R") { ## compiler etc settings used in default make rules QMAKE_CXXFLAGS += $$RCPPWARNING $$RCPPFLAGS $$RCPPINCL $$RINSIDEINCL - LIBS += $$RLDFLAGS $$RBLAS $$RLAPACK $$RCPPLIBS $$RINSIDELIBS + LIBS += $$RLDFLAGS $$RBLAS $$RLAPACK $$RCPPLIBS $$RINSIDELIBS + + HEADERS += Charts/RChart.h }