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_datumgetnode (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 treenodegetnode (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 21 of file tree.hpp.

Member Typedef Documentation

◆ type_datum

Constructor & Destructor Documentation

◆ ~tree()

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

Definition at line 29 of file tree.cpp.

30{}

◆ tree()

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

Definition at line 13 of file tree.cpp.

14 : QAbstractItemModel ( parent ),
16{
17 confaccessor::gethandler()->root = new dbe::treenode ( Headers );
18
19 for ( std::string const & aclass : dbe::config::api::info::onclass::allnames <
20 std::vector<std::string >> () )
21 {
22 new ClassNode ( dbe::config::api::info::onclass::definition ( aclass, false ),
24 }
25
27}
static cptr< datahandler > gethandler()
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
bool abstract_classes_selectable
Definition tree.hpp:86
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 {
201 treenode * ParentNode = getnode ( parent );
202 return ( !ParentNode->GetWasFetched() );
203 }
204
205 return false;
206}
type_datum * getnode(const type_index &index) const override
Definition tree.cpp:309

◆ columnCount()

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

Definition at line 79 of file tree.cpp.

80{
81 if ( parent.isValid() )
82 {
83 dbe::treenode * DataNode = getnode ( parent );
84
85 return DataNode->ColumnCount();
86 }
87 else
88 {
89 return confaccessor::gethandler()->root->ColumnCount();
90 }
91}
int ColumnCount() const
Definition treenode.cpp:120

◆ data()

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

Definition at line 116 of file tree.cpp.

117{
118 if ( index.isValid() )
119 {
120 switch ( role )
121 {
122 case Qt::ForegroundRole:
123 if ( ObjectNode * onode = dynamic_cast<ObjectNode *> ( getnode ( index ) ) )
124 {
125 try
126 {
127 tref const & obj = onode->GetObject();
128
129 if ( confaccessor::check_file_rw ( QString::fromStdString ( obj.contained_in() ) ) )
130 {
131 return QVariant ( QColor ( Qt::blue ) );
132 }
133 else
134 {
135 return QVariant ( QColor ( Qt::darkGray ) );
136 }
137 }
138 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
139 {
140 // nothing to do the onode refers to a removed object and has not yet been removed
141 return QVariant();
142 }
143 }
144
145 break;
146
147 case Qt::DisplayRole:
148 case Qt::DecorationRole:
149 return getnode ( index )->GetData ( index.column(), role );
150 }
151 }
152
153 return QVariant();
154}
static bool check_file_rw(const QString &FileName)
type_index index(int row, int column, const type_index &parent) const override
Definition tree.cpp:32
virtual QVariant GetData(const int Column, int role=Qt::DisplayRole) const
Definition treenode.cpp:58
inner::configobject::tref tref
Definition tref.hpp:30

◆ 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 {
212 treenode * ParentNode = getnode ( parent );
213
214 if ( !ParentNode->GetWasFetched() )
215 {
216 insertRows ( 0, 0, parent );
217 ParentNode->SetWasFetched ( true );
218 }
219 }
220}
bool insertRows(int position, int rows, const type_index &parent) override
Definition tree.cpp:167

◆ flags()

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

Definition at line 93 of file tree.cpp.

94{
95 treenode * node = getnode ( index );
96
97 if ( ClassNode * classnode = dynamic_cast<ClassNode *> ( node ) )
98 {
99 dunedaq::conffwk::class_t classinfo = classnode->GetClassInfo();
100
101 if ( classinfo.p_abstract )
102 {
103 return
105 ( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) : ( Qt::ItemIsSelectable );
106 }
107 else
108 {
109 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
110 }
111 }
112
113 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
114}

◆ getindex()

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

Definition at line 279 of file tree.cpp.

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

◆ getnode()

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

Definition at line 309 of file tree.cpp.

311{
312 if ( index.isValid() )
313 {
314 return static_cast<treenode *> ( index.internalPointer() );
315 }
316
317 return confaccessor::gethandler()->root;
318}

◆ hasChildren()

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

Definition at line 222 of file tree.cpp.

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

◆ headerData()

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

Definition at line 156 of file tree.cpp.

158{
159 if ( ( orientation == Qt::Horizontal ) && ( role == Qt::DisplayRole ) )
160 {
161 return confaccessor::gethandler()->root->GetData ( section );
162 }
163
164 return QVariant();
165}

◆ index()

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

Definition at line 32 of file tree.cpp.

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

◆ insertRows()

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

Definition at line 167 of file tree.cpp.

168{
169 if ( ClassNode * onode = dynamic_cast<ClassNode *> ( getnode ( parent ) ) )
170 {
171 rows = onode->ChildCount();
172
173 beginInsertRows ( parent, position, position + rows - 1 );
174
175 std::string const & classname = onode->GetData (
176 static_cast<int> ( tablepositions::classname ) ).toString().toStdString();
177
178 std::vector<tref> const & objects = config::api::info::onclass::objects ( classname,
179 false );
180
181 for ( auto const & i : objects )
182 {
183 new ObjectNode ( i, false, onode );
184 emit ObjectFile(QString::fromStdString(i.contained_in()));
185 }
186
187 endInsertRows();
188
189 return true;
190 }
191 else
192 {
193 return false;
194 }
195}
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 43 of file tree.hpp.

44 {
45 return i;
46 }

◆ 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 {
259 if ( index.isValid() && index.column() == 0 )
260 {
261 QStringList Text;
262 treenode * NodeObject = getnode ( index );
263
264 tref Object = NodeObject->GetObject();
265 QString ObjectUid = QString::fromStdString ( Object.UID() );
266 QString ObjectClassName = QString::fromStdString ( Object.class_name() );
267
268 Text.append ( ObjectUid );
269 Text.append ( ObjectClassName );
270
271 stream << Text;
272 }
273 }
274
275 mimeData->setData ( "application/vnd.text.list", encodedData );
276 return mimeData;
277}
QMimeData * mimeData(const QModelIndexList &indexes) const override
Definition tree.cpp:250

◆ mimeTypes()

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

Definition at line 243 of file tree.cpp.

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

◆ ObjectFile

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

◆ objectsUpdated()

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

Definition at line 379 of file tree.cpp.

379 {
381}
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 {
52 dbe::treenode * up = getnode ( child )->GetParent();
53
54 if ( up != confaccessor::gethandler()->root )
55 {
56 return createIndex ( up->GetRow(), 0, up );
57 }
58 }
59
60 return QModelIndex();
61}
treenode * GetParent() const
Definition treenode.cpp:110
int GetRow() const
Definition treenode.cpp:80

◆ ResetModel()

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

Definition at line 303 of file tree.cpp.

304{
305 beginResetModel();
306 endResetModel();
307}

◆ rowCount()

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

Definition at line 63 of file tree.cpp.

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

◆ setData()

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

Definition at line 233 of file tree.cpp.

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

◆ 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 373 of file tree.cpp.

374{
376 ResetModel();
377}
void ResetModel()
Definition tree.cpp:303

Member Data Documentation

◆ abstract_classes_selectable

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

Definition at line 86 of file tree.hpp.


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