From f9183105745653ccdc137126aa8f4f1269014af2 Mon Sep 17 00:00:00 2001 From: Lubos Dolezel Date: Tue, 2 Jun 2015 22:03:32 +0200 Subject: Ported getaddressform to Qt4 --- src/gui/addresstablemodel.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/gui/addresstablemodel.cpp (limited to 'src/gui/addresstablemodel.cpp') diff --git a/src/gui/addresstablemodel.cpp b/src/gui/addresstablemodel.cpp new file mode 100644 index 0000000..2e7120c --- /dev/null +++ b/src/gui/addresstablemodel.cpp @@ -0,0 +1,103 @@ +/* + Copyright (C) 2015 Lubos Dolezel + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "addresstablemodel.h" +#include + +// Columns +#define COL_ADDR_NAME 0 +#define COL_ADDR_PHONE 1 +#define COL_ADDR_REMARK 2 + +AddressTableModel::AddressTableModel(QObject *parent, const list& data) + : QAbstractTableModel(parent) +{ + m_data = QList::fromStdList(data); +} + +int AddressTableModel::rowCount(const QModelIndex &parent) const +{ + return m_data.size(); +} + +int AddressTableModel::columnCount(const QModelIndex &parent) const +{ + return 3; +} + +QVariant AddressTableModel::data(const QModelIndex &index, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + const int row = index.row(); + switch (index.column()) + { + case COL_ADDR_NAME: + return QString::fromStdString(m_data[row].get_display_name()); + case COL_ADDR_PHONE: + return QString::fromStdString(m_data[row].sip_address); + case COL_ADDR_REMARK: + return QString::fromStdString(m_data[row].remark); + default: + return QVariant(); + } +} + +QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + switch (section) + { + case COL_ADDR_NAME: + return tr("Name"); + case COL_ADDR_PHONE: + return tr("Phone"); + case COL_ADDR_REMARK: + return tr("Remark"); + default: + return QVariant(); + } +} + +void AddressTableModel::appendAddress(const t_address_card& card) +{ + qDebug() << "Appending contact" << QString::fromStdString(card.get_display_name()); + + beginInsertRows(QModelIndex(), m_data.size(), m_data.size()); + m_data << card; + endInsertRows(); +} + +void AddressTableModel::removeAddress(int index) +{ + beginRemoveRows(QModelIndex(), index, index); + + m_data.removeAt(index); + + endRemoveRows(); +} + +void AddressTableModel::modifyAddress(int index, const t_address_card& card) +{ + m_data[index] = card; + emit dataChanged(createIndex(index, 0), createIndex(index, 2)); +} + -- cgit v1.2.3