PulseView  unreleased development snapshot
A Qt-based sigrok GUI
item.cpp
Go to the documentation of this file.
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 
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 
65 {
66  return subItems_.size();
67 }
68 
70 {
71  return data_.size();
72 }
73 
75 {
76  if (parent_)
77  for (size_t 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
shared_ptr< DecoderCollectionItem > findSubItem(const QVariant &value, int column)
Definition: item.cpp:54
vector< shared_ptr< DecoderCollectionItem > > subItems_
Definition: subwindow.hpp:57
T value(details::expression_node< T > *n)
Definition: exprtk.hpp:12358
shared_ptr< DecoderCollectionItem > parent() const
Definition: item.cpp:49
DecoderCollectionItem(const vector< QVariant > &data, shared_ptr< DecoderCollectionItem > parent=nullptr)
Definition: item.cpp:28
static std::string data()
Definition: exprtk.hpp:39024
shared_ptr< DecoderCollectionItem > parent_
Definition: subwindow.hpp:59
shared_ptr< DecoderCollectionItem > subItem(int row) const
Definition: item.cpp:40
void appendSubItem(shared_ptr< DecoderCollectionItem > item)
Definition: item.cpp:35