diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/addresstablemodel.cpp | 25 | ||||
-rw-r--r-- | src/gui/addresstablemodel.h | 1 | ||||
-rw-r--r-- | src/gui/getaddressform.ui | 3 |
3 files changed, 29 insertions, 0 deletions
diff --git a/src/gui/addresstablemodel.cpp b/src/gui/addresstablemodel.cpp index 2e7120c..9fc21fc 100644 --- a/src/gui/addresstablemodel.cpp +++ b/src/gui/addresstablemodel.cpp @@ -101,3 +101,28 @@ void AddressTableModel::modifyAddress(int index, const t_address_card& card) emit dataChanged(createIndex(index, 0), createIndex(index, 2)); } +void AddressTableModel::sort(int column, Qt::SortOrder order) +{ + qSort(m_data.begin(), m_data.end(), [=](const t_address_card& a1, const t_address_card& a2) -> bool { + bool retval = false; + + switch (column) + { + case COL_ADDR_NAME: + retval = QString::fromStdString(a1.get_display_name()) < QString::fromStdString(a2.get_display_name()); + break; + case COL_ADDR_PHONE: + retval = a1.sip_address.compare(a2.sip_address) < 0; + break; + case COL_ADDR_REMARK: + retval = a1.remark.compare(a2.remark) < 0; + break; + } + + if (order == Qt::DescendingOrder) + retval = !retval; + return retval; + }); + + emit dataChanged(createIndex(0, 0), createIndex(m_data.size()-1, 2)); +} diff --git a/src/gui/addresstablemodel.h b/src/gui/addresstablemodel.h index 847ee05..c38b9ac 100644 --- a/src/gui/addresstablemodel.h +++ b/src/gui/addresstablemodel.h @@ -34,6 +34,7 @@ public: virtual int columnCount(const QModelIndex &parent) const; virtual QVariant data(const QModelIndex &index, int role) const; virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; + virtual void sort(int column, Qt::SortOrder order); void appendAddress(const t_address_card& card); void removeAddress(int index); diff --git a/src/gui/getaddressform.ui b/src/gui/getaddressform.ui index c288384..0682f2a 100644 --- a/src/gui/getaddressform.ui +++ b/src/gui/getaddressform.ui @@ -139,6 +139,9 @@ <property name="selectionBehavior"> <enum>QAbstractItemView::SelectRows</enum> </property> + <property name="sortingEnabled"> + <bool>true</bool> + </property> <property name="columnCount" stdset="0"> <number>3</number> </property> |