forked from qt-creator/qt-creator
Axivion: Store key inside column info
Small refactoring which makes later improvements of the UX easier. Change-Id: Ia6630cfbed68295271344b95d66cfed26dd8b3fc Reviewed-by: Mohammad Mehdi Salem Naraghi <mehdi.salem@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -429,6 +429,7 @@ void IssuesWidget::updateTable()
|
||||
if (!column.showByDefault)
|
||||
hiddenColumns << column.key;
|
||||
IssueHeaderView::ColumnInfo info;
|
||||
info.key = column.key;
|
||||
info.sortable = column.canSort;
|
||||
info.filterable = column.canFilter;
|
||||
info.width = column.width;
|
||||
@@ -643,6 +644,7 @@ void IssuesWidget::setFiltersEnabled(bool enabled)
|
||||
IssueListSearch IssuesWidget::searchFromUi() const
|
||||
{
|
||||
IssueListSearch search;
|
||||
QTC_ASSERT(m_currentTableInfo, return search);
|
||||
search.kind = m_currentPrefix; // not really ui.. but anyhow
|
||||
search.owner = m_userNames.at(m_ownerFilter->currentIndex());
|
||||
search.filter_path = m_pathGlobFilter->text();
|
||||
@@ -656,24 +658,8 @@ IssueListSearch IssuesWidget::searchFromUi() const
|
||||
else if (m_removedFilter->isChecked())
|
||||
search.state = "removed";
|
||||
|
||||
QTC_ASSERT(m_currentTableInfo, return search);
|
||||
QString sort;
|
||||
const QList<QPair<int, Qt::SortOrder>> currentSortColumns = m_headerView->currentSortColumns();
|
||||
for (const auto &pair : currentSortColumns) {
|
||||
QTC_ASSERT((ulong)pair.first < m_currentTableInfo->columns.size(), return search);
|
||||
if (!sort.isEmpty())
|
||||
sort.append(',');
|
||||
sort.append(m_currentTableInfo->columns.at(pair.first).key
|
||||
+ (pair.second == Qt::AscendingOrder ? " asc" : " desc"));
|
||||
}
|
||||
search.sort = sort;
|
||||
QMap<QString, QString> filter;
|
||||
const QList<QPair<int, QString>> currentFilterColumns = m_headerView->currentFilterColumns();
|
||||
for (const auto &pair : currentFilterColumns) {
|
||||
QTC_ASSERT((ulong)pair.first < m_currentTableInfo->columns.size(), return search);
|
||||
filter.insert("filter_" + m_currentTableInfo->columns.at(pair.first).key, pair.second);
|
||||
}
|
||||
search.filter = filter;
|
||||
search.sort = m_headerView->currentSortString();
|
||||
search.filter = m_headerView->currentFilterMapping();
|
||||
return search;
|
||||
}
|
||||
|
||||
|
@@ -169,23 +169,28 @@ void IssueHeaderView::setColumnInfoList(const QList<ColumnInfo> &infos)
|
||||
headerDataChanged(Qt::Horizontal, oldIndex, oldIndex);
|
||||
}
|
||||
|
||||
QList<QPair<int, Qt::SortOrder>> IssueHeaderView::currentSortColumns() const
|
||||
const QString IssueHeaderView::currentSortString() const
|
||||
{
|
||||
QList<QPair<int, Qt::SortOrder>> result;
|
||||
for (int i : m_currentSortIndexes)
|
||||
result.append({i, *m_columnInfoList.at(i).sortOrder});
|
||||
return result;
|
||||
QString sort;
|
||||
for (int i : m_currentSortIndexes) {
|
||||
QTC_ASSERT(i >= 0 && i < m_columnInfoList.size(), return {});
|
||||
if (!sort.isEmpty())
|
||||
sort.append(',');
|
||||
const ColumnInfo info = m_columnInfoList.at(i);
|
||||
sort.append(info.key + (info.sortOrder == Qt::AscendingOrder ? " asc" : " desc"));
|
||||
}
|
||||
return sort;
|
||||
}
|
||||
|
||||
QList<QPair<int, QString>> IssueHeaderView::currentFilterColumns() const
|
||||
const QMap<QString, QString> IssueHeaderView::currentFilterMapping() const
|
||||
{
|
||||
QList<QPair<int, QString>> result;
|
||||
QMap<QString, QString> filter;
|
||||
for (int i = 0, end = m_columnInfoList.size(); i < end; ++i) {
|
||||
const ColumnInfo ci = m_columnInfoList.at(i);
|
||||
if (ci.filter.has_value())
|
||||
result.append({i, *ci.filter});
|
||||
filter.insert("filter_" + ci.key, *ci.filter);
|
||||
}
|
||||
return result;
|
||||
return filter;
|
||||
}
|
||||
|
||||
void IssueHeaderView::mousePressEvent(QMouseEvent *event)
|
||||
|
@@ -16,6 +16,7 @@ class IssueHeaderView : public QHeaderView
|
||||
public:
|
||||
struct ColumnInfo
|
||||
{
|
||||
QString key;
|
||||
int width = 0;
|
||||
std::optional<Qt::SortOrder> sortOrder = std::nullopt;
|
||||
bool sortable = false;
|
||||
@@ -26,8 +27,8 @@ public:
|
||||
explicit IssueHeaderView(QWidget *parent = nullptr) : QHeaderView(Qt::Horizontal, parent) {}
|
||||
void setColumnInfoList(const QList<ColumnInfo> &infos);
|
||||
|
||||
QList<QPair<int, Qt::SortOrder>> currentSortColumns() const;
|
||||
QList<QPair<int, QString>> currentFilterColumns() const;
|
||||
const QString currentSortString() const;
|
||||
const QMap<QString, QString> currentFilterMapping() const;
|
||||
|
||||
signals:
|
||||
void filterChanged();
|
||||
|
Reference in New Issue
Block a user