From 3eaa51abffd241ce32accd97db94d41019b00001 Mon Sep 17 00:00:00 2001 From: boutinb Date: Thu, 12 Sep 2024 17:01:41 +0200 Subject: [PATCH] Auto Sort labels does bug and other label handling issues --- CommonData/column.cpp | 113 +++++++++++++----- CommonData/column.h | 14 ++- CommonData/databaseinterface.cpp | 15 ++- CommonData/databaseinterface.h | 2 +- CommonData/dataset.cpp | 17 +-- CommonData/dataset.h | 2 +- .../JASP/Widgets/LabelEditorWindow.qml | 32 ++--- Desktop/data/columnmodel.cpp | 25 ++-- Desktop/data/columnmodel.h | 6 +- Desktop/data/computedcolumnmodel.cpp | 2 +- Desktop/data/datasetpackage.cpp | 23 ++-- Desktop/data/datasetpackage.h | 2 +- Desktop/po/jaspDesktop-de.po | 4 +- Desktop/po/jaspDesktop-es.po | 4 +- Desktop/po/jaspDesktop-gl.po | 4 +- Desktop/po/jaspDesktop-nl.po | 4 +- Desktop/qquick/datasetview.cpp | 8 ++ Desktop/qquick/datasetview.h | 1 + 18 files changed, 167 insertions(+), 111 deletions(-) diff --git a/CommonData/column.cpp b/CommonData/column.cpp index 74c4b48a71..734fefccab 100644 --- a/CommonData/column.cpp +++ b/CommonData/column.cpp @@ -17,28 +17,43 @@ void Column::setAutoSortByValuesByDefault(bool autoSort) _autoSortByValuesByDefault = autoSort; } -Column::Column(DataSet * data, int id) +Column::Column(DataSet * data, int id, columnType colType, computedColumnType computedType, bool autoSort) : DataSetBaseNode(dataSetBaseNodeType::column, data->dataNode()), _data( data), _id( id), _emptyValues( new EmptyValues(data->emptyValues())), _doubleDummy( new Label(this)), - _autoSortByValue( _autoSortByValuesByDefault) + _type( colType), + _codeType( computedType), + _autoSortByValue( autoSort) {} -Column::~Column() + +Column* Column::addColumn(DataSet * data, int index, const std::string& name, columnType colType, computedColumnType computedType, bool alterDataSetTable) { - labelsTempReset(); - delete _emptyValues; - delete _doubleDummy; + int id = data->db().columnInsert(data->id(), index, colType, computedType, Column::autoSortByValuesByDefault()); + Column* col = new Column(data, id, colType, computedType, Column::autoSortByValuesByDefault()); + + if (!name.empty()) + col->setName(name); + + return col; } -void Column::dbCreate(int index) +Column* Column::loadColumn(DataSet * data, int index) { - JASPTIMER_SCOPE(Column::dbCreate); + Column* col = new Column(data, index, columnType::unknown, computedColumnType::notComputed, Column::autoSortByValuesByDefault()); + col->dbLoadIndex(index, false); - assert(_id == -1); - db().columnInsert(_id, index); + return col; +} + + +Column::~Column() +{ + labelsTempReset(); + delete _emptyValues; + delete _doubleDummy; } void Column::dbLoad(int id, bool getValues) @@ -401,18 +416,17 @@ columnTypeChangeResult Column::changeType(columnType colType) if(codeType() == computedColumnType::analysis) return columnTypeChangeResult::generatedFromAnalysis; - setDefaultValues(colType); + if (colType != columnType::unknown) + setType(colType); + setDefaultValues(); invalidate(); return columnTypeChangeResult::changed; } } -void Column::setDefaultValues(enum columnType columnType) +void Column::setDefaultValues() { JASPTIMER_SCOPE(Column::setDefaultValues); - - if(columnType != columnType::unknown) - setType(columnType); for(size_t i=0; i<_ints.size(); i++) { @@ -1638,7 +1652,7 @@ void Column::labelsOrderByValue(bool doDbUpdateEtc) bool replaceAllDoubles = false; static double dummy; - for(Label * label : labels()) + for(Label * label : labels()) if(!label->isEmptyValue() && !(label->originalValue().isDouble() || ColumnUtils::getDoubleValue(label->originalValueAsString(), dummy))) { replaceAllDoubles = true; @@ -1648,24 +1662,43 @@ void Column::labelsOrderByValue(bool doDbUpdateEtc) if(replaceAllDoubles) replaceDoublesTillLabelsRowWithLabels(labelsTempCount()); - doublevec asc = valuesNumericOrdered(); - size_t curMax = asc.size()+1; - std::map orderMap; - - for(size_t i=0; ioriginalValue().isDouble()) - aValue = label->originalValue().asDouble(); - else - ColumnUtils::getDoubleValue(label->originalValueAsString(), aValue); - - label->setOrder(!std::isnan(aValue) ? orderMap[aValue] : curMax++); + stringvec orderedstrings = valuesAlphabeticOrdered(); + size_t curMax = orderedstrings.size()+1; + std::map orderMap; + + for(size_t i=0; ioriginalValueAsString(); + label->setOrder(!isEmptyValue(aValue) ? orderMap[aValue] : curMax++); + } + } + else + { + size_t curMax = asc.size()+1; + std::map orderMap; + + for(size_t i=0; ioriginalValue().isDouble()) + aValue = label->originalValue().asDouble(); + else + ColumnUtils::getDoubleValue(label->originalValueAsString(), aValue); + + label->setOrder(!std::isnan(aValue) ? orderMap[aValue] : curMax++); + } } _sortLabelsByOrder(); @@ -1694,6 +1727,20 @@ doublevec Column::valuesNumericOrdered() return doublevec(values.begin(), values.end()); } +stringvec Column::valuesAlphabeticOrdered() +{ + stringset values; + + for(const Label * label : _labels) + { + std::string aValue = label->originalValueAsString(); + if (!isEmptyValue(aValue)) + values.insert(aValue); + } + + return stringvec(values.begin(), values.end()); +} + void Column::valuesReverse() { JASPTIMER_SCOPE(Column::valuesReverse); diff --git a/CommonData/column.h b/CommonData/column.h index eb204e3f07..1c47f119f8 100644 --- a/CommonData/column.h +++ b/CommonData/column.h @@ -40,14 +40,17 @@ class Analysis; /// It also handles storing the information of computed columns (those used to be split off) class Column : public DataSetBaseNode { -public: - Column(DataSet * data, int id = -1); +private: + Column(DataSet * data, int id, columnType colType, computedColumnType computedType, bool autoSort); + +public: + static Column * addColumn(DataSet* data, int index = -1, const std::string & name = "", columnType colType = columnType::scale, computedColumnType computedType = computedColumnType::notComputed, bool alterDataSetTable = true); + static Column * loadColumn(DataSet* data, int index); ~Column(); DatabaseInterface & db(); const DatabaseInterface & db() const; - void dbCreate( int index); void dbLoad( int id=-1, bool getValues = true); ///< Loads *and* reloads from DB! void dbLoadIndex(int index, bool getValues = true); void dbUpdateComputedColumnStuff(); @@ -71,7 +74,7 @@ class Column : public DataSetBaseNode void setInvalidated( bool invalidated ); void setForceType( bool force ); void setCompColStuff( bool invalidated, bool forceSourceColType, computedColumnType codeType, const std::string & rCode, const std::string & error, const Json::Value & constructorJson); - void setDefaultValues( enum columnType columnType = columnType::unknown); + void setDefaultValues(); bool setAsNominalOrOrdinal( const intvec & values, bool is_ordinal = false); bool setAsNominalOrOrdinal( const intvec & values, intstrmap uniqueValues, bool is_ordinal = false); @@ -238,7 +241,8 @@ class Column : public DataSetBaseNode columnTypeChangeResult _changeColumnToScale(); void _convertVectorIntToDouble(intvec & intValues, doublevec & doubleValues); void _resetLabelValueMap(); - doublevec valuesNumericOrdered(); + doublevec valuesNumericOrdered(); + stringvec valuesAlphabeticOrdered(); private: DataSet * const _data; diff --git a/CommonData/databaseinterface.cpp b/CommonData/databaseinterface.cpp index d7257e3f5a..878d86def3 100644 --- a/CommonData/databaseinterface.cpp +++ b/CommonData/databaseinterface.cpp @@ -392,11 +392,11 @@ void DatabaseInterface::filterWrite(int filterIndex, const std::vector & v transactionWriteEnd(); } -int DatabaseInterface::columnInsert(int dataSetId, int index, const std::string & name, columnType colType, bool alterTable) +int DatabaseInterface::columnInsert(int dataSetId, int index, columnType colType, computedColumnType computedType, bool autoSort, bool alterTable) { JASPTIMER_SCOPE(DatabaseInterface::columnInsert); transactionWriteBegin(); - + if(index == -1) index = columnLastFreeIndex(dataSetId); else columnIndexIncrements(dataSetId, index); @@ -405,14 +405,17 @@ int DatabaseInterface::columnInsert(int dataSetId, int index, const std::string #endif //Create column entry - int columnId = runStatementsId("INSERT INTO Columns (dataSet, name, columnType, colIdx, analysisId) VALUES (?, ?, ?, ?, -1) RETURNING id;", [&](sqlite3_stmt * stmt) + int columnId = runStatementsId("INSERT INTO Columns (dataSet, columnType, codeType, autoSortByValue, colIdx, analysisId) VALUES (?, ?, ?, ?, ?, -1) RETURNING id;", [&](sqlite3_stmt * stmt) { sqlite3_bind_int(stmt, 1, dataSetId); - sqlite3_bind_text(stmt, 2, name.c_str(), name.length(), SQLITE_TRANSIENT); std::string colT = columnTypeToString(colType); - sqlite3_bind_text(stmt, 3, colT.c_str(), colT.length(), SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 4, index); + std::string codeT = computedColumnTypeToString(computedType); + + sqlite3_bind_text(stmt, 2, colT.c_str(), colT.length(), SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 3, codeT.c_str(), codeT.length(), SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 4, autoSort); + sqlite3_bind_int(stmt, 5, index); }); #ifdef SIR_LOG_A_LOT diff --git a/CommonData/databaseinterface.h b/CommonData/databaseinterface.h index 92c82d64bc..0be9a1b8a0 100644 --- a/CommonData/databaseinterface.h +++ b/CommonData/databaseinterface.h @@ -110,7 +110,7 @@ class DatabaseInterface //Columns & Data/Values //Index stuff: - int columnInsert( int dataSetId, int index = -1, const std::string & name = "", columnType colType = columnType::unknown, bool alterTable=true); ///< Insert a row into Columns and create the corresponding columns in DataSet_? Also makes sure the indices are correct + int columnInsert( int dataSetId, int index, columnType colType, computedColumnType computedType, bool autoSort, bool alterTable=true); ///< Insert a row into Columns and create the corresponding columns in DataSet_? Also makes sure the indices are correct int columnLastFreeIndex( int dataSetId); void columnIndexIncrements( int dataSetId, int index); ///< If index already is in use that column and all after are incremented by 1 void columnIndexDecrements( int dataSetId, int index); ///< Indices bigger than index are decremented, assumption is that the previous one using it has been removed already diff --git a/CommonData/dataset.cpp b/CommonData/dataset.cpp index 59f82d2301..22f27a0f80 100644 --- a/CommonData/dataset.cpp +++ b/CommonData/dataset.cpp @@ -172,25 +172,26 @@ void DataSet::removeColumn(const std::string & name) } } -void DataSet::insertColumn(size_t index, bool alterDataSetTable) +Column* DataSet::insertColumn(size_t index, bool alterDataSetTable, const std::string & name, columnType colType, computedColumnType computedType) { - assert(_dataSetID > 0); - Column * newColumn = new Column(this, db().columnInsert(_dataSetID, index, "", columnType::unknown, alterDataSetTable)); + Column * newColumn = Column::addColumn(this, index, name, colType, computedType, alterDataSetTable); _columns.insert(_columns.begin()+index, newColumn); newColumn->setRowCount(_rowCount); + newColumn->setDefaultValues(); incRevision(); + + return newColumn; } Column * DataSet::newColumn(const std::string &name) { assert(_dataSetID > 0); - Column * col = new Column(this, db().columnInsert(_dataSetID, -1, name)); - col->setName(name); + Column * col = Column::addColumn(this, -1, name); _columns.push_back(col); @@ -281,9 +282,9 @@ void DataSet::dbLoad(int index, std::function progressCallback, boo for(size_t i=0; idbLoadIndex(i, false); + _columns.push_back(Column::loadColumn(this, i)); + else + _columns[i]->dbLoadIndex(i, false); progressCallback(0.2 + (i * colProgressMult * 0.3)); //should end at 0.5 } diff --git a/CommonData/dataset.h b/CommonData/dataset.h index 04d59b3252..7fa0b95635 100644 --- a/CommonData/dataset.h +++ b/CommonData/dataset.h @@ -44,7 +44,7 @@ class DataSet : public DataSetBaseNode void removeColumn( const std::string & name ); void removeColumn( size_t index ); void removeColumnById( size_t id ); - void insertColumn( size_t index, bool alterDataSetTable = true); + Column * insertColumn(size_t index, bool alterDataSetTable = true, const std::string & name = "", columnType colType = columnType::unknown, computedColumnType computedType = computedColumnType::notComputed); Column * newColumn( const std::string & name); int getColumnIndex( const std::string & name ) const; int columnIndex( const Column * col ) const; diff --git a/Desktop/components/JASP/Widgets/LabelEditorWindow.qml b/Desktop/components/JASP/Widgets/LabelEditorWindow.qml index 2898675d4d..eddcee0eab 100644 --- a/Desktop/components/JASP/Widgets/LabelEditorWindow.qml +++ b/Desktop/components/JASP/Widgets/LabelEditorWindow.qml @@ -57,7 +57,7 @@ FocusScope target: columnModel function onChosenColumnChanged() { - levelsTableView.lastRow = -1; + levelsTableView.selectedRow = -1; } } @@ -65,7 +65,7 @@ FocusScope property real remainingWidth: width - filterColWidth property real valueColWidth: Math.min(columnModel.valueMaxWidth + 10, remainingWidth * 0.5) * jaspTheme.uiScale property real labelColWidth: Math.min(columnModel.labelMaxWidth + 10, remainingWidth * 0.5) * jaspTheme.uiScale - property int lastRow: -1 + property int selectedRow: -1 columnHeaderDelegate: Item @@ -129,7 +129,7 @@ FocusScope { id: backgroundItem - onActiveFocusChanged: if(activeFocus) levelsTableView.lastRow = rowIndex + onActiveFocusChanged: if(activeFocus) levelsTableView.selectedRow = rowIndex MouseArea { @@ -440,7 +440,7 @@ FocusScope iconSource: jaspTheme.iconPath + "menu-column-order-by-values.svg" onClicked: { forceActiveFocus(); columnModel.toggleAutoSortByValues(); } - toolTip: qsTr("Automatically order labels by their numeric value") + toolTip: qsTr("Automatically order labels by their value") height: buttonColumnVariablesWindow.buttonHeight implicitHeight: buttonColumnVariablesWindow.buttonHeight @@ -458,7 +458,7 @@ FocusScope height: buttonColumnVariablesWindow.buttonHeight implicitHeight: buttonColumnVariablesWindow.buttonHeight width: height - visible: !columnModel.autoSort || columnModel.firstNonNumericRow > 1 //if there are at least 2 numerics we have something to reverse + visible: columnModel.hasSeveralNumericValues //if there are at least 2 numerics we have something to reverse } RoundedButton @@ -466,41 +466,41 @@ FocusScope iconSource: jaspTheme.iconPath + "arrow-reverse.png" onClicked: { forceActiveFocus(); columnModel.reverse(); } - toolTip: columnModel.autoSort ? qsTr("Reverse order of the labels with non-numeric values") : qsTr("Reverse order of all labels") + toolTip: qsTr("Reverse order of all labels") height: buttonColumnVariablesWindow.buttonHeight implicitHeight: buttonColumnVariablesWindow.buttonHeight width: height - visible: !columnModel.autoSort || columnModel.rowsTotal - columnModel.firstNonNumericRow > 1 //If there are at least 2 non numerics there is something to reverse - + visible: !columnModel.autoSort + enabled: columnModel.rowCount() > 1 } RoundedButton { iconSource: jaspTheme.iconPath + "arrow-up.png" - onClicked: { forceActiveFocus(); columnModel.moveSelectionUp(); levelsTableView.lastRow--; } - toolTip: columnModel.autoSort ? qsTr("Move selected non-numeric labels up") : qsTr("Move selected labels up") + onClicked: { forceActiveFocus(); columnModel.moveSelectionUp(); levelsTableView.selectedRow--; } + toolTip: qsTr("Move selected labels up") height: buttonColumnVariablesWindow.buttonHeight implicitHeight: buttonColumnVariablesWindow.buttonHeight width: height - enabled: levelsTableView.lastRow == -1 ? false : columnModel.firstNonNumericRow < levelsTableView.lastRow - visible: !columnModel.autoSort || columnModel.rowsTotal - columnModel.firstNonNumericRow > 1 //If there are at least 2 non numerics there is something to move up + enabled: levelsTableView.selectedRow > 0 + visible: !columnModel.autoSort } RoundedButton { iconSource: jaspTheme.iconPath + "arrow-down.png" - onClicked: { forceActiveFocus(); columnModel.moveSelectionDown(); levelsTableView.lastRow++; } - toolTip: columnModel.autoSort ? qsTr("Move selected non-numeric labels down") : qsTr("Move selected labels down") + onClicked: { forceActiveFocus(); columnModel.moveSelectionDown(); levelsTableView.selectedRow++; } + toolTip: qsTr("Move selected labels down") height: buttonColumnVariablesWindow.buttonHeight implicitHeight: buttonColumnVariablesWindow.buttonHeight width: height - enabled: levelsTableView.lastRow == -1 ? false : ((columnModel.firstNonNumericRow <= levelsTableView.lastRow) && ( levelsTableView.lastRow < columnModel.rowsTotal - 1 )) - visible: !columnModel.autoSort || columnModel.rowsTotal - columnModel.firstNonNumericRow > 1 //If there are at least 2 non numerics there is something to move down + enabled: levelsTableView.selectedRow >= 0 && levelsTableView.selectedRow < columnModel.rowCount() - 1 + visible: !columnModel.autoSort } RoundedButton diff --git a/Desktop/data/columnmodel.cpp b/Desktop/data/columnmodel.cpp index 81859ffcb9..2c4f16dffe 100644 --- a/Desktop/data/columnmodel.cpp +++ b/Desktop/data/columnmodel.cpp @@ -184,27 +184,25 @@ int ColumnModel::rowsTotal() const return rowCount(); } -int ColumnModel::firstNonNumericRow() const +bool ColumnModel::hasSeveralNumericValues() const { - if(!column() || !column()->autoSortByValue()) - return 0; + if(!column()) + return false; - int nonEmptyNonNumerics = 0; + int numberOfNumericalValues = 0; for(Label * label : column()->labels()) if(!label->isEmptyValue()) { static double dummy; - if(!(label->originalValue().isDouble() || ColumnUtils::getDoubleValue(label->originalValueAsString(), dummy))) - return nonEmptyNonNumerics; - nonEmptyNonNumerics++; + if(label->originalValue().isDouble() && ColumnUtils::getDoubleValue(label->originalValueAsString(), dummy)) + numberOfNumericalValues++; + + if (numberOfNumericalValues > 1) + return true; } - //If we have more temporary labels then normal ones then those afterwards are all numeric (or something wouldve been replaced/sorted) so we can return labelsTempCount() - if(column()->labelsTempCount() > nonEmptyNonNumerics) - return column()->labelsTempCount(); - - return nonEmptyNonNumerics; + return column()->labelsTempNumerics() > 1; } void ColumnModel::setCustomEmptyValues(const QStringList& customEmptyValues) @@ -589,10 +587,9 @@ void ColumnModel::refresh() emit nameEditableChanged(); emit columnDescriptionChanged(); emit computedTypeValuesChanged(); - emit firstNonNumericRowChanged(); + emit hasSeveralNumericValuesChanged(); emit computedTypeEditableChanged(); emit useCustomEmptyValuesChanged(); - emit firstNonNumericRowChanged(); emit columnTypeValuesChanged(); emit computedTypeChanged(); emit emptyValuesChanged(); diff --git a/Desktop/data/columnmodel.h b/Desktop/data/columnmodel.h index e09acf66ce..de65c5e7eb 100644 --- a/Desktop/data/columnmodel.h +++ b/Desktop/data/columnmodel.h @@ -38,7 +38,7 @@ class ColumnModel : public DataSetTableProxy Q_PROPERTY(bool isVirtual READ isVirtual NOTIFY isVirtualChanged ) Q_PROPERTY(bool compactMode READ compactMode WRITE setCompactMode NOTIFY compactModeChanged ) Q_PROPERTY(bool autoSort READ autoSort WRITE setAutoSort NOTIFY autoSortChanged ) - Q_PROPERTY(int firstNonNumericRow READ firstNonNumericRow NOTIFY firstNonNumericRowChanged ) //Only works when autosort is on + Q_PROPERTY(bool hasSeveralNumericValues READ hasSeveralNumericValues NOTIFY hasSeveralNumericValuesChanged ) //Only works when autosort is on Q_PROPERTY(int rowsTotal READ rowsTotal NOTIFY rowsTotalChanged ) public: @@ -58,7 +58,7 @@ class ColumnModel : public DataSetTableProxy QVariantList columnTypeValues() const; bool useCustomEmptyValues() const; QStringList emptyValues() const; - int firstNonNumericRow() const; + bool hasSeveralNumericValues() const; int rowsTotal() const; @@ -158,7 +158,7 @@ public slots: void isVirtualChanged(); void compactModeChanged(); void autoSortChanged(); - void firstNonNumericRowChanged(); + void hasSeveralNumericValuesChanged(); private: std::vector getSortedSelection() const; diff --git a/Desktop/data/computedcolumnmodel.cpp b/Desktop/data/computedcolumnmodel.cpp index ce25ca9391..5c0be8b922 100644 --- a/Desktop/data/computedcolumnmodel.cpp +++ b/Desktop/data/computedcolumnmodel.cpp @@ -269,7 +269,7 @@ void ComputedColumnModel::computeColumnFailed(QString columnNameQ, QString error if(areLoopDependenciesOk(columnName) && column->setError(error) && shouldNotifyQML) emit computeColumnErrorChanged(); - DataSetPackage::pkg()->columnSetDefaultValues(columnName, columnType::unknown, false); + DataSetPackage::pkg()->columnSetDefaultValues(columnName, false); emit refreshColumn(columnNameQ); validate(tq(columnName)); diff --git a/Desktop/data/datasetpackage.cpp b/Desktop/data/datasetpackage.cpp index 60bf062f0b..1b10b014c5 100644 --- a/Desktop/data/datasetpackage.cpp +++ b/Desktop/data/datasetpackage.cpp @@ -1873,7 +1873,7 @@ void DataSetPackage::labelReverse(size_t colIdx) emit labelsReordered(tq(column->name())); } -void DataSetPackage::columnSetDefaultValues(const std::string & columnName, columnType columnType, bool emitSignals) +void DataSetPackage::columnSetDefaultValues(const std::string & columnName, bool emitSignals) { if(!_dataSet) return; @@ -1883,7 +1883,7 @@ void DataSetPackage::columnSetDefaultValues(const std::string & columnName, colu if(colIndex >= 0) { Column * column = _dataSet->columns()[colIndex]; - column->setDefaultValues(columnType); + column->setDefaultValues(); QModelIndex p = indexForSubNode(_dataSet->dataNode()); @@ -2018,13 +2018,12 @@ QString DataSetPackage::insertColumnSpecial(int columnIndex, const QMapdataNode()), columnIndex, columnIndex); #endif - _dataSet->insertColumn(columnIndex); - - Column * column = _dataSet->column(columnIndex); - column->setName( props.contains("name") ? fq(props["name"].toString()) : freeNewColumnName(columnIndex) ); - column->setDefaultValues( props.contains("type") ? columnType(props["type"].toInt()) : columnType::scale ); - column->setCodeType( props.contains("computed") ? computedColumnType(props["computed"].toInt()) : computedColumnType::notComputed ); + std::string name = props.contains("name") ? fq(props["name"].toString()) : freeNewColumnName(columnIndex); + columnType colType = props.contains("type") ? columnType(props["type"].toInt()) : columnType::scale; + computedColumnType codeType = props.contains("computed") ? computedColumnType(props["computed"].toInt()) : computedColumnType::notComputed; + + Column * column = _dataSet->insertColumn(columnIndex, true, name, colType, codeType); _dataSet->incRevision(); @@ -2066,10 +2065,8 @@ bool DataSetPackage::insertColumns(int column, int count, const QModelIndex & ap for(int c = column; cinsertColumn(c); const std::string & name = freeNewColumnName(c); - _dataSet->column(c)->setName(name); - _dataSet->column(c)->setDefaultValues(columnType::scale); + _dataSet->insertColumn(c, true, name, columnType::scale); changed.push_back(name); } @@ -2218,9 +2215,7 @@ Column * DataSetPackage::createColumn(const std::string & name, columnType colum enginesPrepareForData(); beginResetModel(); - _dataSet->insertColumn(newColumnIndex); - _dataSet->column(newColumnIndex)->setName(name); - _dataSet->column(newColumnIndex)->setDefaultValues(columnType); + _dataSet->insertColumn(newColumnIndex, true, name, columnType); endResetModel(); enginesReceiveNewData(); diff --git a/Desktop/data/datasetpackage.h b/Desktop/data/datasetpackage.h index 897205b943..fae3f352e2 100644 --- a/Desktop/data/datasetpackage.h +++ b/Desktop/data/datasetpackage.h @@ -191,7 +191,7 @@ class DataSetPackage : public QAbstractItemModel //Not QAbstractTableModel becau void pasteSpreadsheet(size_t row, size_t column, const std::vector> & values, const std::vector> & labels, const intvec & colTypes, const QStringList & colNames, const std::vector & selected = {}); ///< If selected.size() >0 it is assumed to be the same size as labels/values. And it will make sure that it will only overwrite values where it is `true` - void columnSetDefaultValues( const std::string & columnName, columnType colType = columnType::unknown, bool emitSignals = true); + void columnSetDefaultValues( const std::string & columnName, bool emitSignals = true); Column * createColumn( const std::string & name, columnType colType); Column * createComputedColumn( const std::string & name, columnType type, computedColumnType desiredType, Analysis * analysis = nullptr); void renameColumn( const std::string & oldColumnName, const std::string & newColumnName); diff --git a/Desktop/po/jaspDesktop-de.po b/Desktop/po/jaspDesktop-de.po index f2b9b97769..871e757c57 100644 --- a/Desktop/po/jaspDesktop-de.po +++ b/Desktop/po/jaspDesktop-de.po @@ -5250,8 +5250,8 @@ msgid "Order labels by value by default" msgstr "Standardmäßig Beschriftungen nach Wert sortieren" msgctxt "LabelEditorWindow|" -msgid "Automatically order labels by their numeric value" -msgstr "Automatisch Beschriftungen nach deren numerischen Wert sortieren" +msgid "Automatically order labels by their value" +msgstr "Automatisch Beschriftungen nach deren Wert sortieren" msgctxt "LabelEditorWindow|" msgid "Reverse order of the labels with non-numeric values" diff --git a/Desktop/po/jaspDesktop-es.po b/Desktop/po/jaspDesktop-es.po index 7eefe3531b..737bb47724 100644 --- a/Desktop/po/jaspDesktop-es.po +++ b/Desktop/po/jaspDesktop-es.po @@ -5258,8 +5258,8 @@ msgid "Order labels by value by default" msgstr "Ordenar las etiquetas según valor, por defecto" msgctxt "LabelEditorWindow|" -msgid "Automatically order labels by their numeric value" -msgstr "Ordenar automaticamente las etiquetas según su valor numérico" +msgid "Automatically order labels by their value" +msgstr "Ordenar automaticamente las etiquetas según su valor" msgctxt "LabelEditorWindow|" msgid "Reverse order of the labels with non-numeric values" diff --git a/Desktop/po/jaspDesktop-gl.po b/Desktop/po/jaspDesktop-gl.po index d7235b18ed..ee24d4ceb0 100644 --- a/Desktop/po/jaspDesktop-gl.po +++ b/Desktop/po/jaspDesktop-gl.po @@ -5235,8 +5235,8 @@ msgid "Order labels by value by default" msgstr "Arranxar por defecto as etiquetas segundo o valor" msgctxt "LabelEditorWindow|" -msgid "Automatically order labels by their numeric value" -msgstr "Arranxar automaticamente as etiquetas segundo seu valor numérico" +msgid "Automatically order labels by their value" +msgstr "Arranxar automaticamente as etiquetas segundo seu valor" msgctxt "LabelEditorWindow|" msgid "Reverse order of the labels with non-numeric values" diff --git a/Desktop/po/jaspDesktop-nl.po b/Desktop/po/jaspDesktop-nl.po index 93dd8280aa..658d013faa 100644 --- a/Desktop/po/jaspDesktop-nl.po +++ b/Desktop/po/jaspDesktop-nl.po @@ -5211,8 +5211,8 @@ msgid "Order labels by value by default" msgstr "Standaard labels ordenen op waarde" msgctxt "LabelEditorWindow|" -msgid "Automatically order labels by their numeric value" -msgstr "Labels automatisch ordenen op hun numerieke waarde" +msgid "Automatically order labels by their value" +msgstr "Labels automatisch ordenen op hun waarde" msgctxt "LabelEditorWindow|" msgid "Reverse order of the labels with non-numeric values" diff --git a/Desktop/qquick/datasetview.cpp b/Desktop/qquick/datasetview.cpp index e4582a2b3a..a00da45862 100644 --- a/Desktop/qquick/datasetview.cpp +++ b/Desktop/qquick/datasetview.cpp @@ -80,6 +80,7 @@ void DataSetView::setModel(QAbstractItemModel * model) connect(model, &QAbstractItemModel::modelAboutToBeReset, this, &DataSetView::modelAboutToBeReset ); connect(_selectionModel, &QItemSelectionModel::selectionChanged, this, &DataSetView::selectionChanged); + connect(_selectionModel, &QItemSelectionModel::currentColumnChanged, this, &DataSetView::currentSelectedColumnHandler); connect(model, &QAbstractItemModel::columnsAboutToBeInserted, this, &DataSetView::columnsAboutToBeInserted ); connect(model, &QAbstractItemModel::columnsAboutToBeRemoved, this, &DataSetView::columnsAboutToBeRemoved ); @@ -1550,6 +1551,13 @@ void DataSetView::resizeData(int rows, int columns) _model->resize(rows - 1, columns - 1, false, tr("Resize data to %1 rows and %2 columns").arg(rows).arg(columns)); } +void DataSetView::currentSelectedColumnHandler(const QModelIndex ¤t, const QModelIndex &previous) +{ + int selectedColumn = current.column(); + if (selectedColumn >= 0) + emit DataSetPackage::pkg()->chooseColumn(selectedColumn); +} + void DataSetView::columnReverseValues(int columnIndex) { columnIndexSelectedApply(columnIndex, [&](intset col) { _model->columnReverseValues(col); }); diff --git a/Desktop/qquick/datasetview.h b/Desktop/qquick/datasetview.h index 86134c341e..381b0f5ceb 100644 --- a/Desktop/qquick/datasetview.h +++ b/Desktop/qquick/datasetview.h @@ -273,6 +273,7 @@ public slots: void setColumnType(int columnIndex, int newColumnType); void resizeData(int rows, int columns); + void currentSelectedColumnHandler(const QModelIndex ¤t, const QModelIndex &previous); protected: void _copy(QPoint where, bool clear);