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_qstatetreemodel.h"
27 #include "vogleditor_statetreeitem.h"
28 #include "vogleditor_statetreecontextitem.h"
30 #include "vogl_sync_object.h"
32 //===============================================
34 vogleditor_QStateTreeModel::vogleditor_QStateTreeModel( QObject* parent)
35 : QAbstractItemModel(parent),
37 m_pBaseSnapshot(NULL),
38 m_pCurrentContextItem(NULL)
40 m_ColumnTitles << "State";
41 m_ColumnTitles << "Value";
43 m_rootItem = new vogleditor_stateTreeItem(m_ColumnTitles, this);
46 void vogleditor_QStateTreeModel::set_snapshot(vogleditor_gl_state_snapshot *pSnapshot)
48 m_pSnapshot = pSnapshot;
49 setupModelData(m_pSnapshot, m_rootItem);
52 vogleditor_QStateTreeModel::vogleditor_QStateTreeModel(vogleditor_gl_state_snapshot* pSnapshot, QObject* parent)
53 : QAbstractItemModel(parent),
54 m_pSnapshot(pSnapshot),
57 m_ColumnTitles << "State";
58 m_ColumnTitles << "Value";
60 m_rootItem = new vogleditor_stateTreeItem(m_ColumnTitles, this);
61 setupModelData(m_pSnapshot, m_rootItem);
64 vogleditor_QStateTreeModel::~vogleditor_QStateTreeModel()
66 if (m_rootItem != NULL)
73 QModelIndex vogleditor_QStateTreeModel::index(int row, int column, const QModelIndex& parent) const
75 if (!hasIndex(row, column, parent))
78 vogleditor_stateTreeItem *parentItem;
80 if (!parent.isValid())
81 parentItem = m_rootItem;
83 parentItem = static_cast<vogleditor_stateTreeItem*>(parent.internalPointer());
85 vogleditor_stateTreeItem *childItem = parentItem->child(row);
87 return createIndex(row, column, childItem);
92 QModelIndex vogleditor_QStateTreeModel::parent(const QModelIndex& child) const
97 vogleditor_stateTreeItem* childItem = static_cast<vogleditor_stateTreeItem*>(child.internalPointer());
98 vogleditor_stateTreeItem* parentItem = childItem->parent();
100 if (parentItem == m_rootItem)
101 return QModelIndex();
103 return createIndex(parentItem->row(), 0, parentItem);
106 int vogleditor_QStateTreeModel::rowCount(const QModelIndex& parent) const
108 vogleditor_stateTreeItem* parentItem;
109 if (parent.column() > 0)
112 if (!parent.isValid())
113 parentItem = m_rootItem;
115 parentItem = static_cast<vogleditor_stateTreeItem*>(parent.internalPointer());
117 return parentItem->childCount();
120 int vogleditor_QStateTreeModel::columnCount(const QModelIndex& parent) const
122 VOGL_NOTE_UNUSED(parent);
123 return m_ColumnTitles.size();
126 QVariant vogleditor_QStateTreeModel::data(const QModelIndex& index, int role) const
128 if (!index.isValid())
131 vogleditor_stateTreeItem *item = static_cast<vogleditor_stateTreeItem*>(index.internalPointer());
133 return item->columnData(index.column(), role);
136 QVariant vogleditor_QStateTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
138 if (orientation == Qt::Horizontal)
139 return m_rootItem->columnData(section, role);
144 vogleditor_stateTreeItem* vogleditor_QStateTreeModel::root() const
149 vogleditor_gl_state_snapshot* vogleditor_QStateTreeModel::get_snapshot() const
154 void vogleditor_QStateTreeModel::set_diff_base_snapshot(const vogleditor_gl_state_snapshot *pDiffBaseSnapshot)
156 m_pBaseSnapshot = pDiffBaseSnapshot;
159 void vogleditor_QStateTreeModel::setupModelData(vogleditor_gl_state_snapshot* pSnapshot, vogleditor_stateTreeItem* parent)
163 vogl_context_snapshot_ptr_vec contexts = pSnapshot->get_contexts();
164 for (uint c = 0; c < contexts.size(); c++)
166 vogl_context_snapshot* pContext = contexts[c];
168 const vogl_context_desc& desc = pContext->get_context_desc();
169 vogleditor_stateTreeContextItem* pContextItem = new vogleditor_stateTreeContextItem(tmp.sprintf("Context %p", (void*)desc.get_trace_context()), "", parent, *pContext);
170 if (m_pBaseSnapshot != NULL && m_pBaseSnapshot->is_valid() && m_pBaseSnapshot->get_contexts().size() > 0 && m_pBaseSnapshot->get_contexts().at(c) != NULL)
172 // set the diff state to be the same state, so that there does not appear to be any diff's
173 const vogl_context_snapshot* pDiffContext = m_pBaseSnapshot->get_contexts()[c];
174 pContextItem->set_diff_base_state(pDiffContext);
176 // if this is the current context, store it
177 if (pContext->get_context_desc().get_trace_context() == pSnapshot->get_cur_trace_context())
179 m_pCurrentContextItem = pContextItem;
183 parent->appendChild(pContextItem);
187 vogl::vector<vogleditor_stateTreeProgramItem*> vogleditor_QStateTreeModel::get_program_objects()
189 vogl::vector<vogleditor_stateTreeProgramItem*> programs;
190 if (m_pCurrentContextItem != NULL)
192 programs = m_pCurrentContextItem->get_program_objects();