summaryrefslogtreecommitdiffstats
path: root/src/gui/addresstablemodel.cpp
diff options
context:
space:
mode:
authorLubos Dolezel <lubos@dolezel.info>2015-06-02 22:03:32 +0200
committerLubos Dolezel <lubos@dolezel.info>2015-06-02 22:03:32 +0200
commitf9183105745653ccdc137126aa8f4f1269014af2 (patch)
tree56c606a58849846ed7a2471bc3714bf226ae6ea1 /src/gui/addresstablemodel.cpp
parentbf8bdac13a2d399ddded91de4bfb05e8dad0a0c8 (diff)
downloadtwinkle-f9183105745653ccdc137126aa8f4f1269014af2.tar
twinkle-f9183105745653ccdc137126aa8f4f1269014af2.tar.gz
twinkle-f9183105745653ccdc137126aa8f4f1269014af2.tar.lz
twinkle-f9183105745653ccdc137126aa8f4f1269014af2.tar.xz
twinkle-f9183105745653ccdc137126aa8f4f1269014af2.zip
Ported getaddressform to Qt4
Diffstat (limited to 'src/gui/addresstablemodel.cpp')
-rw-r--r--src/gui/addresstablemodel.cpp103
1 files changed, 103 insertions, 0 deletions
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 <lubos@dolezel.info>
+
+ 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 <QtDebug>
+
+// Columns
+#define COL_ADDR_NAME 0
+#define COL_ADDR_PHONE 1
+#define COL_ADDR_REMARK 2
+
+AddressTableModel::AddressTableModel(QObject *parent, const list<t_address_card>& data)
+ : QAbstractTableModel(parent)
+{
+ m_data = QList<t_address_card>::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));
+}
+