mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 19:11:39 -06:00
Avoid displaying sort indicators in plot dock and "Copy with headers"
headerData() now returns column name plus sort indicator in the display role and only the column name in the edit role. This allows to use the edit role for the plot and the copy-with-headers features, so they do not show the sort indicator as part of the column name. See related issue #1409 and PR #1810
This commit is contained in:
@@ -482,7 +482,7 @@ void ExtendedTableWidget::copyMimeData(const QModelIndexList& fromIndices, QMime
|
||||
htmlResult.append("<tr><th>");
|
||||
int firstColumn = indices.front().column();
|
||||
for(int i = firstColumn; i <= indices.back().column(); i++) {
|
||||
QByteArray headerText = model()->headerData(i, Qt::Horizontal, Qt::DisplayRole).toByteArray();
|
||||
QByteArray headerText = model()->headerData(i, Qt::Horizontal, Qt::EditRole).toByteArray();
|
||||
if (i != firstColumn) {
|
||||
result.append(fieldSepText);
|
||||
htmlResult.append("</th><th>");
|
||||
|
||||
@@ -193,7 +193,7 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett
|
||||
// in the PlotColumnType, both using the User Role.
|
||||
columnitem->setData(PlotColumnField, Qt::UserRole, i);
|
||||
columnitem->setData(PlotColumnType, Qt::UserRole, static_cast<int>(columntype));
|
||||
columnitem->setText(PlotColumnField, model->headerData(i, Qt::Horizontal).toString());
|
||||
columnitem->setText(PlotColumnField, model->headerData(i, Qt::Horizontal, Qt::EditRole).toString());
|
||||
|
||||
// restore previous check state
|
||||
if(mapItemsY.contains(columnitem->text(PlotColumnField)))
|
||||
@@ -435,7 +435,7 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett
|
||||
if(column == RowNumId)
|
||||
yAxisLabels << tr("Row #");
|
||||
else
|
||||
yAxisLabels << model->headerData(column, Qt::Horizontal).toString();
|
||||
yAxisLabels << model->headerData(column, Qt::Horizontal, Qt::EditRole).toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,7 +448,7 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett
|
||||
if(x == RowNumId)
|
||||
ui->plotWidget->xAxis->setLabel(tr("Row #"));
|
||||
else
|
||||
ui->plotWidget->xAxis->setLabel(model->headerData(x, Qt::Horizontal).toString());
|
||||
ui->plotWidget->xAxis->setLabel(model->headerData(x, Qt::Horizontal, Qt::EditRole).toString());
|
||||
ui->plotWidget->yAxis->setLabel(yAxisLabels.join("|"));
|
||||
}
|
||||
|
||||
|
||||
@@ -243,24 +243,30 @@ static QString toSuperScript(T number)
|
||||
|
||||
QVariant SqliteTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
if (role != Qt::DisplayRole && role != Qt::EditRole)
|
||||
return QVariant();
|
||||
|
||||
if (orientation == Qt::Horizontal)
|
||||
{
|
||||
// if we have a VIRTUAL table the model will not be valid, with no header data
|
||||
if(static_cast<size_t>(section) < m_headers.size()) {
|
||||
QString sortIndicator;
|
||||
for(size_t i = 0; i < m_query.orderBy().size(); i++) {
|
||||
const sqlb::SortedColumn sortedColumn = m_query.orderBy()[i];
|
||||
// Append sort indicator with direction and ordinal number in superscript style
|
||||
if (sortedColumn.column == static_cast<size_t>(section)) {
|
||||
sortIndicator = sortedColumn.direction == sqlb::Ascending ? " ▾" : " ▴";
|
||||
sortIndicator.append(toSuperScript(i+1));
|
||||
break;
|
||||
const QString plainHeader = QString::fromStdString(m_headers.at(static_cast<size_t>(section)));
|
||||
// In the edit role, return a plain column name, but in the display role, add the sort indicator.
|
||||
if (role == Qt::EditRole)
|
||||
return plainHeader;
|
||||
else {
|
||||
QString sortIndicator;
|
||||
for(size_t i = 0; i < m_query.orderBy().size(); i++) {
|
||||
const sqlb::SortedColumn sortedColumn = m_query.orderBy()[i];
|
||||
// Append sort indicator with direction and ordinal number in superscript style
|
||||
if (sortedColumn.column == static_cast<size_t>(section)) {
|
||||
sortIndicator = sortedColumn.direction == sqlb::Ascending ? " ▾" : " ▴";
|
||||
sortIndicator.append(toSuperScript(i+1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return plainHeader + sortIndicator;
|
||||
}
|
||||
return QString::fromStdString(m_headers.at(static_cast<size_t>(section))) + sortIndicator;
|
||||
}
|
||||
return QString("%1").arg(section + 1);
|
||||
}
|
||||
@@ -538,7 +544,7 @@ Qt::ItemFlags SqliteTableModel::flags(const QModelIndex& index) const
|
||||
if(m_query.selectedColumns().size())
|
||||
{
|
||||
if(index.column() > 0)
|
||||
custom_display_format = QString::fromStdString(m_query.selectedColumns().at(static_cast<size_t>(index.column())-1).selector) != sqlb::escapeIdentifier(headerData(index.column(), Qt::Horizontal).toString());
|
||||
custom_display_format = QString::fromStdString(m_query.selectedColumns().at(static_cast<size_t>(index.column())-1).selector) != sqlb::escapeIdentifier(headerData(index.column(), Qt::Horizontal, Qt::EditRole).toString());
|
||||
}
|
||||
|
||||
if(!isBinary(index) && !custom_display_format)
|
||||
|
||||
Reference in New Issue
Block a user