Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R Syntax: Load QML Controls as QML Module #5785

Merged
merged 22 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (UNIX)
add_compile_options(-Werror=return-type)
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(APPLE)

Expand Down Expand Up @@ -58,7 +59,7 @@ project(
HOMEPAGE_URL "http://jasp-stats.org/"
DESCRIPTION "A fresh way to do statistics")

#needed for R-Interface and QMLComponents for them to build stuff porperly when *inside* JASP
#needed for R-Interface and QMLComponents for them to build stuff properly when *inside* JASP
add_definitions(-DBUILDING_JASP)
set(BUILDING_JASP TRUE)

Expand Down Expand Up @@ -93,6 +94,13 @@ include(Config)
# ------ Conan Dependency Manager

include(Conan)
# Conan set the CMAKE_MSVC_RUNTIME_LIBRARY to MultiThreadedDLL (this adds the /MD flag, cf conan_toolchain.cmake)
# But on debug mode it does not set it to the MultiThreadedDebugDLL (/MDd): this can lead to a crash if a library uses a Qt function in a static method, as in DynamicRuntimeInfo)
if(WIN32 AND (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "$<$<CONFIG:Debug>:MultiThreadedDLL>"))
set(CMAKE_MSVC_RUNTIME_LIBRARY "$<$<CONFIG:Debug>:MultiThreadedDebugDLL>")
message(STATUS "CMAKE_MSVC_RUNTIME_LIBRARY is set to ${CMAKE_MSVC_RUNTIME_LIBRARY}")
endif()


# ------ JASP Config

Expand Down
23 changes: 12 additions & 11 deletions Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@ message(STATUS "appinfo.cpp is successfully generated...")
file(GLOB_RECURSE HEADER_FILES "${CMAKE_CURRENT_LIST_DIR}/*.h")
file(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/*.cpp")

add_library(Common ${SOURCE_FILES} ${HEADER_FILES})
add_library(Common STATIC ${SOURCE_FILES} ${HEADER_FILES})

if(LINUX)
target_link_libraries(Common PUBLIC ${_LIB_RT})
target_link_options(Common PUBLIC -lrt)
endif()

target_include_directories(
Common
PUBLIC # JASP
${PROJECT_SOURCE_DIR}/Common/jaspColumnEncoder
# R
${R_INCLUDE_PATH}
${R_HOME_PATH}/include
${RCPP_PATH}/include
Common
PUBLIC
${PROJECT_SOURCE_DIR}/Common/jaspColumnEncoder
# R
${R_INCLUDE_PATH}
${R_HOME_PATH}/include
${RCPP_PATH}/include
${Boost_INCLUDE_DIRS}
)

target_link_libraries(
Expand All @@ -40,13 +41,12 @@ target_link_libraries(
Boost::timer
Boost::chrono
$<$<BOOL:${WINDOWS}>:ntdll>
$<$<BOOL:${JASP_USES_QT_HERE}>:Qt::Core>
)

target_compile_definitions(
Common PUBLIC $<$<BOOL:${JASP_USES_QT_HERE}>:JASP_USES_QT_HERE>
Common PUBLIC
$<$<BOOL:${JASP_TIMER_USED}>:PROFILE_JASP>
JSONCPP_NO_LOCALE_SUPPORT )
JSONCPP_NO_LOCALE_SUPPORT )

if(WINDOWS)
target_compile_definitions(
Expand All @@ -59,4 +59,5 @@ if(IWYU_EXECUTABLE AND RUN_IWYU)
set_target_properties(Common PROPERTIES CXX_INCLUDE_WHAT_YOU_USE ${IWYU_EXECUTABLE})
endif()


list(POP_BACK CMAKE_MESSAGE_CONTEXT)
2 changes: 1 addition & 1 deletion Common/jaspColumnEncoder
Submodule jaspColumnEncoder updated 1 files
+4 −4 utils.cpp
12 changes: 6 additions & 6 deletions Common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class Log
static void redirectStdOut();
static const char * getTimestamp();

static logType _default;
static logType _where;
static std::string _logFilePath;
static logError _logError;
static int _stdoutfd,
_engineNo;
static logType _default;
static logType _where;
static std::string _logFilePath;
static logError _logError;
static int _stdoutfd,
_engineNo;
static std::ostream* _nullStream;
static std::ofstream _logFile;

Expand Down
20 changes: 11 additions & 9 deletions CommonData/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ file(GLOB_RECURSE HEADER_FILES "${CMAKE_CURRENT_LIST_DIR}/*.h")
file(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/*.cpp")
file(GLOB_RECURSE SQL_FILES "${CMAKE_CURRENT_LIST_DIR}/*.sql")

add_library(CommonData ${SOURCE_FILES} ${HEADER_FILES} ${SQL_FILES})
add_library(CommonData STATIC ${SOURCE_FILES} ${HEADER_FILES} ${SQL_FILES})


if(LINUX)
Expand All @@ -33,19 +33,21 @@ target_include_directories(
${R_INCLUDE_PATH}
${R_HOME_PATH}/include
${RCPP_PATH}/include
${Boost_INCLUDE_DIRS}
PRIVATE
SQLite::SQLite3
)

target_link_libraries(
CommonData
PUBLIC
Common
LibArchive::LibArchive
SQLite::SQLite3
#
$<$<BOOL:${JASP_USES_QT_HERE}>:Qt::Core>)
CommonData
PUBLIC
LibArchive::LibArchive
# Common
SQLite::SQLite3
)

target_compile_definitions(
CommonData PUBLIC $<$<BOOL:${JASP_USES_QT_HERE}>:JASP_USES_QT_HERE>
CommonData PUBLIC
$<$<BOOL:${JASP_TIMER_USED}>:PROFILE_JASP>
JSONCPP_NO_LOCALE_SUPPORT )

Expand Down
21 changes: 11 additions & 10 deletions CommonData/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "dataset.h"
#include "columnutils.h"
#include "databaseinterface.h"
#include <cassert>

bool Column::_autoSortByValuesByDefault = true;

Expand Down Expand Up @@ -435,7 +436,7 @@ stringset Column::mergeOldMissingDataMap(const Json::Value &missingData)
stringset foundEmpty;

std::map<std::string, Label*> displayToLabel; //Keep track of which labels we added because only those could possibly be derived from missingDataMap
for(qsizetype r=0; r<_ints.size(); r++)
for(size_t r=0; r<_ints.size(); r++)
{
const std::string row = std::to_string(r);
if(missingData.isMember(row))
Expand Down Expand Up @@ -940,7 +941,7 @@ int Column::labelsTempCount()
_labelsTemp . push_back(doubleLabel);
_labelsTempDbls . push_back(dbl);
_labelsTempToIndex[doubleLabel] = _labelsTemp.size()-1;
_labelsTempMaxWidth = std::max(_labelsTempMaxWidth, qsizetype(_labelsTemp[_labelsTemp.size()-1].size()));
_labelsTempMaxWidth = std::max(_labelsTempMaxWidth, size_t(_labelsTemp[_labelsTemp.size()-1].size()));
_labelsTempNumerics ++;
}
}
Expand Down Expand Up @@ -983,7 +984,7 @@ stringvec Column::nonFilteredLevels()
levels.insert(label->label());
}
else if(!isEmptyValue(_dbls[r]))
levels.insert(ColumnUtils::doubleToString(_dbls[r]));
levels.insert(ColumnUtils::doubleToString(_dbls[r]));
}

// Use the right label order
Expand Down Expand Up @@ -1777,15 +1778,15 @@ bool Column::labelsRemoveOrphans()
return idsNotUsed.size();
}

std::set<size_t> Column::labelsMoveRows(std::vector<qsizetype> rows, bool up)
std::set<size_t> Column::labelsMoveRows(std::vector<size_t> rows, bool up)
{
JASPTIMER_SCOPE(Column::labelsMoveRows);

int mod = up ? -1 : 1;

std::sort(rows.begin(), rows.end(), [&](const auto & l, const auto & r) { return up ? l < r : r < l; });

replaceDoublesTillLabelsRowWithLabels(std::min(qsizetype(labelsTempCount()), rows.back() + 1));
replaceDoublesTillLabelsRowWithLabels(std::min(size_t(labelsTempCount()), rows.back() + 1));

std::vector<Label*> new_labels(_labels.begin(), _labels.end());

Expand Down Expand Up @@ -2020,7 +2021,7 @@ void Column::upgradeExtractDoublesIntsFromLabels()
{
_dbls.resize(_ints.size());

for(qsizetype r=0; r<_dbls.size(); r++)
for(size_t r=0; r<_dbls.size(); r++)
{
Label * label = labelByIntsId(_ints[r]);

Expand Down Expand Up @@ -2318,7 +2319,7 @@ bool Column::isEmptyValue(const double val) const
return _emptyValues->isEmptyValue(val);
}

qsizetype Column::getMaximumWidthInCharactersIncludingShadow()
size_t Column::getMaximumWidthInCharactersIncludingShadow()
{
bool thereIsAShadow = false;

Expand All @@ -2337,9 +2338,9 @@ qsizetype Column::getMaximumWidthInCharactersIncludingShadow()
}


qsizetype Column::getMaximumWidthInCharacters(bool fancyEmptyValue, bool valuesPlease, qsizetype extraPad)
size_t Column::getMaximumWidthInCharacters(bool fancyEmptyValue, bool valuesPlease, size_t extraPad)
{
qsizetype maxWidth = 0;
size_t maxWidth = 0;
std::string takeWidth;

//Call labelsTempCount() to both find out how many there are and generate them if necessary
Expand All @@ -2349,7 +2350,7 @@ qsizetype Column::getMaximumWidthInCharacters(bool fancyEmptyValue, bool valuesP
for(Label * label : labels())
{
takeWidth = !valuesPlease ? label->label() : label->originalValueAsString(fancyEmptyValue);
maxWidth = std::max(maxWidth, qsizetype(stringUtils::approximateVisualLength(takeWidth)));
maxWidth = std::max(maxWidth, size_t(stringUtils::approximateVisualLength(takeWidth)));
}


Expand Down
10 changes: 5 additions & 5 deletions CommonData/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "utils.h"
#include <list>
#include "emptyvalues.h"

#include <cmath>
class DataSet;
class Analysis;

Expand Down Expand Up @@ -133,7 +133,7 @@ class Column : public DataSetBaseNode
stringvec nonFilteredLevels();
void nonFilteredCountersReset();

std::set<size_t> labelsMoveRows(std::vector<qsizetype> rows, bool up);
std::set<size_t> labelsMoveRows(std::vector<size_t> rows, bool up);
void labelsReverse();
void valuesReverse();
void labelsOrderByValue(bool doDbUpdateEtc=true);
Expand Down Expand Up @@ -226,8 +226,8 @@ class Column : public DataSetBaseNode
bool isEmptyValue( const std::string & val) const;
bool isEmptyValue( const double val) const;

qsizetype getMaximumWidthInCharactersIncludingShadow();
qsizetype getMaximumWidthInCharacters(bool shortenAndFancyEmptyValue, bool valuesPlease, qsizetype extraPad = 4); ///< Tries to take into consideration that utf-8 can have more characters than codepoints and compensates for it
size_t getMaximumWidthInCharactersIncludingShadow();
size_t getMaximumWidthInCharacters(bool shortenAndFancyEmptyValue, bool valuesPlease, size_t extraPad = 4); ///< Tries to take into consideration that utf-8 can have more characters than codepoints and compensates for it
columnType resetValues(int thresholdScale); ///< "Reimport" the values it already has with a possibly different threshold of values
stringset mergeOldMissingDataMap(const Json::Value & missingData); ///< <0.19 JASP collected the removed empty values values in a map in a json object... We need to be able to read at least 0.18.3 so here this function that absorbs such a map and adds any required labels. It does not add the empty values itself though!

Expand Down Expand Up @@ -258,7 +258,7 @@ class Column : public DataSetBaseNode
_labelsTempRevision = -1, ///< When were the "temporary labels" created?
_labelsTempNumerics = 0, ///< Use the labelsTemp step to calculate the amount of numeric labels
_highestIntsId = -1;
qsizetype _labelsTempMaxWidth = 0;
size_t _labelsTempMaxWidth = 0;
stringvec _labelsTemp; ///< Contains displaystring for labels. Used to allow people to edit "double" labels. Initialized when necessary
doublevec _labelsTempDbls;
strintmap _labelsTempToIndex;
Expand Down
3 changes: 0 additions & 3 deletions CommonData/columnutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#define COLUMNUTILS_H

#include <string>
#include <vector>
#include <set>
#include <map>
#include "utils.h"

class ColumnUtils
Expand Down
15 changes: 14 additions & 1 deletion CommonData/databaseinterface.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "databaseinterface.h"
#include "columntype.h"
#include "tempfiles.h"
#include <sqlite3.h>
#include "version.h"
#include "dataset.h"
#include "timers.h"
#include "utils.h"
#include <cassert>
#include "log.h"

DatabaseInterface * DatabaseInterface::_singleton = nullptr;
Expand Down Expand Up @@ -302,7 +304,7 @@ bool DatabaseInterface::filterSelect(int filterIndex, boolvec & bools)
[&](sqlite3_stmt *){ }, [&](size_t row, sqlite3_stmt * stmt)
{
int val = sqlite3_column_int(stmt, 0);
changed = changed || bools[row] != val;
changed = changed || bools[row] != bool(val);
bools[row] = val;
});
}
Expand Down Expand Up @@ -1367,6 +1369,17 @@ std::string DatabaseInterface::dbFile(bool onlyName) const
return onlyName ? fileName : Utils::osPath(TempFiles::sessionDirName() + "/" + fileName).string();
}

DatabaseInterface *DatabaseInterface::singleton()
{
if(!_singleton)
{
Log::log() << "No DatabaseInterface::singleton available here yet, creating an interface for internal.sqlite without recreating the dbstructure" << std::endl;
_singleton = new DatabaseInterface(false);
}

return _singleton;
}

void DatabaseInterface::runQuery(const std::string & query, std::function<void(sqlite3_stmt *stmt)> bindParameters, std::function<void(size_t row, sqlite3_stmt *stmt)> processRow)
{
JASPTIMER_SCOPE(DatabaseInterface::runQuery);
Expand Down
7 changes: 4 additions & 3 deletions CommonData/databaseinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
#define DATABASEINTERFACE_H

#include "columntype.h"
#include <sqlite3.h>
#include <string>
#include "utils.h"
#include <json/json.h>
#include "version.h"

#include <functional>

class DataSet;
class Column;
class DatabaseInterface;
struct sqlite3_stmt;
struct sqlite3;

///Single point of interaction with sqlite, can later be turned into an interface for supporting other sql
///
Expand Down Expand Up @@ -60,7 +61,7 @@ class DatabaseInterface
~DatabaseInterface();
std::string dbFile(bool onlyPostfix = false) const; ///< Convenience function for getting the filename where sqlite db should be

static DatabaseInterface * singleton() { return _singleton; } ///< There can be only one! https://www.youtube.com/watch?v=sqcLjcSloXs
static DatabaseInterface * singleton(); ///< There can be only one! https://www.youtube.com/watch?v=sqcLjcSloXs

bool hasConnection() { return _db; }
void upgradeDBFromVersion(Version originalVersion); ///< Ensures that the database has all the fields configured as required for the current JASP version, useful when loading older sqlite-containing jasp-files
Expand Down
4 changes: 2 additions & 2 deletions CommonData/dataset.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "log.h"
#include <regex>
#include <cassert>
#include "timers.h"
#include "dataset.h"
#include "columnencoder.h"
Expand Down Expand Up @@ -200,7 +200,7 @@ Column * DataSet::newColumn(const std::string &name)
return col;
}

qsizetype DataSet::getMaximumColumnWidthInCharacters(size_t columnIndex) const
size_t DataSet::getMaximumColumnWidthInCharacters(size_t columnIndex) const
{
if(columnIndex >= columnCount())
return 0;
Expand Down
2 changes: 1 addition & 1 deletion CommonData/dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DataSet : public DataSetBaseNode

bool allColumnsPassFilter() const;

qsizetype getMaximumColumnWidthInCharacters(size_t columnIndex) const;
size_t getMaximumColumnWidthInCharacters(size_t columnIndex) const;
stringvec getColumnNames();

void setDataFile( const std::string & dataFilePath, long timestamp) { _dataFilePath = dataFilePath; _dataFileTimestamp = timestamp; dbUpdate(); }
Expand Down
1 change: 1 addition & 0 deletions CommonData/datasetbasenode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DATASETBASENODE_H

#include "enumutilities.h"
#include <functional>

DECLARE_ENUM(dataSetBaseNodeType, unknown, dataSet, data, filters, filter, column, label);

Expand Down
1 change: 1 addition & 0 deletions CommonData/filter.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <cassert>
#include "filter.h"
#include "timers.h"
#include "dataset.h"
Expand Down
1 change: 1 addition & 0 deletions CommonData/label.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "label.h"
#include "column.h"
#include <cassert>
#include "timers.h"
#include "databaseinterface.h"

Expand Down
Loading
Loading