DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::models::tree Class Reference

#include <tree.hpp>

Inheritance diagram for dbe::models::tree:
[legend]
Collaboration diagram for dbe::models::tree:
[legend]

Public Types

typedef dbe::treenode type_datum

Signals

void ObjectFile (QString)

Public Member Functions

 ~tree ()
 tree (const QStringList &Headers, QObject *parent=nullptr)
type_index index (int row, int column, const type_index &parent) const override
type_index parent (const type_index &child) const override
type_index mapToSource (type_index const &i)
int rowCount (const type_index &parent) const override
int columnCount (const type_index &parent) const override
Qt::ItemFlags flags (const type_index &index) const override
QVariant data (const type_index &index, int role=Qt::DisplayRole) const override
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
bool insertRows (int position, int rows, const type_index &parent) override
void fetchMore (const type_index &parent) override
bool canFetchMore (const type_index &parent) const override
bool hasChildren (const type_index &parent) const override
bool setData (const type_index &index, const QVariant &value, int role) override
QStringList mimeTypes () const override
QMimeData * mimeData (const QModelIndexList &indexes) const override
type_datum * getnode (const type_index &index) const override
type_index getindex (treenode *NodeItem, type_index const &RootIndex=QModelIndex()) const
void ResetModel ()
void objectsUpdated (const std::vector< dbe::dref > &objects)
Public Member Functions inherited from dbe::TreeModelInterface
virtual treenode * getnode (const QModelIndex &index) const =0
virtual ~TreeModelInterface ()=default
Public Member Functions inherited from dbe::model_common_impl< tree >
bool delete_objects (type_indices::iterator, type_indices::iterator) override
bool update_objects (type_indices::iterator, type_indices::iterator) override
bool create_objects (type_indices::iterator, type_indices::iterator) override
Public Member Functions inherited from dbe::model_common_interface
virtual ~model_common_interface ()=default
Public Member Functions inherited from dbe::model_initiate_actions_interface
virtual ~model_initiate_actions_interface ()=default
Public Member Functions inherited from dbe::model_common_data_access_interface
virtual type_object_ref getobject (type_index const &index) const =0
virtual type_class_info getclass (type_index const &index) const =0
virtual QAbstractItemModel * ReturnSourceModel () const =0
virtual ~model_common_data_access_interface ()=default
Public Member Functions inherited from dbe::model_common_async_operations< tree >
MODEL_COMMON_TYPES_TOPLEVEL_DEFINITIONS model_common_async_operations ()
void model_common_connections ()

Private Slots

void ToggleAbstractClassesSelectable (bool)
void slot_create_object (QString const &src, dref const &obj)
void slot_remove_object (QString const &src, dref const &obj)
void slot_update_object (QString const &src, dref const &obj)
void slot_rename_object (QString const &src, dref const &obj)

Private Attributes

bool abstract_classes_selectable

Additional Inherited Members

Protected Member Functions inherited from dbe::model_common_interface
virtual void remove_deleted_object (type_index const &index)=0
virtual void rename_contained_object (type_index const &index, type_object_info const &obj)=0
virtual void update_contained_object (type_index const &index, type_object_info const &obj)=0
virtual void create_contained_object (type_index const &index, type_object_info const &obj)=0
virtual type_index lookup (type_object_info const &)=0
QUuid getuuid () const
Protected Member Functions inherited from dbe::model_common_async_operations< tree >
void remove_object (type_object_info const &)
void create_object (type_object_info const &)
void rename_object (type_object_info const &)
void update_object (type_object_info const &)
void update_multiple_objects (std::vector< type_object_info > const &)

Detailed Description

Definition at line 24 of file tree.hpp.

Member Typedef Documentation

◆ type_datum

Definition at line 35 of file tree.hpp.

Constructor & Destructor Documentation

◆ ~tree()

dbe::models::tree::~tree ( )

Definition at line 32 of file tree.cpp.

32{}

◆ tree()

dbe::models::tree::tree ( const QStringList & Headers,
QObject * parent = nullptr )
explicit

Definition at line 19 of file tree.cpp.

20 : QAbstractItemModel(parent)
22{
23 confaccessor::gethandler()->root = new dbe::treenode(Headers);
24
25 for (std::string const& aclass : dbe::config::api::info::onclass::allnames<std::vector<std::string>>()) {
27 }
28
30}
ClassNode(const dunedaq::conffwk::class_t &Info, treenode *ParentNode)
Definition treenode.cpp:157
static cptr< datahandler > gethandler()
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
bool abstract_classes_selectable
Definition tree.hpp:83
type_index parent(const type_index &child) const override
Definition tree.cpp:48

Member Function Documentation

◆ canFetchMore()

bool dbe::models::tree::canFetchMore ( const type_index & parent) const
override

Definition at line 197 of file tree.cpp.

198{
199 if (parent.isValid()) {
200 treenode* ParentNode = getnode(parent);
201 return (!ParentNode->GetWasFetched());
202 }
203
204 return false;
205}
type_datum * getnode(const type_index &index) const override
Definition tree.cpp:306

◆ columnCount()

int dbe::models::tree::columnCount ( const type_index & parent) const
override

Definition at line 76 of file tree.cpp.

77{
78 if (parent.isValid()) {
79 dbe::treenode* DataNode = getnode(parent);
80
81 return DataNode->ColumnCount();
82 } else {
83 return confaccessor::gethandler()->root->ColumnCount();
84 }
85}
int ColumnCount() const
Definition treenode.cpp:128

◆ data()

QVariant dbe::models::tree::data ( const type_index & index,
int role = Qt::DisplayRole ) const
override

Definition at line 106 of file tree.cpp.

107{
108 if (index.isValid()) {
109 switch (role) {
110 case Qt::ForegroundRole:
111 if (ObjectNode* onode = dynamic_cast<ObjectNode*>(getnode(index))) {
112 try {
113 tref const& obj = onode->GetObject();
114
115 if (confaccessor::check_file_rw(QString::fromStdString(obj.contained_in()))) {
116 return QVariant(StyleUtility::ObjectForeground);
117 } else {
119 }
120 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
121 // nothing to do the onode refers to a removed object and has not yet been removed
122 return QVariant();
123 }
124 }
125
126 break;
127
128 case Qt::BackgroundRole:
129 if (ObjectNode* onode = dynamic_cast<ObjectNode*>(getnode(index))) {
130 try {
131 tref const& obj = onode->GetObject();
132
133 if (confaccessor::check_file_rw(QString::fromStdString(obj.contained_in()))) {
134 return QVariant(StyleUtility::ObjectBackground);
135 } else {
137 }
138 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
139 // nothing to do the onode refers to a removed object and has not yet been removed
140 return QVariant();
141 }
142 }
143
144 break;
145
146 case Qt::ToolTipRole:
147 if (auto cnode = dynamic_cast<ClassNode*>(getnode(index))) {
148 return cnode->GetData(index.column(), role);
149 }
150 break;
151
152 case Qt::DisplayRole:
153 case Qt::DecorationRole:
154 return getnode(index)->GetData(index.column(), role);
155 }
156 }
157
158 return QVariant();
159}
static QColor ObjectForeground
static QColor FileReadOnlyForeground
static QColor ObjectBackground
static QColor FileReadOnlyBackground
static bool check_file_rw(const QString &FileName)
type_index index(int row, int column, const type_index &parent) const override
Definition tree.cpp:35
virtual QVariant GetData(const int Column, int role=Qt::DisplayRole) const
Definition treenode.cpp:60
inner::configobject::tref tref
Definition tref.hpp:36

◆ fetchMore()

void dbe::models::tree::fetchMore ( const type_index & parent)
override

Definition at line 208 of file tree.cpp.

209{
210 if (parent.isValid()) {
211 treenode* ParentNode = getnode(parent);
212
213 if (!ParentNode->GetWasFetched()) {
214 insertRows(0, 0, parent);
215 ParentNode->SetWasFetched(true);
216 }
217 }
218}
bool insertRows(int position, int rows, const type_index &parent) override
Definition tree.cpp:172

◆ flags()

Qt::ItemFlags dbe::models::tree::flags ( const type_index & index) const
override

Definition at line 88 of file tree.cpp.

89{
90 treenode* node = getnode(index);
91
92 if (ClassNode* classnode = dynamic_cast<ClassNode*>(node)) {
93 dunedaq::conffwk::class_t classinfo = classnode->GetClassInfo();
94
95 if (classinfo.p_abstract) {
96 return abstract_classes_selectable ? (Qt::ItemIsEnabled | Qt::ItemIsSelectable) : (Qt::ItemIsSelectable);
97 } else {
98 return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
99 }
100 }
101
102 return (Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
103}

◆ getindex()

QModelIndex dbe::models::tree::getindex ( treenode * NodeItem,
type_index const & RootIndex = QModelIndex() ) const

Definition at line 278 of file tree.cpp.

279{
280 for (int i = 0; i < rowCount(RootIndex); ++i) {
281 QModelIndex ChildIndex = index(i, 0, RootIndex);
282 treenode* ChildNode = getnode(ChildIndex);
283
284 if (NodeItem == ChildNode) {
285 return ChildIndex;
286 }
287
288 QModelIndex ChildChildIndex = getindex(NodeItem, ChildIndex);
289
290 if (ChildChildIndex.isValid()) {
291 return ChildChildIndex;
292 }
293 }
294
295 return QModelIndex();
296}
type_index getindex(treenode *NodeItem, type_index const &RootIndex=QModelIndex()) const
Definition tree.cpp:278
int rowCount(const type_index &parent) const override
Definition tree.cpp:62

◆ getnode()

dbe::models::tree::type_datum * dbe::models::tree::getnode ( const type_index & index) const
override

Definition at line 306 of file tree.cpp.

307{
308 if (index.isValid()) {
309 return static_cast<treenode*>(index.internalPointer());
310 }
311
312 return confaccessor::gethandler()->root;
313}

◆ hasChildren()

bool dbe::models::tree::hasChildren ( const type_index & parent) const
override

Definition at line 221 of file tree.cpp.

222{
223 if (parent.isValid()) {
224 treenode* ParentNode = getnode(parent);
225 return (ParentNode->GetHasStructure());
226 }
227
228 return true;
229}

◆ headerData()

QVariant dbe::models::tree::headerData ( int section,
Qt::Orientation orientation,
int role = Qt::DisplayRole ) const
override

Definition at line 162 of file tree.cpp.

163{
164 if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) {
165 return confaccessor::gethandler()->root->GetData(section);
166 }
167
168 return QVariant();
169}

◆ index()

dbe::models::tree::type_index dbe::models::tree::index ( int row,
int column,
const type_index & parent ) const
override

Definition at line 35 of file tree.cpp.

36{
37 // This is standard qt implementation for a tree mode;
38 dbe::treenode* up{ parent.isValid() ? getnode(parent) : confaccessor::gethandler()->root };
39
40 if (dbe::treenode* down = up->GetChild(row)) {
41 return createIndex(row, column, down);
42 } else {
43 return QModelIndex();
44 }
45}
treenode * GetChild(const int Row) const
Definition treenode.cpp:104

◆ insertRows()

bool dbe::models::tree::insertRows ( int position,
int rows,
const type_index & parent )
override

Definition at line 172 of file tree.cpp.

173{
174 if (ClassNode* onode = dynamic_cast<ClassNode*>(getnode(parent))) {
175 rows = onode->ChildCount();
176
177 beginInsertRows(parent, position, position + rows - 1);
178
179 std::string const& classname = onode->GetData(static_cast<int>(tablepositions::classname)).toString().toStdString();
180
181 std::vector<tref> const& objects = config::api::info::onclass::objects(classname, false);
182
183 for (auto const& i : objects) {
184 new ObjectNode(i, false, onode);
185 emit ObjectFile(QString::fromStdString(i.contained_in()));
186 }
187
188 endInsertRows();
189
190 return true;
191 } else {
192 return false;
193 }
194}
ObjectNode(dref ObjectData, bool IsCopy, treenode *ParentNode)
Definition treenode.cpp:228
static std::vector< dbe::inner::configobject::tref > objects(std::string const &cname, bool const keep_inherited=true)
void ObjectFile(QString)

◆ mapToSource()

type_index dbe::models::tree::mapToSource ( type_index const & i)
inline

Definition at line 45 of file tree.hpp.

45{ return i; }

◆ mimeData()

QMimeData * dbe::models::tree::mimeData ( const QModelIndexList & indexes) const
override

Definition at line 250 of file tree.cpp.

251{
252 QMimeData* mimeData = new QMimeData();
253 QByteArray encodedData;
254
255 QDataStream stream(&encodedData, QIODevice::WriteOnly);
256
257 foreach (QModelIndex index, indexes) {
258 if (index.isValid() && index.column() == 0) {
259 QStringList Text;
260 treenode* NodeObject = getnode(index);
261
262 tref Object = NodeObject->GetObject();
263 QString ObjectUid = QString::fromStdString(Object.UID());
264 QString ObjectClassName = QString::fromStdString(Object.class_name());
265
266 Text.append(ObjectUid);
267 Text.append(ObjectClassName);
268
269 stream << Text;
270 }
271 }
272
273 mimeData->setData("application/vnd.text.list", encodedData);
274 return mimeData;
275}
QMimeData * mimeData(const QModelIndexList &indexes) const override
Definition tree.cpp:250

◆ mimeTypes()

QStringList dbe::models::tree::mimeTypes ( ) const
override

Definition at line 242 of file tree.cpp.

243{
244 QStringList types;
245 types << "application/vnd.text.list";
246 return types;
247}

◆ ObjectFile

void dbe::models::tree::ObjectFile ( QString )
signal

◆ objectsUpdated()

void dbe::models::tree::objectsUpdated ( const std::vector< dbe::dref > & objects)

Definition at line 370 of file tree.cpp.

371{
373}
void update_multiple_objects(std::vector< type_object_info > const &)

◆ parent()

dbe::models::tree::type_index dbe::models::tree::parent ( const type_index & child) const
override

Definition at line 48 of file tree.cpp.

49{
50 if (child.isValid()) {
51 dbe::treenode* up = getnode(child)->GetParent();
52
53 if (up != confaccessor::gethandler()->root) {
54 return createIndex(up->GetRow(), 0, up);
55 }
56 }
57
58 return QModelIndex();
59}
treenode * GetParent() const
Definition treenode.cpp:116
int GetRow() const
Definition treenode.cpp:82

◆ ResetModel()

void dbe::models::tree::ResetModel ( )

Definition at line 299 of file tree.cpp.

300{
301 beginResetModel();
302 endResetModel();
303}

◆ rowCount()

int dbe::models::tree::rowCount ( const type_index & parent) const
override

Definition at line 62 of file tree.cpp.

63{
64 dbe::treenode* ParentNode;
65
66 if (!parent.isValid()) {
67 ParentNode = confaccessor::gethandler()->getnode();
68 } else {
69 ParentNode = getnode(parent);
70 }
71
72 return ParentNode->ChildCount();
73}
int ChildCount() const
Definition treenode.cpp:122

◆ setData()

bool dbe::models::tree::setData ( const type_index & index,
const QVariant & value,
int role )
override

Definition at line 232 of file tree.cpp.

233{
234 Q_UNUSED(index)
235 Q_UNUSED(value)
236 Q_UNUSED(role)
237
238 return true;
239}

◆ slot_create_object

void dbe::models::tree::slot_create_object ( QString const & src,
dref const & obj )
privateslot

◆ slot_remove_object

void dbe::models::tree::slot_remove_object ( QString const & src,
dref const & obj )
privateslot

◆ slot_rename_object

void dbe::models::tree::slot_rename_object ( QString const & src,
dref const & obj )
privateslot

◆ slot_update_object

void dbe::models::tree::slot_update_object ( QString const & src,
dref const & obj )
privateslot

◆ ToggleAbstractClassesSelectable

void dbe::models::tree::ToggleAbstractClassesSelectable ( bool val)
privateslot

Definition at line 363 of file tree.cpp.

364{
366 ResetModel();
367}
void ResetModel()
Definition tree.cpp:299

Member Data Documentation

◆ abstract_classes_selectable

bool dbe::models::tree::abstract_classes_selectable
private

Definition at line 83 of file tree.hpp.


The documentation for this class was generated from the following files: