@@ -19,10 +19,10 @@ void Column::setAutoSortByValuesByDefault(bool autoSort)
19
19
}
20
20
21
21
Column::Column (DataSet * data, int id)
22
- : DataSetBaseNode(dataSetBaseNodeType::column, data-> dataNode () ),
22
+ : DataSetBaseNode(dataSetBaseNodeType::column, data),
23
23
_data( data),
24
24
_id( id),
25
- _emptyValues( new EmptyValues(data->emptyValues ())),
25
+ _emptyValues( new EmptyValues(data->emptyValues ())),
26
26
_autoSortByValue( _autoSortByValuesByDefault)
27
27
{
28
28
if (_id != -1 )
@@ -188,6 +188,8 @@ void Column::setType(columnType colType)
188
188
_type = colType;
189
189
db ().columnSetType (_id, _type);
190
190
incRevision ();
191
+
192
+ _emitTypeChanged ();
191
193
}
192
194
193
195
bool Column::hasCustomEmptyValues () const
@@ -680,13 +682,21 @@ bool Column::overwriteDataAndType(stringvec colData, columnType colType)
680
682
681
683
for (size_t iFilter=0 , iData=0 ; iFilter < filtered.size () && iData < colData.size (); iFilter++)
682
684
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 ());
683
693
684
694
colData = newData;
685
695
}
686
696
687
697
688
698
// 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
690
700
691
701
bool changes = _type != colType,
692
702
toScale = colType == columnType::scale;
@@ -900,6 +910,12 @@ int Column::_labelMapIt(Label * label)
900
910
return label->intsId ();
901
911
}
902
912
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
+
903
919
int Column::labelsAdd (int value, const std::string & display, bool filterAllows, const std::string & description, const Json::Value & originalValue, int order, int id)
904
920
{
905
921
JASPTIMER_SCOPE (Column::labelsAdd lotsa arg);
@@ -909,10 +925,12 @@ int Column::labelsAdd(int value, const std::string & display, bool filterAllows,
909
925
if (_labelByValDis.count (valDisplay))
910
926
return _labelByValDis.at (valDisplay)->intsId ();
911
927
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);
914
929
_labels.push_back (label);
915
930
931
+ if (hasLabelFilter ())
932
+ _emitLabelFilterChanged ();
933
+
916
934
return _labelMapIt (label);
917
935
}
918
936
@@ -959,7 +977,7 @@ int Column::labelsSet(int labelIndex, int value, const std::string &display, boo
959
977
if (_labels.size () < labelIndex+1 )
960
978
_labels . resize (labelIndex+1 );
961
979
962
- _labels[labelIndex] = new Label ( this , display, value, filterAllows, description, originalValue, order, id);
980
+ _labels[labelIndex] = _createLabel ( display, value, filterAllows, description, originalValue, order, id);
963
981
label = _labels[labelIndex];
964
982
}
965
983
@@ -1025,7 +1043,7 @@ int Column::nonFilteredNumericsCount()
1025
1043
doubleset numerics;
1026
1044
1027
1045
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]))
1029
1047
numerics.insert (_dbls[r]);
1030
1048
1031
1049
if (!shouldDropLevels ())
@@ -1039,24 +1057,37 @@ int Column::nonFilteredNumericsCount()
1039
1057
return _nonFilteredNumericsCount;
1040
1058
}
1041
1059
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
+
1042
1070
stringvec Column::nonFilteredLevels ()
1043
1071
{
1044
1072
if (_nonFilteredLevels.empty ())
1045
1073
{
1046
1074
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])
1051
1080
if (_ints[r] != Label::NO_LABEL)
1052
1081
{
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
+ }
1056
1090
}
1057
- else if (!isEmptyValue (_dbls[r]))
1058
- levels.insert (ColumnUtils::doubleToString (_dbls[r]));
1059
- }
1060
1091
1061
1092
if (!shouldDropLevels ())
1062
1093
for (Label * label : _labels)
@@ -1071,6 +1102,16 @@ stringvec Column::nonFilteredLevels()
1071
1102
return _nonFilteredLevels;
1072
1103
}
1073
1104
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
+
1074
1115
void Column::nonFilteredCountersReset ()
1075
1116
{
1076
1117
_nonFilteredLevels.clear ();
@@ -1125,7 +1166,10 @@ std::string Column::getShadow(size_t row, bool fancyEmptyValue, bool sepas) cons
1125
1166
std::string Column::getValue (size_t row, bool fancyEmptyValue, bool ignoreEmptyValue, bool sepas, columnType asType) const
1126
1167
{
1127
1168
if (asType == columnType::unknown)
1169
+ {
1128
1170
asType = _type;
1171
+ _emitTypeChanged ();
1172
+ }
1129
1173
1130
1174
if (row < rowCount ())
1131
1175
{
@@ -1531,7 +1575,7 @@ bool Column::setValue(size_t row, std::string value, const std::string & label,
1531
1575
{
1532
1576
JASPTIMER_SCOPE (Column::setValue (stringstring));
1533
1577
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.
1535
1579
// if both are "" we just want to clear the cell
1536
1580
// the assumption is that this is not direct user-input, but internal jasp stuff.
1537
1581
if (value == " " && label == " " )
@@ -1858,7 +1902,7 @@ bool Column::allLabelsPassFilter() const
1858
1902
return true ;
1859
1903
}
1860
1904
1861
- bool Column::hasFilter () const
1905
+ bool Column::hasLabelFilter () const
1862
1906
{
1863
1907
return !allLabelsPassFilter ();
1864
1908
}
@@ -2077,6 +2121,7 @@ void Column::deserializeLabelsForRevert(const Json::Value & labels)
2077
2121
{
2078
2122
nonFilteredCountersReset ();
2079
2123
2124
+ _beginResetModel ();
2080
2125
beginBatchedLabelsDB ();
2081
2126
2082
2127
// intset updatedLbls;
@@ -2121,20 +2166,6 @@ void Column::deserializeLabelsForRevert(const Json::Value & labels)
2121
2166
2122
2167
endBatchedLabelsDB ();
2123
2168
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
-
2138
2169
incRevision ();
2139
2170
}
2140
2171
@@ -2146,33 +2177,25 @@ void Column::deserialize(const Json::Value &json)
2146
2177
std::string name = json[" name" ].asString (),
2147
2178
title = json[" title" ].asString ();
2148
2179
2149
- _name = getUniqueName (name);
2150
- db ().columnSetName (_id, _name);
2180
+ setName (getUniqueName (name));
2151
2181
2152
2182
// 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 () );
2161
2193
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
-
2172
2194
deserializeLabelsForCopy (json[" labels" ]);
2173
2195
2174
2196
_emptyValues->fromJson (json[" customEmptyValues" ]);
2175
-
2197
+
2198
+ _beginResetModel ();
2176
2199
size_t i=0 ;
2177
2200
_dbls.resize (json[" dbls" ].size ());
2178
2201
for (const Json::Value& dblJson : json[" dbls" ])
@@ -2182,6 +2205,7 @@ void Column::deserialize(const Json::Value &json)
2182
2205
_ints.resize (json[" ints" ].size ());
2183
2206
for (const Json::Value& intJson : json[" ints" ])
2184
2207
_ints[i++] = intJson.asInt ();
2208
+ _endResetModel ();
2185
2209
2186
2210
assert (_ints.size () == _dbls.size ());
2187
2211
0 commit comments