OpenCores
URL https://opencores.org/ocsvn/ezidebug/ezidebug/trunk

Subversion Repositories ezidebug

[/] [ezidebug/] [trunk/] [EziDebug_src/] [ezidebugtreemodel.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 EziDebug
#include <QString>
2
#include <QList>
3
#include <QDebug>
4
#include <QFileIconProvider>
5
#include "ezidebuginstancetreeitem.h"
6
#include "ezidebugtreemodel.h"
7
 
8
 
9
EziDebugTreeModel::EziDebugTreeModel(EziDebugInstanceTreeItem* item, QObject *parent)\
10
    :QAbstractItemModel(parent)
11
{
12
    m_pinstanceTopItem = item ;
13
    m_pheadItem = new EziDebugInstanceTreeItem("module","instance");
14
    m_pheadItem->setItemParent(NULL);
15
    m_pheadItem->appendChild(m_pinstanceTopItem);
16
 
17
    m_pinstanceTopItem->setItemParent(m_pheadItem);
18
 
19
}
20
 
21
 
22
EziDebugTreeModel::~EziDebugTreeModel()
23
{
24
    if(m_pheadItem)
25
        delete m_pheadItem ;
26
    m_pheadItem = NULL ;
27
}
28
 
29
QVariant EziDebugTreeModel::data(const QModelIndex &index, int role) const
30
{
31
 
32
    QIcon iexistChainIcon(tr(":/images/yeschain.png"));
33
    QIcon inoChainIcon(tr(":/images/nochain.png"));
34
 
35
 
36
    EziDebugInstanceTreeItem* pparentItem = static_cast<EziDebugInstanceTreeItem*>(index.internalPointer());
37
 
38
    // index 无效 则返回 QVariant()
39
    if (!index.isValid())
40
        return QVariant();
41
    //
42
    if (role == Qt::DisplayRole)
43
    {
44
        return (pparentItem->getNameData());
45
    }
46
 
47
    if (role == Qt::DecorationRole)
48
    {
49
        if (index.column() == 0)
50
        {
51
            if(pparentItem->getScanChainInfo())
52
                return iexistChainIcon ;
53
            else
54
                return inoChainIcon ;
55
        }
56
            //return iconProvider.icon(QFileIconProvider::Folder);
57
       // return iconProvider.icon(QFileIconProvider::File);
58
    }
59
    return QVariant();
60
}
61
 
62
Qt::ItemFlags EziDebugTreeModel::flags(const QModelIndex &index) const
63
{
64
    if (!index.isValid())
65
        return 0;
66
 
67
    return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
68
}
69
 
70
QVariant EziDebugTreeModel::headerData(int section, Qt::Orientation orientation, \
71
                    int role) const
72
{
73
    QString iheadData = "Node Tree" ;
74
    if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
75
        return iheadData ;
76
 
77
    return QVariant();
78
}
79
 
80
// 获得 parent 的 row 行 column 列 的 modelIndex
81
QModelIndex EziDebugTreeModel::index(int row, int column, const QModelIndex &parent) const
82
{
83
    //如果行列在允许范围之内
84
    if(!hasIndex(row, column, parent))
85
    {
86
      return QModelIndex();
87
    }
88
 
89
    EziDebugInstanceTreeItem * pparentItem;
90
 
91
    if (!parent.isValid())
92
        //return QModelIndex();
93
        pparentItem = m_pheadItem ;
94
    else
95
        pparentItem = static_cast<EziDebugInstanceTreeItem*>(parent.internalPointer());
96
 
97
    EziDebugInstanceTreeItem *pchildItem = pparentItem->child(row);
98
    // qDebug() << pchildItem << "first" << column ;
99
    //qDebug() << pchildItem << row << column << pparentItem;
100
    //qDebug() << QObject::tr("创建index") << QObject::tr("行数") << row;
101
 
102
    //qDebug() << "index" << pchildItem->getModuleName() << pchildItem->getInstanceName()  ;
103
    if (pchildItem)
104
        return createIndex(row, column, pchildItem);
105
    else
106
        return QModelIndex();
107
 
108
}
109
 
110
// 根据 child 的 modelIndex 获取  parent 的 modelIndex
111
QModelIndex EziDebugTreeModel::parent(const QModelIndex &child) const
112
{
113
    //qDebug() << "parent" << __LINE__  ;
114
    if(child.isValid())
115
    {
116
        EziDebugInstanceTreeItem *pchildItem = static_cast<EziDebugInstanceTreeItem*>(child.internalPointer());
117
 
118
        EziDebugInstanceTreeItem *pparentItem = pchildItem->parent();
119
        // qDebug() << pchildItem << "result" << child.row() << child.column();
120
 
121
        if (pparentItem == m_pheadItem)
122
        {
123
            return QModelIndex();
124
        }
125
        else
126
        {
127
            //  return createIndex(0, 0, pparentItem);
128
            //qDebug() << "parent" <<  pparentItem->row() ;
129
            return createIndex(pparentItem->row(), 0, pparentItem);
130
        }
131
    }
132
    return QModelIndex();
133
}
134
 
135
// 父节点下面有多少行
136
int EziDebugTreeModel::rowCount(const QModelIndex &parent) const
137
{
138
    //qDebug() << "rowCount" << __LINE__  ;
139
    EziDebugInstanceTreeItem *pparentItem;
140
    if (parent.column() > 1)
141
        return 0 ;
142
 
143
    if (!parent.isValid())
144
        pparentItem = m_pheadItem ;
145
    else
146
        pparentItem = static_cast<EziDebugInstanceTreeItem*>(parent.internalPointer());
147
    //qDebug() << QObject::tr("获取节点下面多少行") << pparentItem->getModuleName() << pparentItem->childCount() ;
148
    return pparentItem->childCount();
149
}
150
 
151
int EziDebugTreeModel::columnCount(const QModelIndex &parent) const
152
{
153
    if (parent.isValid())
154
        return 1 ;
155
    else
156
        return 1 ;
157
 
158
}
159
 
160
EziDebugInstanceTreeItem* EziDebugTreeModel::getInstanceTreeRootItem(void)
161
{
162
    return m_pinstanceTopItem ;
163
}
164
 
165
void  EziDebugTreeModel::setInstanceTreeRootItem(EziDebugInstanceTreeItem* item)
166
{
167
    m_pheadItem->removeChild(m_pinstanceTopItem);
168
 
169
    m_pinstanceTopItem = item ;
170
 
171
    m_pheadItem->appendChild(m_pinstanceTopItem);
172
 
173
    m_pinstanceTopItem->setItemParent(m_pheadItem);
174
 
175
    return ;
176
}
177
 
178
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.