Skip to content

Commit 7e4c04a

Browse files
committed
make computed columns behave with filters
1 parent 18adbdc commit 7e4c04a

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

CommonData/column.cpp

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ columnType Column::setValues(size_t rows, const std::function<std::string(size_t
568568
{
569569
const std::string value = valueLookup(i),
570570
label = labelLookup(i);
571-
571+
572572
if(setValue(i, value, label, false, useLocale) && aChange)
573573
(*aChange) = true;
574574

@@ -634,28 +634,17 @@ bool Column::overwriteDataAndType(stringvec colData, columnType colType)
634634
{
635635
JASPTIMER_SCOPE(Column::overwriteDataAndType);
636636

637-
if(computeFilter() != "")
638-
{
639-
Filter theFilter(data(), computeFilter(), false);
640-
641-
const boolvec & filtered = theFilter.filtered();
642-
stringvec newData;
643-
newData . reserve(filtered.size());
644-
645-
for(size_t iFilter=0, iData=0; iFilter < filtered.size() && iData < colData.size(); iFilter++)
646-
newData.push_back(filtered[iFilter] ? colData[iData++] : "");
647-
648-
colData = newData;
649-
}
650-
else if(colData.size() == data()->shownFilter()->filteredRowCount())
651-
{
652-
const boolvec & filtered = data()->shownFilter()->filtered();
653-
stringvec newData;
654-
newData . reserve(filtered.size());
655-
656-
657-
colData = newData;
658-
}
637+
assert(data()->shownFilter()->name() == computeFilter());
638+
639+
const boolvec & filtered = data()->shownFilter()->filtered();
640+
stringvec newData;
641+
newData . reserve(filtered.size());
642+
643+
for(size_t iFilter=0, iData=0; iFilter < filtered.size() && iData < colData.size(); iFilter++)
644+
newData.push_back(filtered[iFilter] ? colData[iData++] : "");
645+
646+
colData = newData;
647+
659648

660649
//Now to make sure that the colData is neither bigger nor smaller than the dataset:
661650
colData.resize(data()->rowCount()); //Either add blanks rows add end or drop superfluous data
@@ -1326,7 +1315,7 @@ doublevec Column::dataAsRDoubles(const boolvec &filter) const
13261315
if(!useFilter || filter[row])
13271316
{
13281317
Label * l = labelByRow(row);
1329-
doubles.push_back(!l->isEmptyValue() ? l->originalValueAsDouble() : EmptyValues::missingValueDouble);
1318+
doubles.push_back(l && !l->isEmptyValue() ? l->originalValueAsDouble() : EmptyValues::missingValueDouble);
13301319
}
13311320

13321321
return doubles;
@@ -1525,7 +1514,7 @@ bool Column::setStringValue(size_t row, const std::string & userEntered, const s
15251514

15261515
if(label && label->isEmptyValue()) return false;
15271516
if (cur == "") return false;
1528-
else return setValue(row, EmptyValues::missingValueDouble, writeToDB);
1517+
else return setValue(row, EmptyValues::missingValueInteger, writeToDB);
15291518
}
15301519

15311520
double newDoubleToSet = EmptyValues::missingValueDouble;
@@ -1556,7 +1545,7 @@ bool Column::setValue(size_t row, std::string value, const std::string & label,
15561545
//if both are "" we just want to clear the cell
15571546
//the assumption is that this is not direct user-input, but internal jasp stuff.
15581547
if(value == "" && label == "")
1559-
return setValue(row, EmptyValues::missingValueDouble, writeToDB);
1548+
return setValue(row, EmptyValues::missingValueInteger, writeToDB);
15601549

15611550
double newDoubleToSet = EmptyValues::missingValueDouble;
15621551
bool itsADouble = ColumnUtils::getDoubleValue(value, newDoubleToSet, useLocale);
@@ -1569,7 +1558,6 @@ bool Column::setValue(size_t row, std::string value, const std::string & label,
15691558

15701559
Label * newLabel = justAValue ? labelByValue(value) : labelByValueAndDisplay(value, label);
15711560

1572-
15731561
if(!newLabel)
15741562
newLabel = labelByIntsId(labelsAdd((justAValue || labelIsValue) ? value : label, "", itsADouble ? Json::Value(newDoubleToSet) : value));
15751563

@@ -2359,7 +2347,7 @@ stringvec Column::previewTransform(columnType transformType)
23592347

23602348
bool Column::initFromLookups(const std::string & newName, size_t rows, const std::function<std::string(size_t)> valueLookup, const std::function<std::string(size_t)> labelLookup, const std::string & title, columnType desiredType, const stringset & emptyValues, int threshold, bool orderLabelsByValue, bool leaveBatchedUnfinished)
23612349

2362-
{
2350+
{
23632351
setHasCustomEmptyValues(emptyValues.size());
23642352
setCustomEmptyValues(emptyValues);
23652353
setName(newName);

CommonData/dataset.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ void DataSet::registerFilter(Filter *f)
105105
emit filtersCountChanged();
106106
}
107107

108-
109108
void DataSet::dbDelete()
110109
{
111110
JASPTIMER_SCOPE(DataSet::dbDelete);

CommonData/filter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Filter::Filter(DataSet * data)
1616
_constructorJson( DEFAULT_FILTER_JSON),
1717
_generatedFilter( DEFAULT_FILTER_GEN)
1818
{
19+
assert(_data);
1920
connectionCreation();
2021

2122
_rFilter = fq(defaultRFilter());
@@ -26,6 +27,7 @@ Filter::Filter(DataSet * data, const std::string & name, bool createIfMissing)
2627
: DataSetBaseNode(dataSetBaseNodeType::filter), _data(data), _name(name)
2728
{
2829
assert(_name != "");
30+
assert(_data);
2931

3032
_rFilter = fq(defaultRFilter()); //Might get overwritten, that is fine
3133

@@ -46,7 +48,7 @@ void Filter::connectionCreation()
4648

4749
_data->registerFilter(this);
4850

49-
if(_data->defaultFilter() != this)
51+
if(_data->defaultFilter() != this && _data->defaultFilter()) //If it doesnt exist yet this is probably it
5052
connect(_data->defaultFilter(), &Filter::generatedFilterChanged, this, &Filter::generatedFilterChanged);
5153
}
5254

0 commit comments

Comments
 (0)