Skip to content

Commit ad91a7c

Browse files
committed
DataSetQ Etc
make classes make it shorter start moving functionality to their proper place flesh out DataSetQ maak factory functies en ruim datasetpackage alvast beetje op Move label set stuff to ColumnQ from DataSetPackage and some related changes Fairly sure the whol beginLoadingData etc in DataSetPackage isnt really necessary anymore move more stuff to Filter add invalidation to Filter move LabelFilterGenerator to another spot also tightly integrate it with FilterQ etc fix some problems move more stuff from FilterModel to FilterQ cleanin more changes use set functions for deserializen etc stapjes
1 parent 5018791 commit ad91a7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2388
-1988
lines changed

CommonData/column.cpp

Lines changed: 78 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ void Column::setAutoSortByValuesByDefault(bool autoSort)
1919
}
2020

2121
Column::Column(DataSet * data, int id)
22-
: DataSetBaseNode(dataSetBaseNodeType::column, data->dataNode()),
22+
: DataSetBaseNode(dataSetBaseNodeType::column, data),
2323
_data( data),
2424
_id( id),
25-
_emptyValues( new EmptyValues(data->emptyValues())),
25+
_emptyValues( new EmptyValues(data->emptyValues())),
2626
_autoSortByValue( _autoSortByValuesByDefault)
2727
{
2828
if(_id != -1)
@@ -188,6 +188,8 @@ void Column::setType(columnType colType)
188188
_type = colType;
189189
db().columnSetType(_id, _type);
190190
incRevision();
191+
192+
_emitTypeChanged();
191193
}
192194

193195
bool Column::hasCustomEmptyValues() const
@@ -680,13 +682,21 @@ bool Column::overwriteDataAndType(stringvec colData, columnType colType)
680682

681683
for(size_t iFilter=0, iData=0; iFilter < filtered.size() && iData < colData.size(); iFilter++)
682684
newData.push_back(filtered[iFilter] ? colData[iData++] : "");
685+
}
686+
else
687+
{
688+
if(colData.size() == data()->shownFilter()->filteredRowCount())
689+
{
690+
const boolvec & filtered = data()->shownFilter()->filtered();
691+
stringvec newData;
692+
newData . reserve(filtered.size());
683693

684694
colData = newData;
685695
}
686696

687697

688698
//Now to make sure that the colData is neither bigger nor smaller than the dataset:
689-
colData.resize(_data->rowCount()); //Either add blanks rows add end or drop superfluous data
699+
colData.resize(data()->rowCount()); //Either add blanks rows add end or drop superfluous data
690700

691701
bool changes = _type != colType,
692702
toScale = colType == columnType::scale;
@@ -900,6 +910,12 @@ int Column::_labelMapIt(Label * label)
900910
return label->intsId();
901911
}
902912

913+
Label * Column::_createLabel(const std::string &label, int value, bool filterAllows, const std::string &description, const Json::Value &originalValue, int order, int id)
914+
{
915+
return new Label(this, label, value, filterAllows, description, originalValue, order, id);
916+
}
917+
918+
903919
int Column::labelsAdd(int value, const std::string & display, bool filterAllows, const std::string & description, const Json::Value & originalValue, int order, int id)
904920
{
905921
JASPTIMER_SCOPE(Column::labelsAdd lotsa arg);
@@ -909,10 +925,12 @@ int Column::labelsAdd(int value, const std::string & display, bool filterAllows,
909925
if(_labelByValDis.count(valDisplay))
910926
return _labelByValDis.at(valDisplay)->intsId();
911927

912-
913-
Label * label = new Label(this, display, value, filterAllows, description, originalValue, order, id);
928+
Label * label = _createLabel(display, value, filterAllows, description, originalValue, order, id);
914929
_labels.push_back(label);
915930

931+
if(hasLabelFilter())
932+
_emitLabelFilterChanged();
933+
916934
return _labelMapIt(label);
917935
}
918936

@@ -959,7 +977,7 @@ int Column::labelsSet(int labelIndex, int value, const std::string &display, boo
959977
if(_labels.size() < labelIndex+1)
960978
_labels . resize(labelIndex+1);
961979

962-
_labels[labelIndex] = new Label(this, display, value, filterAllows, description, originalValue, order, id);
980+
_labels[labelIndex] = _createLabel(display, value, filterAllows, description, originalValue, order, id);
963981
label = _labels[labelIndex];
964982
}
965983

@@ -1025,7 +1043,7 @@ int Column::nonFilteredNumericsCount()
10251043
doubleset numerics;
10261044

10271045
for(size_t r=0; r<_data->rowCount(); r++)
1028-
if(_data->filter()->filtered()[r] && !isEmptyValue(_dbls[r]))
1046+
if(_data->shownFilter()->filtered()[r] && !isEmptyValue(_dbls[r]))
10291047
numerics.insert(_dbls[r]);
10301048

10311049
if(!shouldDropLevels())
@@ -1039,24 +1057,37 @@ int Column::nonFilteredNumericsCount()
10391057
return _nonFilteredNumericsCount;
10401058
}
10411059

1060+
int Column::nonFilteredNumericsCount() const
1061+
{
1062+
#ifdef JASP_DEBUG
1063+
if(_nonFilteredNumericsCount == -1)
1064+
throw std::runtime_error("nonFilteredNumericsCount() const was not initialized");
1065+
#endif
1066+
1067+
return _nonFilteredNumericsCount;
1068+
}
1069+
10421070
stringvec Column::nonFilteredLevels()
10431071
{
10441072
if (_nonFilteredLevels.empty())
10451073
{
10461074
JASPTIMER_SCOPE(Column::nonFilteredLevels);
1047-
stringset levels;
1048-
for(size_t r=0; r<_data->rowCount(); r++)
1049-
if(_data->filter()->filtered()[r])
1050-
{
1075+
stringset levels;
1076+
intset collected;
1077+
1078+
for(size_t r=0; r<data()->rowCount(); r++)
1079+
if(data()->shownFilter()->filtered()[r])
10511080
if(_ints[r] != Label::NO_LABEL)
10521081
{
1053-
Label * label = labelByIntsId(_ints[r]);
1054-
if(label && !label->isEmptyValue())
1055-
levels.insert(label->label());
1082+
if(!collected.count(_ints[r]))
1083+
{
1084+
Label * label = labelByIntsId(_ints[r]);
1085+
if(label && !label->isEmptyValue())
1086+
levels.insert(label->label());
1087+
1088+
collected.insert(_ints[r]);
1089+
}
10561090
}
1057-
else if(!isEmptyValue(_dbls[r]))
1058-
levels.insert(ColumnUtils::doubleToString(_dbls[r]));
1059-
}
10601091

10611092
if(!shouldDropLevels())
10621093
for(Label * label : _labels)
@@ -1071,6 +1102,16 @@ stringvec Column::nonFilteredLevels()
10711102
return _nonFilteredLevels;
10721103
}
10731104

1105+
stringvec Column::nonFilteredLevels() const
1106+
{
1107+
#ifdef JASP_DEBUG
1108+
if(_nonFilteredLevels.empty())
1109+
throw std::runtime_error("nonFilteredLevels() const was not initialized");
1110+
#endif
1111+
1112+
return _nonFilteredLevels;
1113+
}
1114+
10741115
void Column::nonFilteredCountersReset()
10751116
{
10761117
_nonFilteredLevels.clear();
@@ -1125,7 +1166,10 @@ std::string Column::getShadow(size_t row, bool fancyEmptyValue, bool sepas) cons
11251166
std::string Column::getValue(size_t row, bool fancyEmptyValue, bool ignoreEmptyValue, bool sepas, columnType asType) const
11261167
{
11271168
if(asType == columnType::unknown)
1169+
{
11281170
asType = _type;
1171+
_emitTypeChanged();
1172+
}
11291173

11301174
if (row < rowCount())
11311175
{
@@ -1531,7 +1575,7 @@ bool Column::setValue(size_t row, std::string value, const std::string & label,
15311575
{
15321576
JASPTIMER_SCOPE(Column::setValue(stringstring));
15331577

1534-
//If value != "" and label == "" that means we got copy pasted stuff in the viewer. And we just dont have labels, but we can treat it like we are editing
1578+
//If value != "" and label == "" that means we got copy pasted stuff in the viewer, and we just dont have labels, but we can treat it like we are editing.
15351579
//if both are "" we just want to clear the cell
15361580
//the assumption is that this is not direct user-input, but internal jasp stuff.
15371581
if(value == "" && label == "")
@@ -1858,7 +1902,7 @@ bool Column::allLabelsPassFilter() const
18581902
return true;
18591903
}
18601904

1861-
bool Column::hasFilter() const
1905+
bool Column::hasLabelFilter() const
18621906
{
18631907
return !allLabelsPassFilter();
18641908
}
@@ -2077,6 +2121,7 @@ void Column::deserializeLabelsForRevert(const Json::Value & labels)
20772121
{
20782122
nonFilteredCountersReset();
20792123

2124+
_beginResetModel();
20802125
beginBatchedLabelsDB();
20812126

20822127
//intset updatedLbls;
@@ -2121,20 +2166,6 @@ void Column::deserializeLabelsForRevert(const Json::Value & labels)
21212166

21222167
endBatchedLabelsDB();
21232168

2124-
/* The following is already implied by endBatchedLabelsDB because it deletes all labels first anyway (There are some issues when an operation changed _labels though, in that case it might be better to deserialize the column!)
2125-
for(int id : missingLbls)
2126-
{
2127-
Label * deleteMe = _labelByIntsIdMap[id];
2128-
2129-
for(size_t i=0;i<_labels.size(); i++)
2130-
if(_labels[i] == deleteMe)
2131-
_labels.erase(_labels.begin() + i);
2132-
2133-
_labelByIntsIdMap.erase(id);
2134-
deleteMe->dbDelete();
2135-
delete deleteMe;
2136-
}*/
2137-
21382169
incRevision();
21392170
}
21402171

@@ -2146,33 +2177,25 @@ void Column::deserialize(const Json::Value &json)
21462177
std::string name = json["name"].asString(),
21472178
title = json["title"].asString();
21482179

2149-
_name = getUniqueName(name);
2150-
db().columnSetName(_id, _name);
2180+
setName(getUniqueName(name));
21512181

21522182
// If title was equal to name, then they should still stay the same if the name is changed to be unique.
2153-
_title = name == title ? _name : title;
2154-
db().columnSetTitle(_id, _title);
2155-
2156-
_description = json["description"].asString();
2157-
db().columnSetDescription(_id, _description);
2158-
2159-
_type = columnType(json["type"].asInt());
2160-
db().columnSetType(_id, _type);
2183+
setTitle( name == title ? _name : title);
2184+
setDescription( json["description"] .asString() );
2185+
setType( columnType( json["type"] .asInt()) );
2186+
setInvalidated( json["invalidated"] .asBool() );
2187+
setCodeType( computedColumnType( json["codeType"] .asInt()) );
2188+
setRCode( json["rCode"] .asString() );
2189+
setError( json["error"] .asString() );
2190+
setAnalysisId( json["analysisId"] .asInt() );
2191+
setConstructorJson( json["constructorJson"] );
2192+
setAutoSortByValue( json["autoSortByValue"] .asBool() );
21612193

2162-
_invalidated = json["invalidated"].asBool();
2163-
_codeType = computedColumnType(json["codeType"].asInt());
2164-
_rCode = json["rCode"].asString();
2165-
_error = json["error"].asString();
2166-
_analysisId = json["analysisId"].asInt();
2167-
_constructorJson = json["constructorJson"];
2168-
_autoSortByValue = json["autoSortByValue"].asBool();
2169-
2170-
db().columnSetComputedInfo(_id, _analysisId, _invalidated, _codeType, _rCode, _error, constructorJsonStr(), _computeFilter);
2171-
21722194
deserializeLabelsForCopy(json["labels"]);
21732195

21742196
_emptyValues->fromJson(json["customEmptyValues"]);
2175-
2197+
2198+
_beginResetModel();
21762199
size_t i=0;
21772200
_dbls.resize(json["dbls"].size());
21782201
for (const Json::Value& dblJson : json["dbls"])
@@ -2182,6 +2205,7 @@ void Column::deserialize(const Json::Value &json)
21822205
_ints.resize(json["ints"].size());
21832206
for (const Json::Value& intJson : json["ints"])
21842207
_ints[i++] = intJson.asInt();
2208+
_endResetModel();
21852209

21862210
assert(_ints.size() == _dbls.size());
21872211

CommonData/column.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ class Column : public DataSetBaseNode
4444
public:
4545
typedef std::map<std::pair<std::string, std::string>, Label*> LabelByStrStr;
4646
typedef std::map<std::string, Labelset> LabelsByStr;
47+
friend DataSet;
4748

48-
Column(DataSet * data, int id = -1);
49-
~Column();
49+
protected:
50+
Column(DataSet * data, int id = -1); ///< Dont use directly! Use DataSet::_createColumn
51+
52+
public:
53+
~Column();
5054

5155
DatabaseInterface & db();
5256
const DatabaseInterface & db() const;
@@ -85,7 +89,7 @@ class Column : public DataSetBaseNode
8589
bool overwriteDataAndType( stringvec data, columnType colType);
8690

8791
bool allLabelsPassFilter() const;
88-
bool hasFilter() const;
92+
bool hasLabelFilter() const;
8993
void resetFilter();
9094
void incRevision() override;
9195
bool checkForUpdates();
@@ -130,7 +134,9 @@ class Column : public DataSetBaseNode
130134
void labelsShrinkOnlyToSize( size_t highestToKeep);
131135

132136
int nonFilteredNumericsCount();
137+
int nonFilteredNumericsCount() const;
133138
stringvec nonFilteredLevels();
139+
stringvec nonFilteredLevels() const;
134140
void nonFilteredCountersReset();
135141

136142
std::set<size_t> labelsMoveRows(std::vector<size_t> rows, bool up);
@@ -247,6 +253,24 @@ class Column : public DataSetBaseNode
247253
std::map<Label*,size_t> valuesAlphabeticalOffsets();
248254
int _labelMapIt(Label *label);
249255
void _labelMapUpdates(Label *label, const std::string & previousDisplay, const std::string & previousOriginal);
256+
257+
virtual Label * _createLabel(
258+
const std::string & label,
259+
int value,
260+
bool filterAllows = true,
261+
const std::string & description = "",
262+
const Json::Value & originalValue = Json::nullValue,
263+
int order = -1,
264+
int id = -1);
265+
266+
267+
protected:
268+
std::function<void()> _emitLabelFilterChanged;
269+
std::function<void()> _emitTypeChanged;
270+
std::function<void()> _beginResetModel;
271+
std::function<void()> _endResetModel;
272+
273+
250274
private:
251275
DataSet * const _data;
252276
EmptyValues * const _emptyValues;

0 commit comments

Comments
 (0)