1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 **************************************************************************/
26 #include "vogleditor_qapicalltreemodel.h"
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"
34 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(vogleditor_QApiCallTreeModel* pModel)
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)";
48 // Constructor for frame nodes
49 vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(vogleditor_frameItem* frameItem, vogleditor_apiCallTreeItem* parent)
50 : m_parentItem(parent),
52 m_pFrameItem(frameItem),
55 if (frameItem != NULL)
58 tmp.sprintf("Frame %" PRIu64, frameItem->frameNumber());
59 m_columnData[VOGL_ACTC_APICALL] = tmp;
62 if (m_parentItem != NULL)
64 m_pModel = m_parentItem->m_pModel;
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),
75 m_columnData[VOGL_ACTC_APICALL] = nodeText;
77 if (apiCallItem != NULL)
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();
86 if (m_parentItem != NULL)
88 m_pModel = m_parentItem->m_pModel;
92 vogleditor_apiCallTreeItem::~vogleditor_apiCallTreeItem()
94 if (m_pFrameItem != NULL)
100 if (m_pApiCallItem != NULL)
102 delete m_pApiCallItem;
103 m_pApiCallItem = NULL;
106 for (int i = 0; i < m_childItems.size(); i++)
108 delete m_childItems[i];
109 m_childItems[i] = NULL;
112 m_childItems.clear();
115 vogleditor_apiCallTreeItem* vogleditor_apiCallTreeItem::parent() const
120 void vogleditor_apiCallTreeItem::appendChild(vogleditor_apiCallTreeItem* pChild)
122 m_childItems.append(pChild);
125 int vogleditor_apiCallTreeItem::childCount() const
127 return m_childItems.size();
130 vogleditor_apiCallTreeItem* vogleditor_apiCallTreeItem::child(int index) const
132 if (index < 0 || index >= childCount())
137 return m_childItems[index];
140 vogleditor_apiCallItem* vogleditor_apiCallTreeItem::apiCallItem() const
142 return m_pApiCallItem;
145 vogleditor_frameItem* vogleditor_apiCallTreeItem::frameItem() const
150 void vogleditor_apiCallTreeItem::set_snapshot(vogleditor_gl_state_snapshot* pSnapshot)
154 m_pFrameItem->set_snapshot(pSnapshot);
159 m_pApiCallItem->set_snapshot(pSnapshot);
163 bool vogleditor_apiCallTreeItem::has_snapshot() const
165 bool bHasSnapshot = false;
168 bHasSnapshot = m_pFrameItem->has_snapshot();
173 bHasSnapshot = m_pApiCallItem->has_snapshot();
178 vogleditor_gl_state_snapshot* vogleditor_apiCallTreeItem::get_snapshot() const
180 vogleditor_gl_state_snapshot* pSnapshot = NULL;
183 pSnapshot = m_pFrameItem->get_snapshot();
188 pSnapshot = m_pApiCallItem->get_snapshot();
193 int vogleditor_apiCallTreeItem::columnCount() const
196 if (m_parentItem == NULL)
198 count = VOGL_MAX_ACTC;
202 m_pModel->columnCount();
208 QVariant vogleditor_apiCallTreeItem::columnData(int column, int role) const
210 if (column >= VOGL_MAX_ACTC)
215 if (role == Qt::DecorationRole)
218 if (column == VOGL_ACTC_FLAGS)
222 if (get_snapshot()->is_outdated())
224 // snapshot was dirtied due to an earlier edit
225 return QColor(200, 0, 0);
227 else if (get_snapshot()->is_edited())
229 // snapshot has been edited
230 return QColor(200, 102, 0);
235 return QColor(0, 0, 255);
241 if (role == Qt::DisplayRole)
243 return m_columnData[column];
249 int vogleditor_apiCallTreeItem::row() const
251 // note, this is just the row within the current level of the hierarchy
253 return m_parentItem->m_childItems.indexOf(const_cast<vogleditor_apiCallTreeItem*>(this));