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 #5776

Closed
wants to merge 14 commits into from
Closed
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Use CommanData in QML Components
boutinb committed Jan 14, 2025
commit f7c488d128bfa0b38382ed8119e36ea3d0a63dd8
11 changes: 0 additions & 11 deletions CommonData/filter.cpp
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
#include "dataset.h"
#include "databaseinterface.h"

std::map<std::string, Filter*> _filterMap;

Filter::Filter(DataSet * data)
: DataSetBaseNode(dataSetBaseNodeType::filter, data), _data(data)
{ }
@@ -17,8 +15,6 @@ Filter::Filter(DataSet * data, const std::string & name, bool createIfMissing)
if(db().filterGetId(_name) > -1) dbLoad();
else if(createIfMissing) dbCreate();
else throw std::runtime_error("Filter by name '" + _name + "' but it doesnt exist and createIfMissing=false!\nAre you sure this filter should exist?");

_filterMap[name] = this;
}

void Filter::dbCreate()
@@ -140,8 +136,6 @@ void Filter::dbDelete()

db().filterDelete(_id);
_id = -1;

_filterMap.erase(_name);
}

void Filter::incRevision()
@@ -181,11 +175,6 @@ bool Filter::filterNameIsFree(const std::string &filterName)
return -1 == DatabaseInterface::singleton()->filterGetId(filterName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is also where it was...

}

Filter* Filter::getFilterFromName(const std::string & filterName)
{
return _filterMap[filterName];
}

void Filter::reset()
{
if(!_data->writeBatchedToDB())
21 changes: 10 additions & 11 deletions CommonData/filter.h
Original file line number Diff line number Diff line change
@@ -24,16 +24,16 @@ class Filter : public DataSetBaseNode
Filter(DataSet * data);
Filter(DataSet * data, const std::string & name, bool createIfMissing = true);

DataSet * data() const { return _data; }
int id() const { return _id; }
const std::string & name() const { return _name; }
const std::string & rFilter() const { return _rFilter; }
const std::string & generatedFilter() const { return _generatedFilter; }
const std::string & constructorJson() const { return _constructorJson; }
const std::string & constructorR() const { return _constructorR; }
const std::string & errorMsg() const { return _errorMsg; }
const std::vector<bool> & filtered() const { return _filtered; }
int filteredRowCount() const { return _filteredRowCount; }
DataSet * data() const { return _data; }
int id() const { return _id; }
const std::string & name() const { return _name; }
const std::string & rFilter() const { return _rFilter; }
const std::string & generatedFilter() const { return _generatedFilter; }
const std::string & constructorJson() const { return _constructorJson; }
const std::string & constructorR() const { return _constructorR; }
const std::string & errorMsg() const { return _errorMsg; }
const std::vector<bool> & filtered() const { return _filtered; }
int filteredRowCount() const { return _filteredRowCount; }

void setRFilter( const std::string & rFilter) { _rFilter = rFilter; dbUpdate(); }
void setGeneratedFilter( const std::string & generatedFilter) { _generatedFilter = generatedFilter; dbUpdate(); }
@@ -56,7 +56,6 @@ class Filter : public DataSetBaseNode
bool checkForUpdates();

static bool filterNameIsFree(const std::string & filterName);
static Filter* getFilterFromName(const std::string & filterName);

void reset();

32 changes: 0 additions & 32 deletions Desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -77,7 +77,6 @@ MainWindow * MainWindow::_singleton = nullptr;
MainWindow::MainWindow(QApplication * application) : QObject(application), _application(application)
{
std::cout << "MainWindow constructor started" << std::endl;

connect(this, &MainWindow::exitSignal, this, &QApplication::exit, Qt::QueuedConnection);

assert(!_singleton);
@@ -491,37 +490,6 @@ void MainWindow::makeConnections()
Column::setAutoSortByValuesByDefault(PreferencesModel::prefs()->orderByValueByDefault());

auto * dCSingleton = DesktopCommunicator::singleton();
// For Audit analyses, the Filter object is needed. As the QML objects should not have direct access to the data objects, the needed functions are set as callbacks.
dCSingleton->setFilterFunctions(
[](const std::string& name) {
new Filter(DataSetPackage::pkg()->dataSet(), name, true);
},
[](const std::string& name) {
Filter* filter = Filter::getFilterFromName(name);
if (filter)
filter->dbDelete();
},
[](const std::string& name, const std::string& rFilter) {
Filter* filter = Filter::getFilterFromName(name);
if (filter)
filter->setRFilter(rFilter);
},
[](const std::string& name) {
Filter* filter = Filter::getFilterFromName(name);
return filter ? filter->checkForUpdates() : false;
},
[](const std::string& name) {
Filter* filter = Filter::getFilterFromName(name);
return filter ? filter->filtered() : std::vector<bool>();
},
[](const std::string& name) {
Filter* filter = Filter::getFilterFromName(name);
return filter ? filter->filteredRowCount() : 0;
},
[](const std::string& name) {
return Filter::filterNameIsFree(name);
}
);

//Needed to allow for a hard split between Desktop/QMLComps:
connect(_preferences, &PreferencesModel::uiScaleChanged, dCSingleton, &DesktopCommunicator::uiScaleChanged );
5 changes: 3 additions & 2 deletions QMLComponents/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -8,10 +8,9 @@ file(GLOB_RECURSE QML_FILES RELATIVE "${CMAKE_CURRENT_LIST_DIR}" "components/JAS

qt_add_qml_module(QMLComponents
URI JASP.Controls
#STATIC
OUTPUT_DIRECTORY "JASP/Controls"
RESOURCE_PREFIX /jasp-stats.org/imports
#PLUGIN_TARGET QMLComponents
#PLUGIN_TARGET QMLComponentsPlugin
DEPENDENCIES QtQuick
#NO_PLUGIN_OPTIONAL
NO_GENERATE_PLUGIN_SOURCE
@@ -39,6 +38,7 @@ target_include_directories(
QMLComponents
PUBLIC # JASP
${PROJECT_SOURCE_DIR}/Common
${PROJECT_SOURCE_DIR}/CommonData
${PROJECT_SOURCE_DIR}/Common/jaspColumnEncoder
${CMAKE_CURRENT_LIST_DIR}/controls
${CMAKE_CURRENT_LIST_DIR}/rsyntax
@@ -50,6 +50,7 @@ target_link_libraries(
QMLComponents
PUBLIC
Common
CommonData
Qt::Core
Qt::Gui
Qt::Widgets
82 changes: 28 additions & 54 deletions QMLComponents/models/listmodelfiltereddataentry.cpp
Original file line number Diff line number Diff line change
@@ -3,8 +3,7 @@
#include "utilities/qutils.h"
#include "log.h"
#include "controls/jaspcontrol.h"
#include "utilities/desktopcommunicator.h"

#include "filter.h"

ListModelFilteredDataEntry::ListModelFilteredDataEntry(TableViewBase * parent)
: ListModelTableViewBase(parent)
@@ -16,19 +15,23 @@ ListModelFilteredDataEntry::ListModelFilteredDataEntry(TableViewBase * parent)
connect(_tableView, SIGNAL(colNameSignal(QString)), this, SLOT(setColName(QString)) );
connect(_tableView, SIGNAL(extraColSignal(QString)), this, SLOT(setExtraCol(QString)) );

DataSet* dataSet = VariableInfo::info()->dataSet();
static int counter = 0;
do
{
_filterName = "ListModelFilteredDataEntry_" + std::to_string(counter++);
}
while(!filterNameIsFree(_filterName));
while(!Filter::filterNameIsFree(_filterName));

connect(VariableInfo::info(), &VariableInfo::dataSetChanged, this, &ListModelFilteredDataEntry::dataSetChangedHandler);
}

ListModelFilteredDataEntry::~ListModelFilteredDataEntry()
{
filterDelete();
if(_filter)
_filter->dbDelete();
delete _filter;
_filter = nullptr;
}

void ListModelFilteredDataEntry::dataSetChangedHandler()
@@ -49,14 +52,18 @@ void ListModelFilteredDataEntry::setFilter(QString filter)
_tableTerms.filter = filter;
emit filterChanged(_tableTerms.filter);

filterSetRScript("filterResult <- {" + filter.toStdString() + "};" "\n"
if(_filter)
_filter->setRFilter("filterResult <- {" + filter.toStdString() + "};" "\n"
"if(!is.logical(filterResult)) filterResult <- rep(TRUE, rowcount);" "\n"
" return(filterResult);" "\n");
}

void ListModelFilteredDataEntry::runFilter()
{
runFilterByName(tq(_filterName));
if(!_filter) //prob still need to bind
return;

runFilterByName(tq(_filter->name()));
}

void ListModelFilteredDataEntry::filterDoneHandler(const QString &name, const QString & error)
@@ -66,16 +73,16 @@ void ListModelFilteredDataEntry::filterDoneHandler(const QString &name, const QS

Log::log() << "ListModelFilteredDataEntry::filterDoneHandler for " << name << " and error '" << error << "'" << std::endl;

filterCheckForUpdate();
_filter->checkForUpdates();

setAcceptedRows(filtered());
setAcceptedRows(_filter->filtered());

if(!error.isEmpty())
_tableView->addControlWarning(tr("Filter had error '%1'").arg(error));
else
_tableView->clearControlError();

if(filteredRowCount() == 0)
if(_filter->filteredRowCount() == 0)
runFilter();
else
informDataSetOfInitialValues();
@@ -167,12 +174,16 @@ void ListModelFilteredDataEntry::initTableTerms(const TableTerms& terms)
Log::log() << "Too many values in ListModelFilteredDataEntry" << std::endl;

if(terms.filterName.isEmpty())
{
//We dont apparently have a previous filterName, so this is a fresh one, we need a new filter!
assert(!_filterName.empty());
else if(_filterName.empty())
assert(!_filter && !_filterName.empty());
_filter = new Filter(VariableInfo::info()->dataSet(), _filterName, true);
}
else if(!_filter)
{
_filterName = fq(terms.filterName);

filterBuild();
_filter = new Filter(VariableInfo::info()->dataSet(), _filterName, true);
}

if (terms.colName.isEmpty())
{
@@ -187,7 +198,7 @@ void ListModelFilteredDataEntry::initTableTerms(const TableTerms& terms)
setColName( _tableTerms.colName );
setExtraCol(_tableTerms.extraCol);

_acceptedRows = filtered();
_acceptedRows = _filter->filtered();

_dataColumns = _tableTerms.colNames;

@@ -212,9 +223,10 @@ void ListModelFilteredDataEntry::fillTable()
_tableTerms.rowNames.clear();
_tableTerms.values.clear();

filterCheckForUpdate();
if (_filter)
_filter->checkForUpdates();

size_t dataRows = filtered().size() > 0 ? filtered().size() : getDataSetRowCount();
size_t dataRows = _filter && _filter->filtered().size() > 0 ? _filter->filtered().size() : getDataSetRowCount();

if (_acceptedRows.size() != dataRows)
_acceptedRows = std::vector<bool>(dataRows, true);
@@ -427,41 +439,3 @@ void ListModelFilteredDataEntry::refreshModel()
ListModel::refresh();
}

bool ListModelFilteredDataEntry::filterNameIsFree(const std::string& name)
{
return DesktopCommunicator::singleton()->filterNameIsFree(name);
}

void ListModelFilteredDataEntry::filterBuild()
{
if (!_filterName.empty())
DesktopCommunicator::singleton()->filterBuild(_filterName);
}

void ListModelFilteredDataEntry::filterDelete()
{
if (!_filterName.empty())
DesktopCommunicator::singleton()->filterDelete(_filterName);
}

void ListModelFilteredDataEntry::filterSetRScript(const std::string& script)
{
if (!_filterName.empty())
DesktopCommunicator::singleton()->filterSetRScript(_filterName, script);
}

bool ListModelFilteredDataEntry::filterCheckForUpdate()
{
return !_filterName.empty() ? DesktopCommunicator::singleton()->filterCheckForUpdate(_filterName) : false;
}

std::vector<bool> ListModelFilteredDataEntry::filtered()
{
return !_filterName.empty() ? DesktopCommunicator::singleton()->filtered(_filterName) : std::vector<bool>();
}

int ListModelFilteredDataEntry::filteredRowCount()
{
return !_filterName.empty() ? DesktopCommunicator::singleton()->filteredRowCount(_filterName) : 0;
}

12 changes: 2 additions & 10 deletions QMLComponents/models/listmodelfiltereddataentry.h
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@

#include "listmodeltableviewbase.h"

class Filter;
class ListModelFilteredDataEntry : public ListModelTableViewBase
{
Q_OBJECT
@@ -74,16 +75,6 @@ private slots:
size_t getDataSetRowCount() const;
void fillTable();

bool filterNameIsFree(const std::string& name);
void filterBuild();
void filterDelete();
void filterSetRScript(const std::string& script);
bool filterCheckForUpdate();
std::vector<bool> filtered();
int filteredRowCount();




private:
boolvec _acceptedRows;
@@ -94,6 +85,7 @@ private slots:
QStringList _dataColumns,
_extraColsStr;
std::string _filterName;
Filter * _filter = nullptr;
bool _informOnce = false;
};

Loading