MCPcopy Create free account
hub / github.com/KDE/labplot / powerTransformSelectedColumns

Method powerTransformSelectedColumns

src/frontend/spreadsheet/SpreadsheetView.cpp:3108–3201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3106}
3107
3108void SpreadsheetView::powerTransformSelectedColumns(QAction* action) {
3109 auto columns = selectedColumns();
3110 if (columns.isEmpty())
3111 return;
3112
3113 auto power = static_cast<TukeyLadderPower>(action->data().toInt());
3114
3115 WAIT_CURSOR;
3116 m_spreadsheet->beginMacro(i18n("%1: power transform columns", m_spreadsheet->name()));
3117
3118 for (auto* col : columns) {
3119 if (col->columnMode() != AbstractColumn::ColumnMode::Double && col->columnMode() != AbstractColumn::ColumnMode::Integer
3120 && col->columnMode() != AbstractColumn::ColumnMode::BigInt)
3121 continue;
3122
3123 if (col->columnMode() == AbstractColumn::ColumnMode::Integer || col->columnMode() == AbstractColumn::ColumnMode::BigInt)
3124 col->setColumnMode(AbstractColumn::ColumnMode::Double);
3125
3126 auto* data = static_cast<QVector<double>*>(col->data());
3127 QVector<double> new_data(col->rowCount());
3128
3129 switch (power) {
3130 case InverseSquared: {
3131 for (int i = 0; i < col->rowCount(); ++i) {
3132 double x = data->operator[](i);
3133 if (x != 0.0)
3134 new_data[i] = 1 / gsl_pow_2(x);
3135 else
3136 new_data[i] = NAN;
3137 }
3138 break;
3139 }
3140 case Inverse: {
3141 for (int i = 0; i < col->rowCount(); ++i) {
3142 double x = data->operator[](i);
3143 if (x != 0.0)
3144 new_data[i] = 1 / x;
3145 else
3146 new_data[i] = NAN;
3147 }
3148 break;
3149 }
3150 case InverseSquareRoot: {
3151 for (int i = 0; i < col->rowCount(); ++i) {
3152 double x = data->operator[](i);
3153 if (x >= 0.0)
3154 new_data[i] = 1 / std::sqrt(x);
3155 else
3156 new_data[i] = NAN;
3157 }
3158 break;
3159 }
3160 case Log: {
3161 for (int i = 0; i < col->rowCount(); ++i) {
3162 double x = data->operator[](i);
3163 if (x >= 0.0)
3164 new_data[i] = log10(x);
3165 else

Callers

nothing calls this directly

Calls 10

beginMacroMethod · 0.80
operator[]Method · 0.80
endMacroMethod · 0.80
isEmptyMethod · 0.45
dataMethod · 0.45
nameMethod · 0.45
columnModeMethod · 0.45
setColumnModeMethod · 0.45
rowCountMethod · 0.45
setValuesMethod · 0.45

Tested by

no test coverage detected