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

283{
284 reset ( cname );
285
286 cptr<dbe::datahandler> dbaccess_guard = confaccessor::gethandler();
287
288 dunedaq::conffwk::class_t classinfo = dbe::config::api::info::onclass::definition (
289 cname.toStdString(),
290 false );
291
292 setheader ( classinfo );
293
294 if ( treenode * NodeClass = dbaccess_guard->getnode ( cname ) )
295 {
296 std::vector<treenode *> classnodes
297 { NodeClass };
298
299 if ( include_derived )
300 {
301
302 for ( std::string const & sbcname : classinfo.p_subclasses )
303 {
304 if ( treenode * sbcnode = dbaccess_guard->getnode ( sbcname ) )
305 {
306 classnodes.push_back ( sbcnode );
307 }
308 }
309 }
310
313
314 for ( treenode * clelement : classnodes )
315 {
317
318 for ( treenode * child : clelement->GetChildren() )
319 {
320 this_structure.append ( createrow ( child ) );
321 }
322 }
323
324 enabled = true;
325 return true;
326 }
327 else
328 {
329 return false;
330 }
331}
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:333
void reset(QString const &)
Definition table.cpp:406
void setheader(dunedaq::conffwk::class_t const &)
Definition table.cpp:420
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 445 of file table.cpp.

446{
447 reset ( BuildList.at ( 0 ).at ( 1 ) );
448
449 treenode * classnode = confaccessor::gethandler()->getnode ( this_class_name );
450
451 dunedaq::conffwk::class_t classinfo = dbe::config::api::info::onclass::definition (
452 this_class_name.toStdString(),
453 false );
454
455 setheader ( classinfo );
456
457 confaccessor::gethandler()->FetchMore ( classnode );
458
459 for ( const QStringList & i : BuildList )
460 {
461 QString name = i.at ( 0 );
462 treenode * node = confaccessor::gethandler()->getnode ( this_class_name, name );
463 this_structure.append ( createrow ( node ) );
464 }
465
466 enabled = false;
467 return true;
468}
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 333 of file table.cpp.

335{
336
337 dref obj = rownode->GetObject();
338
339 this_objects.append ( obj );
340
341 dunedaq::conffwk::class_t const & cdef = dbe::config::api::info::onclass::definition (
342 obj.class_name(),
343 false );
344 std::vector<dunedaq::conffwk::attribute_t> const & attributes = cdef.p_attributes;
345 std::vector<dunedaq::conffwk::relationship_t> const & relations = cdef.p_relationships;
346
347 assert ( attributes.size() + relations.size() < 1025 );
348 std::bitset<1024> hindex; // maximum number of columns to display
349
350 {
351 int column = 0;
352
353 for ( dunedaq::conffwk::attribute_t const & attr : attributes )
354 {
355 hindex.set ( column++, this_headers.contains ( QString::fromStdString ( attr.p_name ) ) );
356 }
357
358 for ( dunedaq::conffwk::relationship_t const & rel : relations )
359 {
360 hindex.set ( column++, this_headers.contains ( QString::fromStdString ( rel.p_name ) ) );
361 }
362 }
363
364 // Create the row for this object
365 QList<TableNode *> Row;
366 Row.append ( new TableNode (
367 QStringList {rownode->GetData ( 0 ).toString()},
368 QVariant(QString::fromStdString(cdef.p_description))));
369 {
370 // Loop over object values and add them to the row
371 // Values are represent as nodes ( attributes or relations ) and these contain
372 // the structured data associated either with a attribute / multi-attribute or a relation
373 std::size_t column = 0;
374
375 for ( treenode * valuenode : rownode->GetChildren() )
376 {
377 QStringList values;
378 // Every valuenode has its attributes and relations defined as its childs
379
380 if ( hindex[column++] )
381 {
382
383 for ( treenode * nodevalues : valuenode->GetChildren() )
384 {
385 // Here we need to filter such that only values corresponding to the header are kept
386 // Add only the first of values in a list of values
387 values.append ( nodevalues->GetData ( 0 ).toString() );
388 }
389
390 if ( AttributeNode * NodeAttribute = dynamic_cast<AttributeNode *> ( valuenode ) )
391 {
392 Row.append ( new TableAttributeNode ( NodeAttribute->attribute_t(), values ) );
393 }
394 else if ( RelationshipNode * NodeRelationship =
395 dynamic_cast<RelationshipNode *> ( valuenode ) )
396 {
397 Row.append ( new TableRelationshipNode ( NodeRelationship->relation_t(), values ) );
398 }
399 }
400 }
401 }
402
403 return Row;
404}
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 dref obj_desc = this_objects[index.row()];
103 tref Object = dbe::inner::dbcontroller::get ( { obj_desc.UID(), obj_desc.class_name() } );
104 if ( !confaccessor::check_file_rw ( QString::fromStdString ( Object.contained_in() ) ) ) {
105 return QBrush ( StyleUtility::FileReadOnlyForeground );
106 }
107 return QVariant();
108 }
109 }
110
111 if ( role == Qt::BackgroundRole )
112 {
113 auto attr_node = dynamic_cast<TableAttributeNode *> ( TableItem );
114 if ( attr_node != nullptr ) {
115 auto val = attr_node->GetData();
116 if (val.size() == 1 &&
117 val[0].toStdString() == attr_node->GetAttribute().p_default_value) {
119 }
121 }
122 else if ( dynamic_cast<TableRelationshipNode *> ( TableItem ) ) {
123 return QBrush (
125 }
126 else
127 {
128 dref obj_desc = this_objects[index.row()];
129 tref Object = dbe::inner::dbcontroller::get ( { obj_desc.UID(), obj_desc.class_name() } );
130 if ( !confaccessor::check_file_rw ( QString::fromStdString ( Object.contained_in() ) ) ) {
131 return QBrush ( StyleUtility::FileReadOnlyBackground );
132 }
133 }
134 }
135 }
136 return QVariant();
137}
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:495
inner::configobject::tref tref
Definition tref.hpp:35
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 231 of file table.cpp.

234{
235 Q_UNUSED ( row )
236 Q_UNUSED ( column )
237 Q_UNUSED ( parent )
238
239 bool Accept = true;
240
241 if ( action == Qt::IgnoreAction )
242 {
243 return true;
244 }
245
246 if ( !data->hasFormat ( "application/vnd.text.list" ) )
247 {
248 return false;
249 }
250
252 QByteArray encodedData = data->data ( "application/vnd.text.list" );
253
254 QDataStream stream ( &encodedData, QIODevice::ReadOnly );
255
256 QList<QStringList> newItems;
257
258 while ( !stream.atEnd() )
259 {
260 QStringList text;
261 stream >> text;
262 newItems << text;
263 }
264
265 for ( int i = 0; i < newItems.size(); ++i )
266 {
267 if ( newItems.at ( 0 ).at ( 1 ) != newItems.at ( i ).at ( 1 ) )
268 {
269 Accept = false;
270 }
271 }
272
273 if ( Accept )
274 {
275 BuildTableFromObject ( newItems );
276 emit ResetTab();
277 }
278
279 return Accept;
280}
QVariant data(type_index const &index, int role) const override
Definition table.cpp:52
bool BuildTableFromObject(QList< QStringList > BuildList)
Definition table.cpp:445

◆ flags()

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

Definition at line 203 of file table.cpp.

204{
205 if(index.isValid()) {
206 dref obj_desc = this_objects[index.row()];
207 tref Object = dbe::inner::dbcontroller::get ( { obj_desc.UID(), obj_desc.class_name() } );
208
209 if ( confaccessor::check_file_rw ( QString::fromStdString ( Object.contained_in() ) ) )
210 {
211 return ( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable |
212 Qt::ItemIsDropEnabled );
213 }
214 }
215
216 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
217}

◆ get_class_name()

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

Definition at line 480 of file table.cpp.

481{
482 return this_class_name;
483}

◆ getnode()

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

Definition at line 495 of file table.cpp.

496{
497 if ( Index.isValid() )
498 {
499 return this_structure.at ( Index.row() ).at ( Index.column() );
500 }
501
502 return nullptr;
503}

◆ GetTableObject()

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

Definition at line 470 of file table.cpp.

471{
472 return this_objects.at ( ObjectIndex ).ref();
473}

◆ GetTableObjects()

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

Definition at line 490 of file table.cpp.

491{
492 return &this_objects;
493}

◆ headerData()

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

Definition at line 180 of file table.cpp.

182{
183 if ( role == Qt::DisplayRole )
184 {
185 if ( orientation == Qt::Horizontal )
186 {
187 return this_headers.at ( section );
188 }
189 if ( orientation == Qt::Vertical )
190 {
191 return section + 1;
192 }
193 }
194
195 if ( role == Qt::FontRole )
196 {
197 return QFont ( "Helvetica [Cronyx]", 10 );
198 }
199
200 return QVariant();
201}
Missing configuration section
Message.

◆ is_built()

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

Definition at line 475 of file table.cpp.

476{
477 return enabled;
478}

◆ mimeTypes()

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

Definition at line 224 of file table.cpp.

225{
226 QStringList types;
227 types << "application/vnd.text.list";
228 return types;
229}

◆ objectsUpdated()

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

Definition at line 537 of file table.cpp.

537 {
539}
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 406 of file table.cpp.

407{
408
409 for ( auto & List : this_structure )
410 {
411 qDeleteAll ( List );
412 }
413
414 this_objects.clear();
415 this_structure.clear();
416 this_headers.clear();
417 this_class_name = cname;
418}

◆ ResetModel()

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

Definition at line 505 of file table.cpp.

506{
507 beginResetModel();
508 endResetModel();
509}

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

141{
142 if ( !index.isValid() || role != Qt::EditRole )
143 {
144 return false;
145 }
146
147 TableNode * TableItem = getnode ( index );
148
149 QStringList OldDataList = TableItem->GetData();
150
151 QStringList NewDataList = value.toStringList();
152
153 if ( NewDataList == OldDataList )
154 {
155 return false;
156 }
157
158 dref obj_desc = this_objects[index.row()];
159
161 { obj_desc.UID(), obj_desc.class_name() } );
162
163 if ( dynamic_cast<TableRelationshipNode *> ( TableItem ) )
164 {
165 TableRelationshipNode * RelationshipNode =
166 dynamic_cast<TableRelationshipNode *> ( TableItem );
167 dunedaq::conffwk::relationship_t RelationshipData = RelationshipNode->GetRelationship();
168 dbe::config::api::set::relation ( Object, RelationshipData, NewDataList );
169 }
170 else if ( dynamic_cast<TableAttributeNode *> ( TableItem ) )
171 {
172 TableAttributeNode * AttributeNode = dynamic_cast<TableAttributeNode *> ( TableItem );
173 dunedaq::conffwk::attribute_t AttributeData = AttributeNode->GetAttribute();
174 dbe::config::api::set::attribute ( Object, AttributeData, NewDataList );
175 }
176
177 return true;
178}
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 420 of file table.cpp.

421{
422 if ( !this_headers.contains ( "Object Name" ) )
423 {
424 this_headers.append ( "Object Name" );
425 }
426
427 for ( auto & i : cinfo.p_attributes )
428 {
429 if ( !this_headers.contains ( QString::fromStdString ( i.p_name ) ) )
430 {
431 this_headers.append ( QString::fromStdString ( i.p_name ) );
432 }
433 }
434
435 for ( auto & i : cinfo.p_relationships )
436 {
437 if ( !this_headers.contains ( QString::fromStdString ( i.p_name ) ) )
438 {
439 this_headers.append ( QString::fromStdString ( i.p_name ) );
440 }
441 }
442
443}

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

512{
513 QModelIndex dum;
514 this->dropMimeData ( &data, action, 0, 0, dum );
515}
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, type_index const &parent) override
Definition table.cpp:231

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

220{
221 return Qt::CopyAction;
222}

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: