]> git.cworth.org Git - vogl/blob - src/vogleditor/vogleditor_apicalltreeitem.cpp
5a66db872469cf72c62274e22df61680664cfbf2
[vogl] / src / vogleditor / vogleditor_apicalltreeitem.cpp
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 #include "vogleditor_qapicalltreemodel.h"
27
28 #include "vogl_common.h"
29 #include "vogl_trace_file_reader.h"
30 #include "vogl_trace_packet.h"
31 #include "vogl_trace_stream_types.h"
32 #include "vogleditor_gl_state_snapshot.h"
33
34 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(vogleditor_QApiCallTreeModel* pModel)
35  : m_parentItem(NULL),
36    m_pApiCallItem(NULL),
37    m_pFrameItem(NULL),
38    m_pModel(pModel)
39 {
40     m_columnData[VOGL_ACTC_APICALL] = "API Call";
41     m_columnData[VOGL_ACTC_INDEX] = "Index";
42     m_columnData[VOGL_ACTC_FLAGS] = "";
43     //m_ColumnTitles[VOGL_ACTC_BEGINTIME] = "Begin Time";
44     //m_ColumnTitles[VOGL_ACTC_ENDTIME] = "End Time";
45     m_columnData[VOGL_ACTC_DURATION] = "Duration (ns)";
46 }
47
48 // Constructor for frame nodes
49 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(vogleditor_frameItem* frameItem, vogleditor_apiCallTreeItem* parent)
50  : m_parentItem(parent),
51    m_pApiCallItem(NULL),
52    m_pFrameItem(frameItem),
53    m_pModel(NULL)
54 {
55    if (frameItem != NULL)
56    {
57       QString tmp;
58       tmp.sprintf("Frame %" PRIu64, frameItem->frameNumber());
59       m_columnData[VOGL_ACTC_APICALL] = tmp;
60    }
61
62    if (m_parentItem != NULL)
63    {
64       m_pModel = m_parentItem->m_pModel;
65    }
66 }
67
68 // Constructor for apiCall nodes
69 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(QString nodeText, vogleditor_apiCallItem* apiCallItem, vogleditor_apiCallTreeItem* parent)
70  : m_parentItem(parent),
71    m_pApiCallItem(apiCallItem),
72    m_pFrameItem(NULL),
73    m_pModel(NULL)
74 {
75    m_columnData[VOGL_ACTC_APICALL] = nodeText;
76
77    if (apiCallItem != NULL)
78    {
79       m_columnData[VOGL_ACTC_INDEX] = (qulonglong)apiCallItem->globalCallIndex();
80       m_columnData[VOGL_ACTC_FLAGS] = "";
81       //m_columnData[VOGL_ACTC_BEGINTIME] = apiCallItem->startTime();
82       //m_columnData[VOGL_ACTC_ENDTIME] = apiCallItem->endTime();
83       m_columnData[VOGL_ACTC_DURATION] = (qulonglong)apiCallItem->duration();
84    }
85
86    if (m_parentItem != NULL)
87    {
88       m_pModel = m_parentItem->m_pModel;
89    }
90 }
91
92 vogleditor_apiCallTreeItem::~vogleditor_apiCallTreeItem()
93 {
94    if (m_pFrameItem != NULL)
95    {
96       delete m_pFrameItem;
97       m_pFrameItem = NULL;
98    }
99
100    if (m_pApiCallItem != NULL)
101    {
102       delete m_pApiCallItem;
103       m_pApiCallItem = NULL;
104    }
105
106    for (int i = 0; i < m_childItems.size(); i++)
107    {
108       delete m_childItems[i];
109       m_childItems[i] = NULL;
110    }
111
112    m_childItems.clear();
113 }
114
115 vogleditor_apiCallTreeItem* vogleditor_apiCallTreeItem::parent() const
116 {
117    return m_parentItem;
118 }
119
120 void vogleditor_apiCallTreeItem::appendChild(vogleditor_apiCallTreeItem* pChild)
121 {
122    m_childItems.append(pChild);
123 }
124
125 int vogleditor_apiCallTreeItem::childCount() const
126 {
127    return m_childItems.size();
128 }
129
130 vogleditor_apiCallTreeItem* vogleditor_apiCallTreeItem::child(int index) const
131 {
132    if (index < 0 || index >= childCount())
133    {
134       return NULL;
135    }
136
137    return m_childItems[index];
138 }
139
140 vogleditor_apiCallItem* vogleditor_apiCallTreeItem::apiCallItem() const
141 {
142    return m_pApiCallItem;
143 }
144
145 vogleditor_frameItem* vogleditor_apiCallTreeItem::frameItem() const
146 {
147    return m_pFrameItem;
148 }
149
150 void vogleditor_apiCallTreeItem::set_snapshot(vogleditor_gl_state_snapshot* pSnapshot)
151 {
152     if (m_pFrameItem)
153     {
154         m_pFrameItem->set_snapshot(pSnapshot);
155     }
156
157     if (m_pApiCallItem)
158     {
159         m_pApiCallItem->set_snapshot(pSnapshot);
160     }
161 }
162
163 bool vogleditor_apiCallTreeItem::has_snapshot() const
164 {
165     bool bHasSnapshot = false;
166     if (m_pFrameItem)
167     {
168         bHasSnapshot = m_pFrameItem->has_snapshot();
169     }
170
171     if (m_pApiCallItem)
172     {
173         bHasSnapshot = m_pApiCallItem->has_snapshot();
174     }
175     return bHasSnapshot;
176 }
177
178 vogleditor_gl_state_snapshot* vogleditor_apiCallTreeItem::get_snapshot() const
179 {
180     vogleditor_gl_state_snapshot* pSnapshot = NULL;
181     if (m_pFrameItem)
182     {
183         pSnapshot = m_pFrameItem->get_snapshot();
184     }
185
186     if (m_pApiCallItem)
187     {
188         pSnapshot = m_pApiCallItem->get_snapshot();
189     }
190     return pSnapshot;
191 }
192
193 int vogleditor_apiCallTreeItem::columnCount() const
194 {
195    int count = 0;
196    if (m_parentItem == NULL)
197    {
198       count = VOGL_MAX_ACTC;
199    }
200    else
201    {
202       m_pModel->columnCount();
203    }
204
205    return count;
206 }
207
208 QVariant vogleditor_apiCallTreeItem::columnData(int column, int role) const
209 {
210    if (column >= VOGL_MAX_ACTC)
211    {
212       return QVariant();
213    }
214
215    if (role == Qt::DecorationRole)
216    {
217        // handle flags
218        if (column == VOGL_ACTC_FLAGS)
219        {
220            if (has_snapshot())
221            {
222                if (get_snapshot()->is_outdated())
223                {
224                    // snapshot was dirtied due to an earlier edit
225                    return QColor(200, 0, 0);
226                }
227                else if (get_snapshot()->is_edited())
228                {
229                    // snapshot has been edited
230                    return QColor(200, 102, 0);
231                }
232                else
233                {
234                    // snapshot is good
235                    return QColor(0, 0, 255);
236                }
237            }
238        }
239    }
240
241    if (role == Qt::DisplayRole)
242    {
243        return m_columnData[column];
244    }
245
246    return QVariant();
247 }
248
249 int vogleditor_apiCallTreeItem::row() const
250 {
251    // note, this is just the row within the current level of the hierarchy
252    if (m_parentItem)
253       return m_parentItem->m_childItems.indexOf(const_cast<vogleditor_apiCallTreeItem*>(this));
254
255    return 0;
256 }