OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [java/] [src/] [edu/] [byu/] [cc/] [plieber/] [fpgaenet/] [examples/] [NetValueModel.java] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
/**
2
 *
3
 */
4
package edu.byu.cc.plieber.fpgaenet.examples;
5
 
6
import java.util.ArrayList;
7
 
8
import com.trolltech.qt.core.QModelIndex;
9
import com.trolltech.qt.core.Qt.ItemDataRole;
10
import com.trolltech.qt.core.Qt.ItemFlag;
11
import com.trolltech.qt.core.Qt.ItemFlags;
12
import com.trolltech.qt.core.Qt.Orientation;
13
import com.trolltech.qt.gui.QAbstractTableModel;
14
 
15
import edu.byu.cc.plieber.fpgaenet.debug.IcapReadback;
16
import edu.byu.cc.plieber.fpgaenet.debug.llparse.LatchRBEntry;
17
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
18
 
19
/**
20
 * @author Peter Lieber
21
 *
22
 */
23
public class NetValueModel extends QAbstractTableModel {
24
 
25
        ArrayList<LatchRBEntry> netList;
26
        ArrayList<String> netValueList;
27
        private IcapReadback icapReadback;
28
 
29
        public NetValueModel(ArrayList<LatchRBEntry> entries, IcapReadback icapRB) {
30
                netList = entries;
31
                icapReadback = icapRB;
32
                netValueList = new ArrayList<String>();
33
                for (int i=0; i<netList.size(); i++) {
34
                        netValueList.add("<invalid>");
35
                }
36
        }
37
 
38
        public void replaceContents(ArrayList<LatchRBEntry> entries) {
39
                beginRemoveRows(null, 0, netList.size()-1);
40
                netList.clear();
41
                endRemoveRows();
42
                beginInsertRows(null, 0, entries.size()-1);
43
                netList = entries;
44
                netValueList = new ArrayList<String>();
45
                for (int i=0; i<netList.size(); i++) {
46
                        netValueList.add("<invalid>");
47
                }
48
                endInsertRows();
49
        }
50
 
51
        /* (non-Javadoc)
52
         * @see com.trolltech.qt.core.QAbstractItemModel#columnCount(com.trolltech.qt.core.QModelIndex)
53
         */
54
        @Override
55
        public int columnCount(QModelIndex arg0) {
56
                return 2;
57
        }
58
 
59
        /* (non-Javadoc)
60
         * @see com.trolltech.qt.core.QAbstractItemModel#data(com.trolltech.qt.core.QModelIndex, int)
61
         */
62
        @Override
63
        public Object data(QModelIndex index, int role) {
64
                if (role != ItemDataRole.DisplayRole)
65
                        return null;
66
                switch (index.column()) {
67
                case 0:
68
                        return netList.get(index.row()).getFullName();
69
                case 1:
70
                        return netValueList.get(index.row());
71
                default:
72
                        break;
73
                }
74
                return null;
75
        }
76
 
77
        /* (non-Javadoc)
78
         * @see com.trolltech.qt.core.QAbstractItemModel#rowCount(com.trolltech.qt.core.QModelIndex)
79
         */
80
        @Override
81
        public int rowCount(QModelIndex parent) {
82
                return netList.size();
83
        }
84
 
85
        @Override
86
        public Object headerData(int section, Orientation orientation, int role) {
87
                if (role != ItemDataRole.DisplayRole)
88
                        return null;
89
                else if (orientation == Orientation.Vertical) return "";
90
                switch (section) {
91
                case 0:
92
                        return "Name";
93
                case 1:
94
                        return "Value";
95
                default:
96
                        break;
97
                }
98
                return null;
99
        }
100
 
101
        public LatchRBEntry getEntry(QModelIndex index) {
102
                return netList.get(index.row());
103
        }
104
 
105
        public void updateValues() throws FCPException {
106
                for (int i=0; i<netList.size(); i++) {
107
                        LatchRBEntry entry = netList.get(i);
108
                        if ( entry != null) {
109
                                 netValueList.set(i, String.valueOf(icapReadback.readState(entry)));
110
                        }
111
                }
112
                dataChanged.emit(index(0, 0, null), index(netList.size(), 0, null));
113
        }
114
}

powered by: WebSVN 2.1.0

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