24 #include <libsigrokdecode/libsigrokdecode.h> 26 #define DECODERS_HAVE_TAGS \ 27 ((SRD_PACKAGE_VERSION_MAJOR > 0) || \ 28 (SRD_PACKAGE_VERSION_MAJOR == 0) && (SRD_PACKAGE_VERSION_MINOR > 5)) 30 using std::make_shared;
33 namespace subwindows {
34 namespace decoder_selector {
39 vector<QVariant> header_data;
40 header_data.emplace_back(tr(
"Decoder"));
41 header_data.emplace_back(tr(
"Name"));
42 header_data.emplace_back(tr(
"ID"));
43 root_ = make_shared<DecoderCollectionItem>(header_data);
48 vector<QVariant> item_data;
49 item_data.emplace_back(tr(
"All Decoders"));
52 item_data.emplace_back();
53 item_data.emplace_back();
54 shared_ptr<DecoderCollectionItem> group_item_all =
55 make_shared<DecoderCollectionItem>(item_data,
root_);
56 root_->appendSubItem(group_item_all);
58 for (GSList* li = (GSList*)srd_decoder_list(); li; li = li->next) {
59 const srd_decoder *
const d = (srd_decoder*)li->data;
62 const QString
id = QString::fromUtf8(d->id);
63 const QString name = QString::fromUtf8(d->name);
64 const QString long_name = QString::fromUtf8(d->longname);
68 item_data.emplace_back(name);
69 item_data.emplace_back(long_name);
70 item_data.emplace_back(
id);
71 shared_ptr<DecoderCollectionItem> decoder_item_all =
72 make_shared<DecoderCollectionItem>(item_data, group_item_all);
73 group_item_all->appendSubItem(decoder_item_all);
76 #if DECODERS_HAVE_TAGS 77 for (GSList* ti = (GSList*)d->tags; ti; ti = ti->next) {
78 const QString tag = tr((
char*)ti->data);
79 const QVariant tag_var = QVariant(tag);
82 shared_ptr<DecoderCollectionItem> group_item =
83 root_->findSubItem(tag_var, 0);
87 item_data.emplace_back(tag);
90 item_data.emplace_back();
91 item_data.emplace_back();
92 group_item = make_shared<DecoderCollectionItem>(item_data,
root_);
93 root_->appendSubItem(group_item);
98 item_data.emplace_back(name);
99 item_data.emplace_back(long_name);
100 item_data.emplace_back(
id);
101 shared_ptr<DecoderCollectionItem> decoder_item =
102 make_shared<DecoderCollectionItem>(item_data, group_item);
105 group_item->appendSubItem(decoder_item);
113 if (!index.isValid())
116 if (role == Qt::DisplayRole)
121 return item->
data(index.column());
124 if ((role == Qt::FontRole) && (index.parent().isValid()) && (index.column() == 0))
127 font.setItalic(
true);
128 return QVariant(font);
136 if (!index.isValid())
137 return Qt::NoItemFlags;
139 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
145 if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole))
146 return root_->data(section);
152 const QModelIndex& parent_idx)
const 154 if (!hasIndex(row, column, parent_idx))
155 return QModelIndex();
159 if (parent_idx.isValid())
160 parent = static_cast<DecoderCollectionItem*>(parent_idx.internalPointer());
164 return subItem ? createIndex(row, column, subItem) : QModelIndex();
169 if (!index.isValid())
170 return QModelIndex();
175 shared_ptr<DecoderCollectionItem>
parent = subItem->
parent();
177 return (parent ==
root_) ? QModelIndex() :
178 createIndex(parent->row(), 0, parent.get());
185 if (parent_idx.column() > 0)
188 if (parent_idx.isValid())
189 parent = static_cast<DecoderCollectionItem*>(parent_idx.internalPointer());
196 if (parent_idx.isValid())
197 return static_cast<DecoderCollectionItem*>(
200 return root_->columnCount();
QVariant data(int column) const
DecoderCollectionModel(QObject *parent=nullptr)
shared_ptr< DecoderCollectionItem > parent() const
QVariant data(const QModelIndex &index, int role) const override
int rowCount(const QModelIndex &parent_idx=QModelIndex()) const override
QModelIndex index(int row, int column, const QModelIndex &parent_idx=QModelIndex()) const override
QModelIndex parent(const QModelIndex &index) const override
shared_ptr< DecoderCollectionItem > root_
Qt::ItemFlags flags(const QModelIndex &index) const override
int columnCount(const QModelIndex &parent_idx=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
shared_ptr< DecoderCollectionItem > subItem(int row) const