X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;ds=sidebyside;f=pv%2Fsubwindows%2Fdecoder_selector%2Fitem.cpp;fp=pv%2Fsubwindows%2Fdecoder_selector%2Fitem.cpp;h=00c469e062ceaea8f1c1a1e4a456ce6276aabad1;hb=97378470ded88af84edaa0f1063d10d834475665;hp=0000000000000000000000000000000000000000;hpb=58cd5b584f5bcb19d7c9bd28391c53dd2488fc59;p=pulseview.git diff --git a/pv/subwindows/decoder_selector/item.cpp b/pv/subwindows/decoder_selector/item.cpp new file mode 100644 index 0000000..00c469e --- /dev/null +++ b/pv/subwindows/decoder_selector/item.cpp @@ -0,0 +1,95 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2018 Soeren Apel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "subwindow.hpp" + +using std::out_of_range; + +namespace pv { +namespace subwindows { +namespace decoder_selector { + +DecoderCollectionItem::DecoderCollectionItem(const vector& data, + shared_ptr parent) : + data_(data), + parent_(parent) +{ +} + +void DecoderCollectionItem::appendSubItem(shared_ptr item) +{ + subItems_.push_back(item); +} + +shared_ptr DecoderCollectionItem::subItem(int row) const +{ + try { + return subItems_.at(row); + } catch (out_of_range) { + return nullptr; + } +} + +shared_ptr DecoderCollectionItem::parent() const +{ + return parent_; +} + +shared_ptr DecoderCollectionItem::findSubItem( + const QVariant& value, int column) +{ + for (shared_ptr item : subItems_) + if (item->data(column) == value) + return item; + + return nullptr; +} + +int DecoderCollectionItem::subItemCount() const +{ + return subItems_.size(); +} + +int DecoderCollectionItem::columnCount() const +{ + return data_.size(); +} + +int DecoderCollectionItem::row() const +{ + if (parent_) + for (uint i = 0; i < parent_->subItems_.size(); i++) + if (parent_->subItems_.at(i).get() == const_cast(this)) + return i; + + return 0; +} + +QVariant DecoderCollectionItem::data(int column) const +{ + try { + return data_.at(column); + } catch (out_of_range) { + return QVariant(); + } +} + +} // namespace decoder_selector +} // namespace subwindows +} // namespace pv