Give the tables default sorting

This commit is contained in:
eelke 2021-06-12 07:36:24 +02:00
parent 0da493f1e4
commit ddc163a0ee
10 changed files with 66 additions and 50 deletions

View file

@ -63,60 +63,60 @@ void TablesTableModel::refresh()
m_tables.push_back(e);
}
doSort(1);
// doSort(1);
}
void TablesTableModel::setSortOrder(int so)
{
beginResetModel();
doSort(so);
endResetModel();
}
//void TablesTableModel::setSortOrder(int so)
//{
// beginResetModel();
// doSort(so);
// endResetModel();
//}
namespace {
//namespace {
inline bool compareByName(PgClass l, PgClass r)
{
return l.objectName() < r.objectName()
|| (l.objectName() == r.objectName() && l.nsName() < r.nsName());
}
// inline bool compareByName(PgClass l, PgClass r)
// {
// return l.objectName() < r.objectName()
// || (l.objectName() == r.objectName() && l.nsName() < r.nsName());
// }
inline bool compareBySchema(PgClass l, PgClass r)
{
return l.nsName() < r.nsName()
|| (l.nsName() == r.nsName() && l.objectName() < r.objectName());
}
// inline bool compareBySchema(PgClass l, PgClass r)
// {
// return l.nsName() < r.nsName()
// || (l.nsName() == r.nsName() && l.objectName() < r.objectName());
// }
}
//}
void TablesTableModel::sort(int column, Qt::SortOrder order)
{
if (column == NameCol) {
if (order == Qt::AscendingOrder)
std::sort(m_tables.begin(), m_tables.end(), compareByName);
else
std::sort(m_tables.begin(), m_tables.end(), [] (auto l, auto r) { return !compareByName(l, r); });
}
else if (column == NamespaceCol) {
if (order == Qt::AscendingOrder)
std::sort(m_tables.begin(), m_tables.end(), compareBySchema);
else
std::sort(m_tables.begin(), m_tables.end(), [] (auto l, auto r) { return !compareBySchema(l, r); });
}
//void TablesTableModel::sort(int column, Qt::SortOrder order)
//{
// if (column == NameCol) {
// if (order == Qt::AscendingOrder)
// std::sort(m_tables.begin(), m_tables.end(), compareByName);
// else
// std::sort(m_tables.begin(), m_tables.end(), [] (auto l, auto r) { return !compareByName(l, r); });
// }
// else if (column == NamespaceCol) {
// if (order == Qt::AscendingOrder)
// std::sort(m_tables.begin(), m_tables.end(), compareBySchema);
// else
// std::sort(m_tables.begin(), m_tables.end(), [] (auto l, auto r) { return !compareBySchema(l, r); });
// }
emit layoutChanged();
}
// emit layoutChanged();
//}
void TablesTableModel::doSort(int )
{
// if (so == 1)
// std::sort(m_tables.begin(), m_tables.end(),
// [] (auto l, auto r) -> bool { return l.relnamespace_name < r.relnamespace_name
// || (l.relnamespace_name == r.relnamespace_name && l.name < r.name); });
// else
// std::sort(m_tables.begin(), m_tables.end(),
// [] (auto l, auto r) -> bool { return l.name < r.name; });
}
//void TablesTableModel::doSort(int )
//{
//// if (so == 1)
//// std::sort(m_tables.begin(), m_tables.end(),
//// [] (auto l, auto r) -> bool { return l.relnamespace_name < r.relnamespace_name
//// || (l.relnamespace_name == r.relnamespace_name && l.name < r.name); });
//// else
//// std::sort(m_tables.begin(), m_tables.end(),
//// [] (auto l, auto r) -> bool { return l.name < r.name; });
//}
QVariant TablesTableModel::headerData(int section, Qt::Orientation orientation, int role) const