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
TableNodegetnode (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< drefthis_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 23 of file table.hpp.

Member Typedef Documentation

◆ type_datum

Definition at line 34 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.

31{}

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 268 of file table.cpp.

269{
270 reset ( cname );
271
272 cptr<dbe::datahandler> dbaccess_guard = confaccessor::gethandler();
273
274 dunedaq::conffwk::class_t classinfo = dbe::config::api::info::onclass::definition (
275 cname.toStdString(),
276 false );
277
278 setheader ( classinfo );
279
280 if ( treenode * NodeClass = dbaccess_guard->getnode ( cname ) )
281 {
282 std::vector<treenode *> classnodes
283 { NodeClass };
284
285 if ( include_derived )
286 {
287
288 for ( std::string const & sbcname : classinfo.p_subclasses )
289 {
290 if ( treenode * sbcnode = dbaccess_guard->getnode ( sbcname ) )
291 {
292 classnodes.push_back ( sbcnode );
293 }
294 }
295 }
296
299
300 for ( treenode * clelement : classnodes )
301 {
303
304 for ( treenode * child : clelement->GetChildren() )
305 {
306 this_structure.append ( createrow ( child ) );
307 }
308 }
309
310 enabled = true;
311 return true;
312 }
313 else
314 {
315 return false;
316 }
317}
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:319
void reset(QString const &)
Definition table.cpp:392
void setheader(dunedaq::conffwk::class_t const &)
Definition table.cpp:406
QList< QList< TableNode * > > this_structure
Definition table.hpp:81
const std::vector< std::string > p_subclasses
Definition Schema.hpp:169

◆ BuildTableFromObject()

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

Definition at line 431 of file table.cpp.

432{
433 reset ( BuildList.at ( 0 ).at ( 1 ) );
434
435 treenode * classnode = confaccessor::gethandler()->getnode ( this_class_name );
436
437 dunedaq::conffwk::class_t classinfo = dbe::config::api::info::onclass::definition (
438 this_class_name.toStdString(),
439 false );
440
441 setheader ( classinfo );
442
443 confaccessor::gethandler()->FetchMore ( classnode );
444
445 for ( const QStringList & i : BuildList )
446 {
447 QString name = i.at ( 0 );
448 treenode * node = confaccessor::gethandler()->getnode ( this_class_name, name );
449 this_structure.append ( createrow ( node ) );
450 }
451
452 enabled = false;
453 return true;
454}
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 319 of file table.cpp.

321{
322
323 dref obj = rownode->GetObject();
324
325 this_objects.append ( obj );
326
327 dunedaq::conffwk::class_t const & cdef = dbe::config::api::info::onclass::definition (
328 obj.class_name(),
329 false );
330 std::vector<dunedaq::conffwk::attribute_t> const & attributes = cdef.p_attributes;
331 std::vector<dunedaq::conffwk::relationship_t> const & relations = cdef.p_relationships;
332
333 assert ( attributes.size() + relations.size() < 1025 );
334 std::bitset<1024> hindex; // maximum number of columns to display
335
336 {
337 int column = 0;
338
339 for ( dunedaq::conffwk::attribute_t const & attr : attributes )
340 {
341 hindex.set ( column++, this_headers.contains ( QString::fromStdString ( attr.p_name ) ) );
342 }
343
344 for ( dunedaq::conffwk::relationship_t const & rel : relations )
345 {
346 hindex.set ( column++, this_headers.contains ( QString::fromStdString ( rel.p_name ) ) );
347 }
348 }
349
350 // Create the row for this object
351 QList<TableNode *> Row;
352 Row.append ( new TableNode (
353 QStringList {rownode->GetData ( 0 ).toString()},
354 QVariant(QString::fromStdString(cdef.p_description))));
355 {
356 // Loop over object values and add them to the row
357 // Values are represent as nodes ( attributes or relations ) and these contain
358 // the structured data associated either with a attribute / multi-attribute or a relation
359 std::size_t column = 0;
360
361 for ( treenode * valuenode : rownode->GetChildren() )
362 {
363 QStringList values;
364 // Every valuenode has its attributes and relations defined as its childs
365
366 if ( hindex[column++] )
367 {
368
369 for ( treenode * nodevalues : valuenode->GetChildren() )
370 {
371 // Here we need to filter such that only values corresponding to the header are kept
372 // Add only the first of values in a list of values
373 values.append ( nodevalues->GetData ( 0 ).toString() );
374 }
375
376 if ( AttributeNode * NodeAttribute = dynamic_cast<AttributeNode *> ( valuenode ) )
377 {
378 Row.append ( new TableAttributeNode ( NodeAttribute->attribute_t(), values ) );
379 }
380 else if ( RelationshipNode * NodeRelationship =
381 dynamic_cast<RelationshipNode *> ( valuenode ) )
382 {
383 Row.append ( new TableRelationshipNode ( NodeRelationship->relation_t(), values ) );
384 }
385 }
386 }
387 }
388
389 return Row;
390}
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:170
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:171
std::string p_description
Definition Schema.hpp:165

◆ data()

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

Definition at line 52 of file table.cpp.

53{
54
55 if ( index.isValid() )
56 {
57 TableNode * TableItem = getnode ( index );
58
59 if ( role == Qt::DisplayRole )
60 {
61 QString Data;
62
63 for ( QString const & i : TableItem->GetData() )
64 {
65 static QString space
66 { ", " };
67 Data.append(i).append(space);
68 }
69 Data.remove(Data.length() - 2, 2);
70
71 return QVariant ( Data );
72 }
73
74 if ( role == Qt::ToolTipRole )
75 {
76 return TableItem->get_tooltip();
77 }
78 if ( role == Qt::FontRole )
79 {
80 if ( dynamic_cast<TableAttributeNode *> ( TableItem ) )
81 return QFont ( "Helvetica", 10, -1,
82 false );
83 else if ( dynamic_cast<TableRelationshipNode *> ( TableItem ) )
84 return QFont ( "Courier", 10,
85 QFont::Bold );
86 else
87 {
88 return QFont ( "SansSerif", 10, QFont::Bold );
89 }
90 }
91
92 if ( role == Qt::ForegroundRole )
93 {
94 if ( dynamic_cast<TableAttributeNode *> ( TableItem ) )
95 return QBrush (
97 else if ( dynamic_cast<TableRelationshipNode *> ( TableItem ) )
98 return QBrush (
100 else
101 {
102 return QVariant();
103 }
104 }
105
106 if ( role == Qt::BackgroundRole )
107 {
108 auto attr_node = dynamic_cast<TableAttributeNode *> ( TableItem );
109 if ( attr_node != nullptr ) {
110 auto val = attr_node->GetData();
111 if (val.size() == 1 &&
112 val[0].toStdString() == attr_node->GetAttribute().p_default_value) {
113 return QBrush (
115 }
116 }
117 return QBrush (
119 }
120 }
121
122 return QVariant();
123}
static QColor TableAttributeHighlightBackground
static QColor TableColorAttribute
Including DBE.
static QColor TableAttributeBackground
static QColor TableColorRelationship
TableNode * getnode(const QModelIndex &Index) const
Definition table.cpp:481
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 217 of file table.cpp.

220{
221 Q_UNUSED ( row )
222 Q_UNUSED ( column )
223 Q_UNUSED ( parent )
224
225 bool Accept = true;
226
227 if ( action == Qt::IgnoreAction )
228 {
229 return true;
230 }
231
232 if ( !data->hasFormat ( "application/vnd.text.list" ) )
233 {
234 return false;
235 }
236
238 QByteArray encodedData = data->data ( "application/vnd.text.list" );
239
240 QDataStream stream ( &encodedData, QIODevice::ReadOnly );
241
242 QList<QStringList> newItems;
243
244 while ( !stream.atEnd() )
245 {
246 QStringList text;
247 stream >> text;
248 newItems << text;
249 }
250
251 for ( int i = 0; i < newItems.size(); ++i )
252 {
253 if ( newItems.at ( 0 ).at ( 1 ) != newItems.at ( i ).at ( 1 ) )
254 {
255 Accept = false;
256 }
257 }
258
259 if ( Accept )
260 {
261 BuildTableFromObject ( newItems );
262 emit ResetTab();
263 }
264
265 return Accept;
266}
QVariant data(type_index const &index, int role) const override
Definition table.cpp:52
bool BuildTableFromObject(QList< QStringList > BuildList)
Definition table.cpp:431

◆ flags()

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

Definition at line 189 of file table.cpp.

190{
191 if(index.isValid()) {
192 dref obj_desc = this_objects[index.row()];
193 tref Object = dbe::inner::dbcontroller::get ( { obj_desc.UID(), obj_desc.class_name() } );
194
195 if ( confaccessor::check_file_rw ( QString::fromStdString ( Object.contained_in() ) ) )
196 {
197 return ( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable |
198 Qt::ItemIsDropEnabled );
199 }
200 }
201
202 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
203}
static bool check_file_rw(const QString &FileName)
static configobject::tref get(dbe::cokey const &desc)
inner::configobject::tref tref
Definition tref.hpp:35

◆ get_class_name()

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

Definition at line 466 of file table.cpp.

467{
468 return this_class_name;
469}

◆ getnode()

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

Definition at line 481 of file table.cpp.

482{
483 if ( Index.isValid() )
484 {
485 return this_structure.at ( Index.row() ).at ( Index.column() );
486 }
487
488 return nullptr;
489}

◆ GetTableObject()

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

Definition at line 456 of file table.cpp.

457{
458 return this_objects.at ( ObjectIndex ).ref();
459}

◆ GetTableObjects()

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

Definition at line 476 of file table.cpp.

477{
478 return &this_objects;
479}

◆ headerData()

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

Definition at line 166 of file table.cpp.

168{
169 if ( role == Qt::DisplayRole )
170 {
171 if ( orientation == Qt::Horizontal )
172 {
173 return this_headers.at ( section );
174 }
175 if ( orientation == Qt::Vertical )
176 {
177 return section + 1;
178 }
179 }
180
181 if ( role == Qt::FontRole )
182 {
183 return QFont ( "Helvetica [Cronyx]", 10 );
184 }
185
186 return QVariant();
187}
Missing configuration section
Message.

◆ is_built()

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

Definition at line 461 of file table.cpp.

462{
463 return enabled;
464}

◆ mimeTypes()

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

Definition at line 210 of file table.cpp.

211{
212 QStringList types;
213 types << "application/vnd.text.list";
214 return types;
215}

◆ objectsUpdated()

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

Definition at line 523 of file table.cpp.

523 {
525}
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 392 of file table.cpp.

393{
394
395 for ( auto & List : this_structure )
396 {
397 qDeleteAll ( List );
398 }
399
400 this_objects.clear();
401 this_structure.clear();
402 this_headers.clear();
403 this_class_name = cname;
404}

◆ ResetModel()

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

Definition at line 491 of file table.cpp.

492{
493 beginResetModel();
494 endResetModel();
495}

◆ 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 {
37 return this_structure.size();
38 }
39
40 return 0;
41}

◆ setData()

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

Definition at line 125 of file table.cpp.

127{
128 if ( !index.isValid() || role != Qt::EditRole )
129 {
130 return false;
131 }
132
133 TableNode * TableItem = getnode ( index );
134
135 QStringList OldDataList = TableItem->GetData();
136
137 QStringList NewDataList = value.toStringList();
138
139 if ( NewDataList == OldDataList )
140 {
141 return false;
142 }
143
144 dref obj_desc = this_objects[index.row()];
145
147 { obj_desc.UID(), obj_desc.class_name() } );
148
149 if ( dynamic_cast<TableRelationshipNode *> ( TableItem ) )
150 {
151 TableRelationshipNode * RelationshipNode =
152 dynamic_cast<TableRelationshipNode *> ( TableItem );
153 dunedaq::conffwk::relationship_t RelationshipData = RelationshipNode->GetRelationship();
154 dbe::config::api::set::relation ( Object, RelationshipData, NewDataList );
155 }
156 else if ( dynamic_cast<TableAttributeNode *> ( TableItem ) )
157 {
158 TableAttributeNode * AttributeNode = dynamic_cast<TableAttributeNode *> ( TableItem );
159 dunedaq::conffwk::attribute_t AttributeData = AttributeNode->GetAttribute();
160 dbe::config::api::set::attribute ( Object, AttributeData, NewDataList );
161 }
162
163 return true;
164}
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 406 of file table.cpp.

407{
408 if ( !this_headers.contains ( "Object Name" ) )
409 {
410 this_headers.append ( "Object Name" );
411 }
412
413 for ( auto & i : cinfo.p_attributes )
414 {
415 if ( !this_headers.contains ( QString::fromStdString ( i.p_name ) ) )
416 {
417 this_headers.append ( QString::fromStdString ( i.p_name ) );
418 }
419 }
420
421 for ( auto & i : cinfo.p_relationships )
422 {
423 if ( !this_headers.contains ( QString::fromStdString ( i.p_name ) ) )
424 {
425 this_headers.append ( QString::fromStdString ( i.p_name ) );
426 }
427 }
428
429}

◆ 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 497 of file table.cpp.

498{
499 QModelIndex dum;
500 this->dropMimeData ( &data, action, 0, 0, dum );
501}
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, type_index const &parent) override
Definition table.cpp:217

◆ 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 205 of file table.cpp.

206{
207 return Qt::CopyAction;
208}

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: