File: userlistmodel.h

package info (click to toggle)
dc-qt 0.2.0.alpha-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,936 kB
  • ctags: 5,361
  • sloc: cpp: 28,936; makefile: 19
file content (85 lines) | stat: -rw-r--r-- 2,212 bytes parent folder | download | duplicates (4)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// C++ Interface: UserListModel
//
// Description:
// Defines the UserList data model
//
// Author: Rikard Björklind <olof@linux.nu>, (C) 2005.2006
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef USER_LIST_H__
#define USER_LIST_H__

#include <QAbstractTableModel>
#include <QHash>
#include <QIcon>
#include "user.h"

class UserListModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    UserListModel() : QAbstractTableModel()
    {
        iconNormal = QIcon(":/images/user-normal.png");
        iconOp= QIcon(":/images/user-normal-op.png");
        iconDcpp= QIcon(":/images/user-dcpp.png");
        iconDcppOp= QIcon(":/images/user-dcpp-op.png");
        iconDcppPassive= QIcon(":/images/user-dcpp-passive.png");
        iconPassive= QIcon(":/images/user-passive.png");
        iconPassiveOp= QIcon(":/images/user-passive-op.png");
        iconDcppPassiveOp= QIcon(":/images/user-dcpp-passive-op.png");
        updateSignals = true;
    }
    ~UserListModel()
    {}

    // QAbstractTableModel methods...
    int rowCount ( const QModelIndex& ) const
    {
        //return userIndexMap.size();
        return users.size();
    }
    int columnCount ( const QModelIndex& ) const
    {
        return 3;        // Nick, share, description
    }
    QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
    QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;

    User* getUser(const QModelIndex& i)
    {
        return users[i.row()];
    }

    void setUser(User*);
    User* getUser(int userId)
    {
        return userIdMap.value(userId);
    }
    void removeUser(int userId);
    void sort(int col,Qt::SortOrder order = Qt::AscendingOrder);

    //! Used to turn of emission of the layoutchanhed signal, default true.
    void enableUpdateSignals(bool yes)
    {
        updateSignals=yes;
    }

    void signalLayoutChanged()
    {
        emit layoutChanged();
    }

protected:
    bool updateSignals;
    QHash<int,User*> userIdMap;
    QList<User*> users;
    QIcon iconNormal,iconOp,iconDcpp,iconDcppOp,iconDcppPassive,iconPassive,iconPassiveOp,iconDcppPassiveOp;
};



#endif