mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-29 15:29:50 -06:00
Visual sort indicators for multi-column sorting (#1810)
This adds visual sort indicators to the already working multi-column sorting. Qt sort indicator is disabled, so only one indicator per column is visible. Unicode characters are used to indicate direction (triangles) and sort column order (superscript numbers). See issue #1761
This commit is contained in:
@@ -10,7 +10,8 @@ FilterTableHeader::FilterTableHeader(QTableView* parent) :
|
||||
{
|
||||
// Activate the click signals to allow sorting
|
||||
setSectionsClickable(true);
|
||||
setSortIndicatorShown(true);
|
||||
// But use our own indicators allowing multi-column sorting
|
||||
setSortIndicatorShown(false);
|
||||
|
||||
// Do some connects: Basically just resize and reposition the input widgets whenever anything changes
|
||||
connect(this, SIGNAL(sectionResized(int,int,int)), this, SLOT(adjustPositions()));
|
||||
|
||||
@@ -749,9 +749,6 @@ void MainWindow::populateTable()
|
||||
for(int i=1;i<m_browseTableModel->columnCount();i++)
|
||||
ui->dataTable->setColumnWidth(i, ui->dataTable->horizontalHeader()->defaultSectionSize());
|
||||
|
||||
// Sorting
|
||||
ui->dataTable->filterHeader()->setSortIndicator(0, Qt::AscendingOrder);
|
||||
|
||||
// Encoding
|
||||
m_browseTableModel->setEncoding(defaultBrowseTableEncoding);
|
||||
|
||||
@@ -849,15 +846,6 @@ void MainWindow::applyBrowseTableSettings(BrowseDataTableSettings storedData, bo
|
||||
for(auto widthIt=storedData.columnWidths.constBegin();widthIt!=storedData.columnWidths.constEnd();++widthIt)
|
||||
ui->dataTable->setColumnWidth(widthIt.key(), widthIt.value());
|
||||
|
||||
// Sorting
|
||||
// For now just use the first sort column for the sort indicator
|
||||
if(storedData.query.orderBy().size())
|
||||
{
|
||||
ui->dataTable->filterHeader()->setSortIndicator(
|
||||
storedData.query.orderBy().front().column,
|
||||
storedData.query.orderBy().front().direction == sqlb::Ascending ? Qt::AscendingOrder : Qt::DescendingOrder);
|
||||
}
|
||||
|
||||
// Filters
|
||||
if(!skipFilters)
|
||||
{
|
||||
|
||||
@@ -222,9 +222,6 @@ You can drag SQL statements from an object row and drop them into other applicat
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ContiguousSelection</enum>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
||||
@@ -217,6 +217,23 @@ int SqliteTableModel::filterCount() const
|
||||
return m_query.where().size();
|
||||
}
|
||||
|
||||
// Convert a number to string using the Unicode superscript characters
|
||||
static QString toSuperScript(int number)
|
||||
{
|
||||
QString superScript = QString::number(number);
|
||||
superScript.replace("0", "⁰");
|
||||
superScript.replace("1", "¹");
|
||||
superScript.replace("2", "²");
|
||||
superScript.replace("3", "³");
|
||||
superScript.replace("4", "⁴");
|
||||
superScript.replace("5", "⁵");
|
||||
superScript.replace("6", "⁶");
|
||||
superScript.replace("7", "⁷");
|
||||
superScript.replace("8", "⁸");
|
||||
superScript.replace("9", "⁹");
|
||||
return superScript;
|
||||
}
|
||||
|
||||
QVariant SqliteTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
@@ -225,9 +242,19 @@ QVariant SqliteTableModel::headerData(int section, Qt::Orientation orientation,
|
||||
if (orientation == Qt::Horizontal)
|
||||
{
|
||||
// if we have a VIRTUAL table the model will not be valid, with no header data
|
||||
if(section < m_headers.size())
|
||||
return m_headers.at(section);
|
||||
|
||||
if(section < m_headers.size()) {
|
||||
QString sortIndicator;
|
||||
for(int 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 == section) {
|
||||
sortIndicator = sortedColumn.direction == sqlb::Ascending ? " ▾" : " ▴";
|
||||
sortIndicator.append(toSuperScript(i+1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return m_headers.at(section) + sortIndicator;
|
||||
}
|
||||
return QString("%1").arg(section + 1);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user