summaryrefslogtreecommitdiffstats
blob: e5dc35edc818afdb0c6a04c8c96dd5f2899ff235 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright (c) 2018 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

//#include <Swift/QtUI/ServerList/ServerListModel.h>
#include <QBrush>
#include <QColor>
#include <QMimeData>

#include "ServerListModel.h"

namespace Swift {

ServerListModel::ServerListModel() {
}

ServerListModel::~ServerListModel() {
}

QVariant ServerListModel::data(const QModelIndex& index, int role) const {
    if (!index.isValid()) {
        return QVariant();
    }
    SwiftAccountData::SwiftAccountDataItem* item = static_cast<SwiftAccountData::SwiftAccountDataItem*>(index.internalPointer());
    switch (role) {
    case Qt::DisplayRole: return QString(item->userJID_.toBare().toString().c_str());
    case Qt::BackgroundRole: return QBrush(Qt::transparent);
    case Qt::ToolTipRole: return QString(item->userJID_.toBare().toString().c_str());
    default: return QVariant();
    }
}

QModelIndex ServerListModel::index(int row, int column, const QModelIndex& /*parent*/) const {
    if (!modelData_ || static_cast<size_t>(row) >= modelData_->size()) {
        return QModelIndex();
    }
    return createIndex(row, column, modelData_->getAccount(row));
}

QModelIndex ServerListModel::parent(const QModelIndex& /*index*/) const {
    return QModelIndex();
}

QMimeData* ServerListModel::mimeData(const QModelIndexList& indexes) const {
    return QAbstractItemModel::mimeData(indexes);
}

int ServerListModel::rowCount(const QModelIndex& /*parent*/) const {
    if (!modelData_) {
        return 0;
    }
    return modelData_->size();
}

int ServerListModel::columnCount(const QModelIndex& /*parent*/) const {
    if (!modelData_) {
        return 0;
    }
    return 1;
}

void ServerListModel::handleDataChanged() {
    emit layoutChanged();
}

}