]> sigrok.org Git - pulseview.git/blame - pv/views/tabular_decoder/item.cpp
Add tabular decoder view
[pulseview.git] / pv / views / tabular_decoder / item.cpp
CommitLineData
24d69d27
SA
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2020 Soeren Apel <soeren@apelpie.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "pv/views/tabular_decoder/view.hpp"
21
22using std::out_of_range;
23
24namespace pv {
25namespace views {
26namespace tabular_decoder {
27
28AnnotationCollectionItem::AnnotationCollectionItem(const vector<QVariant>& data,
29 shared_ptr<AnnotationCollectionItem> parent) :
30 data_(data),
31 parent_(parent)
32{
33}
34
35void AnnotationCollectionItem::appendSubItem(shared_ptr<AnnotationCollectionItem> item)
36{
37 subItems_.push_back(item);
38}
39
40shared_ptr<AnnotationCollectionItem> AnnotationCollectionItem::subItem(int row) const
41{
42 try {
43 return subItems_.at(row);
44 } catch (out_of_range&) {
45 return nullptr;
46 }
47}
48
49shared_ptr<AnnotationCollectionItem> AnnotationCollectionItem::parent() const
50{
51 return parent_;
52}
53
54shared_ptr<AnnotationCollectionItem> AnnotationCollectionItem::findSubItem(
55 const QVariant& value, int column)
56{
57 for (shared_ptr<AnnotationCollectionItem> item : subItems_)
58 if (item->data(column) == value)
59 return item;
60
61 return nullptr;
62}
63
64int AnnotationCollectionItem::subItemCount() const
65{
66 return subItems_.size();
67}
68
69int AnnotationCollectionItem::columnCount() const
70{
71 return data_.size();
72}
73
74int AnnotationCollectionItem::row() const
75{
76 if (parent_)
77 for (size_t i = 0; i < parent_->subItems_.size(); i++)
78 if (parent_->subItems_.at(i).get() == const_cast<AnnotationCollectionItem*>(this))
79 return i;
80
81 return 0;
82}
83
84QVariant AnnotationCollectionItem::data(int column) const
85{
86 try {
87 return data_.at(column);
88 } catch (out_of_range&) {
89 return QVariant();
90 }
91}
92
93} // namespace tabular_decoder
94} // namespace views
95} // namespace pv