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

#include <table.hpp>

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

Public Types

typedef TableNode type_datum

Public Slots

void slot_data_dropped (QMimeData const &, Qt::DropAction)

Signals

void ResetTab ()

Public Member Functions

 table (QObject *parent=nullptr)
 Including QT Headers.
 ~table ()
int rowCount (type_index const &parent) const override
int columnCount (type_index const &parent) const override
QVariant data (type_index const &index, int role) const override
bool setData (type_index const &index, const QVariant &value, int role) override
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
Qt::ItemFlags flags (type_index const &index) const override
TableNode * getnode (const QModelIndex &Index) const
QStringList mimeTypes () const override
Qt::DropActions supportedDropActions () const override
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, type_index const &parent) override
void ResetModel ()
bool BuildTableFromClass (const QString &ClassName, bool BuildSubClasses=false)
bool BuildTableFromObject (QList< QStringList > BuildList)
bool is_built () const
QString get_class_name () const
tref GetTableObject (int ObjectIndex) const
QList< dbe::dref > * GetTableObjects ()
void objectsUpdated (const std::vector< dbe::dref > &objects)
Public Member Functions inherited from dbe::model_common_impl< table >
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< table >
MODEL_COMMON_TYPES_TOPLEVEL_DEFINITIONS model_common_async_operations ()
void model_common_connections ()

Private Slots

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 Member Functions

void reset (QString const &)
void setheader (dunedaq::conffwk::class_t const &)
QList< type_datum * > createrow (treenode const *)

Private Attributes

bool enabled
QString this_class_name
dunedaq::conffwk::class_t class_type_info
QStringList this_headers
QList< dref > this_objects
QList< QList< TableNode * > > this_structure

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< table >
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 21 of file table.hpp.

Member Typedef Documentation

◆ type_datum

Definition at line 31 of file table.hpp.

Constructor & Destructor Documentation

◆ table()

dbe::models::table::table ( QObject * parent = nullptr)
explicit

Including QT Headers.

Definition at line 23 of file table.cpp.

24 : QAbstractTableModel(parent)
25 , enabled(false)
26{
28}

◆ ~table()

dbe::models::table::~table ( )

Definition at line 30 of file table.cpp.

30{}

Member Function Documentation

◆ BuildTableFromClass()

bool dbe::models::table::BuildTableFromClass ( const QString & ClassName,
bool BuildSubClasses = false )

Looping over classes Only in the case of derived classes this will be more than one

All objects from that class

Definition at line 252 of file table.cpp.

253{
254 reset(cname);
255
256 cptr<dbe::datahandler> dbaccess_guard = confaccessor::gethandler();
257
258 dunedaq::conffwk::class_t classinfo = dbe::config::api::info::onclass::definition(cname.toStdString(), false);
259
260 setheader(classinfo);
261
262 if (treenode* NodeClass = dbaccess_guard->getnode(cname)) {
263 std::vector<treenode*> classnodes{ NodeClass };
264
265 if (include_derived) {
266
267 for (std::string const& sbcname : classinfo.p_subclasses) {
268 if (treenode* sbcnode = dbaccess_guard->getnode(sbcname)) {
269 classnodes.push_back(sbcnode);
270 }
271 }
272 }
273
276
277 for (treenode* clelement : classnodes) {
279
280 for (treenode* child : clelement->GetChildren()) {
281 this_structure.append(createrow(child));
282 }
283 }
284
285 enabled = true;
286 return true;
287 } else {
288 return false;
289 }
290}
static cptr< datahandler > gethandler()
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
QList< type_datum * > createrow(treenode const *)
Definition table.cpp:293
void reset(QString const &)
Definition table.cpp:354
void setheader(dunedaq::conffwk::class_t const &)
Definition table.cpp:368
QList< QList< TableNode * > > this_structure
Definition table.hpp:81
const std::vector< std::string > p_subclasses
Definition Schema.hpp:160

◆ BuildTableFromObject()

bool dbe::models::table::BuildTableFromObject ( QList< QStringList > BuildList)

Definition at line 388 of file table.cpp.

389{
390 reset(BuildList.at(0).at(1));
391
392 treenode* classnode = confaccessor::gethandler()->getnode(this_class_name);
393
394 dunedaq::conffwk::class_t classinfo =
396
397 setheader(classinfo);
398
399 confaccessor::gethandler()->FetchMore(classnode);
400
401 for (const QStringList& i : BuildList) {
402 QString name = i.at(0);
403 treenode* node = confaccessor::gethandler()->getnode(this_class_name, name);
404 this_structure.append(createrow(node));
405 }
406
407 enabled = false;
408 return true;
409}
QString this_class_name
Definition table.hpp:76

◆ columnCount()

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

Definition at line 43 of file table.cpp.

44{
45 if (!parent.isValid()) {
46 return this_headers.size();
47 }
48
49 return 0;
50}
QStringList this_headers
Definition table.hpp:79

◆ createrow()

QList< dbe::models::table::type_datum * > dbe::models::table::createrow ( treenode const * rownode)
private

Definition at line 293 of file table.cpp.

294{
295
296 dref obj = rownode->GetObject();
297
298 this_objects.append(obj);
299
300 dunedaq::conffwk::class_t const& cdef = dbe::config::api::info::onclass::definition(obj.class_name(), false);
301 std::vector<dunedaq::conffwk::attribute_t> const& attributes = cdef.p_attributes;
302 std::vector<dunedaq::conffwk::relationship_t> const& relations = cdef.p_relationships;
303
304 assert(attributes.size() + relations.size() < 1025);
305 std::bitset<1024> hindex; // maximum number of columns to display
306
307 {
308 int column = 0;
309
310 for (dunedaq::conffwk::attribute_t const& attr : attributes) {
311 hindex.set(column++, this_headers.contains(QString::fromStdString(attr.p_name)));
312 }
313
314 for (dunedaq::conffwk::relationship_t const& rel : relations) {
315 hindex.set(column++, this_headers.contains(QString::fromStdString(rel.p_name)));
316 }
317 }
318
319 // Create the row for this object
320 QList<TableNode*> Row;
321 Row.append(
322 new TableNode(QStringList{ rownode->GetData(0).toString() }, QVariant(QString::fromStdString(cdef.p_description))));
323 {
324 // Loop over object values and add them to the row
325 // Values are represent as nodes ( attributes or relations ) and these contain
326 // the structured data associated either with a attribute / multi-attribute or a relation
327 std::size_t column = 0;
328
329 for (treenode* valuenode : rownode->GetChildren()) {
330 QStringList values;
331 // Every valuenode has its attributes and relations defined as its childs
332
333 if (hindex[column++]) {
334
335 for (treenode* nodevalues : valuenode->GetChildren()) {
336 // Here we need to filter such that only values corresponding to the header are kept
337 // Add only the first of values in a list of values
338 values.append(nodevalues->GetData(0).toString());
339 }
340
341 if (AttributeNode* NodeAttribute = dynamic_cast<AttributeNode*>(valuenode)) {
342 Row.append(new TableAttributeNode(NodeAttribute->attribute_t(), values));
343 } else if (RelationshipNode* NodeRelationship = dynamic_cast<RelationshipNode*>(valuenode)) {
344 Row.append(new TableRelationshipNode(NodeRelationship->relation_t(), values));
345 }
346 }
347 }
348 }
349
350 return Row;
351}
TableAttributeNode(dunedaq::conffwk::attribute_t Attribute, const QStringList &NodeData)
Definition TableNode.cpp:23
TableNode(QStringList const &NodeData, const QVariant &tooltip)
Including DBE.
Definition TableNode.cpp:9
TableRelationshipNode(dunedaq::conffwk::relationship_t Relationship, const QStringList &NodeData)
Definition TableNode.cpp:43
QList< dref > this_objects
Definition table.hpp:80
std::vector< T > attributes(tref const &item)
std::vector< T > relations(tref const &item)
config_object_description dref
const std::vector< attribute_t > p_attributes
Definition Schema.hpp:161
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:162
std::string p_description
Definition Schema.hpp:156

◆ data()

QVariant dbe::models::table::data ( type_index const & index,
int role ) const
override

Definition at line 53 of file table.cpp.

54{
55
56 if (index.isValid()) {
57 TableNode* TableItem = getnode(index);
58
59 if (role == Qt::DisplayRole) {
60 QString Data;
61
62 for (QString const& i : TableItem->GetData()) {
63 static QString space{ ", " };
64 Data.append(i).append(space);
65 }
66 Data.remove(Data.length() - 2, 2);
67
68 return QVariant(Data);
69 }
70
71 if (role == Qt::ToolTipRole) {
72 return TableItem->get_tooltip();
73 }
74 if (role == Qt::FontRole) {
75 if (dynamic_cast<TableAttributeNode*>(TableItem))
76 return QFont("Helvetica", 10, -1, false);
77 else if (dynamic_cast<TableRelationshipNode*>(TableItem))
78 return QFont("Courier", 10, QFont::Bold);
79 else {
80 return QFont("SansSerif", 10, QFont::Bold);
81 }
82 }
83
84 if (role == Qt::ForegroundRole) {
85 if (dynamic_cast<TableAttributeNode*>(TableItem))
87 else if (dynamic_cast<TableRelationshipNode*>(TableItem))
89 else {
90 dref obj_desc = this_objects[index.row()];
91 tref Object = dbe::inner::dbcontroller::get({ obj_desc.UID(), obj_desc.class_name() });
92 if (!confaccessor::check_file_rw(QString::fromStdString(Object.contained_in()))) {
94 }
95 return QVariant();
96 }
97 }
98
99 if (role == Qt::BackgroundRole) {
100 auto attr_node = dynamic_cast<TableAttributeNode*>(TableItem);
101 if (attr_node != nullptr) {
102 auto val = attr_node->GetData();
103 if (val.size() == 1 && val[0].toStdString() == attr_node->GetAttribute().p_default_value) {
105 }
107 } else if (dynamic_cast<TableRelationshipNode*>(TableItem)) {
109 } else {
110 dref obj_desc = this_objects[index.row()];
111 tref Object = dbe::inner::dbcontroller::get({ obj_desc.UID(), obj_desc.class_name() });
112 if (!confaccessor::check_file_rw(QString::fromStdString(Object.contained_in()))) {
114 }
115 }
116 }
117 }
118 return QVariant();
119}
static QColor TableRelationshipBackground
static QColor FileReadOnlyForeground
static QColor TableColorAttribute
Including DBE.
static QColor TableAttributeBackground
static QColor DefaultValueBackground
static QColor TableColorRelationship
static QColor FileReadOnlyBackground
static bool check_file_rw(const QString &FileName)
static configobject::tref get(dbe::cokey const &desc)
TableNode * getnode(const QModelIndex &Index) const
Definition table.cpp:442
inner::configobject::tref tref
Definition tref.hpp:36
nlohmann::json Data
Definition Structs.hpp:24

◆ dropMimeData()

bool dbe::models::table::dropMimeData ( const QMimeData * data,
Qt::DropAction action,
int row,
int column,
type_index const & parent )
override

Here if parent is valid it indicates that the drop ocurred on an item otherwise it ocurred on a top level item

Definition at line 204 of file table.cpp.

209{
210 Q_UNUSED(row)
211 Q_UNUSED(column)
212 Q_UNUSED(parent)
213
214 bool Accept = true;
215
216 if (action == Qt::IgnoreAction) {
217 return true;
218 }
219
220 if (!data->hasFormat("application/vnd.text.list")) {
221 return false;
222 }
223
225 QByteArray encodedData = data->data("application/vnd.text.list");
226
227 QDataStream stream(&encodedData, QIODevice::ReadOnly);
228
229 QList<QStringList> newItems;
230
231 while (!stream.atEnd()) {
232 QStringList text;
233 stream >> text;
234 newItems << text;
235 }
236
237 for (int i = 0; i < newItems.size(); ++i) {
238 if (newItems.at(0).at(1) != newItems.at(i).at(1)) {
239 Accept = false;
240 }
241 }
242
243 if (Accept) {
244 BuildTableFromObject(newItems);
245 emit ResetTab();
246 }
247
248 return Accept;
249}
QVariant data(type_index const &index, int role) const override
Definition table.cpp:53
bool BuildTableFromObject(QList< QStringList > BuildList)
Definition table.cpp:388

◆ flags()

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

Definition at line 175 of file table.cpp.

176{
177 if (index.isValid()) {
178 dref obj_desc = this_objects[index.row()];
179 tref Object = dbe::inner::dbcontroller::get({ obj_desc.UID(), obj_desc.class_name() });
180
181 if (confaccessor::check_file_rw(QString::fromStdString(Object.contained_in()))) {
182 return (Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled);
183 }
184 }
185
186 return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
187}

◆ get_class_name()

QString dbe::models::table::get_class_name ( ) const

Definition at line 424 of file table.cpp.

425{
426 return this_class_name;
427}

◆ getnode()

dbe::TableNode * dbe::models::table::getnode ( const QModelIndex & Index) const

Definition at line 442 of file table.cpp.

443{
444 if (Index.isValid()) {
445 return this_structure.at(Index.row()).at(Index.column());
446 }
447
448 return nullptr;
449}

◆ GetTableObject()

dbe::tref dbe::models::table::GetTableObject ( int ObjectIndex) const

Definition at line 412 of file table.cpp.

413{
414 return this_objects.at(ObjectIndex).ref();
415}

◆ GetTableObjects()

QList< dbe::dref > * dbe::models::table::GetTableObjects ( )

Definition at line 436 of file table.cpp.

437{
438 return &this_objects;
439}

◆ headerData()

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

Definition at line 156 of file table.cpp.

157{
158 if (role == Qt::DisplayRole) {
159 if (orientation == Qt::Horizontal) {
160 return this_headers.at(section);
161 }
162 if (orientation == Qt::Vertical) {
163 return section + 1;
164 }
165 }
166
167 if (role == Qt::FontRole) {
168 return QFont("Helvetica [Cronyx]", 10);
169 }
170
171 return QVariant();
172}
Missing configuration section
Message.

◆ is_built()

bool dbe::models::table::is_built ( ) const

Definition at line 418 of file table.cpp.

419{
420 return enabled;
421}

◆ mimeTypes()

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

Definition at line 196 of file table.cpp.

197{
198 QStringList types;
199 types << "application/vnd.text.list";
200 return types;
201}

◆ objectsUpdated()

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

Definition at line 486 of file table.cpp.

487{
489}
void update_multiple_objects(std::vector< type_object_info > const &)

◆ reset()

void dbe::models::table::reset ( QString const & cname)
private

Clear internal structure and set the name to the given class

Parameters
theclass name to set

Definition at line 354 of file table.cpp.

355{
356
357 for (auto& List : this_structure) {
358 qDeleteAll(List);
359 }
360
361 this_objects.clear();
362 this_structure.clear();
363 this_headers.clear();
364 this_class_name = cname;
365}

◆ ResetModel()

void dbe::models::table::ResetModel ( )

Definition at line 452 of file table.cpp.

453{
454 beginResetModel();
455 endResetModel();
456}

◆ ResetTab

void dbe::models::table::ResetTab ( )
signal

◆ rowCount()

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

Definition at line 33 of file table.cpp.

34{
35 if (!parent.isValid()) {
36 return this_structure.size();
37 }
38
39 return 0;
40}

◆ setData()

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

Definition at line 122 of file table.cpp.

123{
124 if (!index.isValid() || role != Qt::EditRole) {
125 return false;
126 }
127
128 TableNode* TableItem = getnode(index);
129
130 QStringList OldDataList = TableItem->GetData();
131
132 QStringList NewDataList = value.toStringList();
133
134 if (NewDataList == OldDataList) {
135 return false;
136 }
137
138 dref obj_desc = this_objects[index.row()];
139
140 tref Object = dbe::inner::dbcontroller::get({ obj_desc.UID(), obj_desc.class_name() });
141
142 if (dynamic_cast<TableRelationshipNode*>(TableItem)) {
143 TableRelationshipNode* RelationshipNode = dynamic_cast<TableRelationshipNode*>(TableItem);
144 dunedaq::conffwk::relationship_t RelationshipData = RelationshipNode->GetRelationship();
145 dbe::config::api::set::relation(Object, RelationshipData, NewDataList);
146 } else if (dynamic_cast<TableAttributeNode*>(TableItem)) {
147 TableAttributeNode* AttributeNode = dynamic_cast<TableAttributeNode*>(TableItem);
148 dunedaq::conffwk::attribute_t AttributeData = AttributeNode->GetAttribute();
149 dbe::config::api::set::attribute(Object, AttributeData, NewDataList);
150 }
151
152 return true;
153}
void relation(dbe::inner::configobject::tref src, dunedaq::conffwk::relationship_t const &edge, QStringList const &targets)
void attribute(dbe::inner::configobject::tref objectref, dunedaq::conffwk::attribute_t const &attribute_info, QStringList const &attribute_values)

◆ setheader()

void dbe::models::table::setheader ( dunedaq::conffwk::class_t const & cinfo)
private

Set headers as designate by the given class

Parameters
thedunedaq::conffwk::class_t information for the class

Definition at line 368 of file table.cpp.

369{
370 if (!this_headers.contains("Object Name")) {
371 this_headers.append("Object Name");
372 }
373
374 for (auto& i : cinfo.p_attributes) {
375 if (!this_headers.contains(QString::fromStdString(i.p_name))) {
376 this_headers.append(QString::fromStdString(i.p_name));
377 }
378 }
379
380 for (auto& i : cinfo.p_relationships) {
381 if (!this_headers.contains(QString::fromStdString(i.p_name))) {
382 this_headers.append(QString::fromStdString(i.p_name));
383 }
384 }
385}

◆ slot_create_object

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

◆ slot_data_dropped

void dbe::models::table::slot_data_dropped ( QMimeData const & data,
Qt::DropAction action )
slot

Definition at line 459 of file table.cpp.

460{
461 QModelIndex dum;
462 this->dropMimeData(&data, action, 0, 0, dum);
463}
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, type_index const &parent) override
Definition table.cpp:204

◆ slot_remove_object

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

◆ slot_rename_object

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

◆ slot_update_object

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

◆ supportedDropActions()

Qt::DropActions dbe::models::table::supportedDropActions ( ) const
override

Definition at line 190 of file table.cpp.

191{
192 return Qt::CopyAction;
193}

Member Data Documentation

◆ class_type_info

dunedaq::conffwk::class_t dbe::models::table::class_type_info
private

Definition at line 77 of file table.hpp.

◆ enabled

bool dbe::models::table::enabled
private

Definition at line 75 of file table.hpp.

◆ this_class_name

QString dbe::models::table::this_class_name
private

Definition at line 76 of file table.hpp.

◆ this_headers

QStringList dbe::models::table::this_headers
private

Definition at line 79 of file table.hpp.

◆ this_objects

QList<dref> dbe::models::table::this_objects
private

Definition at line 80 of file table.hpp.

◆ this_structure

QList<QList<TableNode*> > dbe::models::table::this_structure
private

Definition at line 81 of file table.hpp.


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