Skip to content

Commit 47eef8e

Browse files
committed
less columnindex more columnname
1 parent d75d948 commit 47eef8e

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

CommonData/dataset.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,8 @@ QVariant DataSet::headerData(int section, Qt::Orientation orientation, int role)
982982
case int(dataPkgRoles::maxRowHeaderString): return QString::number(rowCount()) + "XXX";
983983
case Qt::TextAlignmentRole: return QVariant(Qt::AlignCenter);
984984
case int(dataPkgRoles::filter): return !col ? false : col->hasLabelFilter() || getColumnInDragNDropShownFilter(col);
985-
case Qt::DisplayRole: return tq( !col ? "?" : col->name());
986-
985+
case Qt::DisplayRole: [[fallthrough]];
986+
case int(dataPkgRoles::name): return tq( !col ? "?" : col->name());
987987
case int(dataPkgRoles::labelsHasFilter): return !col ? false : col->hasLabelFilter();
988988
case int(dataPkgRoles::columnIsComputed): return !col ? false : col->isComputed() && col->codeType() != computedColumnType::analysisNotComputed;
989989
case int(dataPkgRoles::computedColumnError): return tq( !col ? "?" : col->error());

Desktop/data/columnmodel.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ void ColumnModel::setChosenColumnByName(const QString chosenNameQ, int colIndex)
543543
// Always set the chosen column even if it is the same one: the ColumnModel might be not reset correctly when the dataset is closed.
544544

545545
//If the user deletes the name the column ought to be removed because we cannot have columns without a name!
546-
int deleteMe = column() && column()->name() == "" ? _columnIndex : -1;
546+
std::string deleteMe = column() && column()->name() == "" ? column()->name() : "";
547547

548548
emit beforeChangingColumn(chosenNameQ);
549549

@@ -566,18 +566,17 @@ void ColumnModel::setChosenColumnByName(const QString chosenNameQ, int colIndex)
566566

567567
refresh();
568568

569-
if(deleteMe >= 0)
569+
if(deleteMe != "")
570570
chosenColumn->data()->removeColumn(deleteMe);
571571
}
572572

573573
void ColumnModel::setChosenColumn(int columnIndex)
574574
{
575-
DataSet * data = DataSetPackage::pkg()->dataSet();
576-
Column * col = data->column(columnIndex);
575+
QString name = emit columnNameForIndex(columnIndex);
577576

578-
if(col)
577+
if(name != "")
579578
{
580-
setChosenColumnByName(col->nameQ());
579+
setChosenColumnByName(name);
581580
return;
582581
}
583582

@@ -635,7 +634,7 @@ QVariant ColumnModel::headerData(int section, Qt::Orientation orientation, int r
635634
case Qt::TextAlignmentRole: return QVariant(Qt::AlignCenter);
636635
}
637636

638-
return QVariant();
637+
return QIdentityProxyModel::headerData(section, orientation, role);
639638
}
640639

641640
int ColumnModel::rowCount(const QModelIndex & p) const
@@ -739,9 +738,8 @@ void ColumnModel::checkCurrentColumn(QStringList, QStringList missingColumns, QM
739738
if (hasNewColumns && _virtual && DataSetPackage::pkg()->dataSet()->columnCount() >= _columnIndex)
740739
{
741740
// The current column is not virtual anymore: reset it
742-
int colId = _columnIndex;
743741
_columnIndex = -1;
744-
setChosenColumn(colId);
742+
setChosenColumnByName(colName);
745743
}
746744
}
747745
}

Desktop/data/columnmodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public slots:
174174
void autoSortChanged();
175175
void hasSeveralNumericValuesChanged();
176176
void computeFilterChanged();
177+
QString columnNameForIndex(int index);
177178

178179
private:
179180
std::vector<size_t> getSortedSelection() const;

Desktop/data/datasettablemodel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ void DataSetTableModel::setColumnFilter(const QString &newColumnFilter)
117117
{
118118
if (_columnFilter == newColumnFilter)
119119
return;
120+
120121
_columnFilter = newColumnFilter;
121-
emit columnFilterChanged();
122+
emit columnFilterChanged(_columnFilter);
123+
122124
invalidateColumnsFilter();
123125
}

Desktop/data/datasettablemodel.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DataSetTableModel : public QSortFilterProxyModel
3939
int columnsFilteredCount() const { return DataSetPackage::pkg()->columnsFilteredCount(); }
4040
Q_INVOKABLE bool isColumnNameFree(QString name) { return DataSetPackage::pkg()->isColumnNameFree(name); }
4141
QString columnFilter() const;
42-
Q_INVOKABLE QString columnName(int column) const;
42+
4343
Q_INVOKABLE void setColumnName(int col, QString name);
4444
Q_INVOKABLE QVariant getColumnTypesWithIcons() const { return DataSetPackage::pkg()->getColumnTypesWithIcons(); }
4545
void setColumnFilter(const QString &newColumnFilter);
@@ -62,11 +62,12 @@ class DataSetTableModel : public QSortFilterProxyModel
6262
void labelChanged(QString columnName, QString originalLabel, QString newLabel);
6363
void labelsReordered(QString columnName);
6464
void emptyValuesChanged();
65-
void columnFilterChanged();
65+
void columnFilterChanged(QString);
6666
void renameColumnDialog(int columnIndex);
6767

6868

6969
public slots:
70+
QString columnName(int column) const;
7071
void setShowInactive(bool showInactive);
7172
void handleDataSetChange();
7273
//void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) { if( roles.count(int(dataPkgRoles::filter)) > 0) invalidateFilter(); }

Desktop/mainwindow.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ MainWindow::MainWindow(QApplication * application) : QObject(application), _appl
106106
_datasetTableModel = new DataSetTableModel();
107107
_dataSetModelVarInfo = new DataSetTableModel(false);
108108
_columnModel = new ColumnModel();
109-
109+
110+
connect(_datasetTableModel, &DataSetTableModel::columnFilterChanged, _dataSetModelVarInfo, &DataSetTableModel::setColumnFilter);
111+
110112
initLog(); //initLog needs _preferences and _engineSync!
111113

112114
Log::log() << "JASP " << AppInfo::version.asString() << " from commit " << AppInfo::gitCommit << " and branch " << AppInfo::gitBranch << " is continuing initialization." << std::endl;
@@ -456,6 +458,8 @@ void MainWindow::makeConnections()
456458
connect(_resultsJsInterface, &ResultsJsInterface::resultsPageLoadedSignal, _languageModel, &LanguageModel::resultsPageLoaded, Qt::QueuedConnection);
457459
connect(_resultsJsInterface, &ResultsJsInterface::showRSyntaxInResults, _analyses, &Analyses::showRSyntaxInResults );
458460

461+
connect(_columnModel, &ColumnModel::columnNameForIndex, _datasetTableModel, &DataSetTableModel::columnName );
462+
459463
connect(_analyses, &Analyses::countChanged, this, &MainWindow::analysesCountChangedHandler );
460464
connect(_analyses, &Analyses::analysisResultsChanged, this, &MainWindow::analysisResultsChangedHandler );
461465
connect(_analyses, &Analyses::analysisImageSaved, this, &MainWindow::analysisImageSavedHandler );

0 commit comments

Comments
 (0)