]> sigrok.org Git - pulseview.git/blob - pv/subwindows/decoder_selector/item.cpp
Fix #1309 by adding a PD info box
[pulseview.git] / pv / subwindows / decoder_selector / item.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2018 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 "subwindow.hpp"
21
22 using std::out_of_range;
23
24 namespace pv {
25 namespace subwindows {
26 namespace decoder_selector {
27
28 DecoderCollectionItem::DecoderCollectionItem(const vector<QVariant>& data,
29         shared_ptr<DecoderCollectionItem> parent) :
30         data_(data),
31         parent_(parent)
32 {
33 }
34
35 void DecoderCollectionItem::appendSubItem(shared_ptr<DecoderCollectionItem> item)
36 {
37         subItems_.push_back(item);
38 }
39
40 shared_ptr<DecoderCollectionItem> DecoderCollectionItem::subItem(int row) const
41 {
42         try {
43                 return subItems_.at(row);
44         } catch (out_of_range) {
45                 return nullptr;
46         }
47 }
48
49 shared_ptr<DecoderCollectionItem> DecoderCollectionItem::parent() const
50 {
51         return parent_;
52 }
53
54 shared_ptr<DecoderCollectionItem> DecoderCollectionItem::findSubItem(
55         const QVariant& value, int column)
56 {
57         for (shared_ptr<DecoderCollectionItem> item : subItems_)
58                 if (item->data(column) == value)
59                         return item;
60
61         return nullptr;
62 }
63
64 int DecoderCollectionItem::subItemCount() const
65 {
66         return subItems_.size();
67 }
68
69 int DecoderCollectionItem::columnCount() const
70 {
71         return data_.size();
72 }
73
74 int DecoderCollectionItem::row() const
75 {
76         if (parent_)
77                 for (uint i = 0; i < parent_->subItems_.size(); i++)
78                         if (parent_->subItems_.at(i).get() == const_cast<DecoderCollectionItem*>(this))
79                                 return i;
80
81         return 0;
82 }
83
84 QVariant DecoderCollectionItem::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 decoder_selector
94 } // namespace subwindows
95 } // namespace pv