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 26 of file tree.hpp.

Member Typedef Documentation

◆ type_datum

Definition at line 37 of file tree.hpp.

Constructor & Destructor Documentation

◆ ~tree()

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

Definition at line 34 of file tree.cpp.

35{}

◆ tree()

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

Definition at line 18 of file tree.cpp.

19 : QAbstractItemModel ( parent ),
21{
22 confaccessor::gethandler()->root = new dbe::treenode ( Headers );
23
24 for ( std::string const & aclass : dbe::config::api::info::onclass::allnames <
25 std::vector<std::string >> () )
26 {
27 new ClassNode ( dbe::config::api::info::onclass::definition ( aclass, false ),
29 }
30
32}
static cptr< datahandler > gethandler()
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
bool abstract_classes_selectable
Definition tree.hpp:91
type_index parent(const type_index &child) const override
Definition tree.cpp:53

Member Function Documentation

◆ canFetchMore()

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

Definition at line 209 of file tree.cpp.

210{
211 if ( parent.isValid() )
212 {
213 treenode * ParentNode = getnode ( parent );
214 return ( !ParentNode->GetWasFetched() );
215 }
216
217 return false;
218}
type_datum * getnode(const type_index &index) const override
Definition tree.cpp:321

◆ columnCount()

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

Definition at line 84 of file tree.cpp.

85{
86 if ( parent.isValid() )
87 {
88 dbe::treenode * DataNode = getnode ( parent );
89
90 return DataNode->ColumnCount();
91 }
92 else
93 {
94 return confaccessor::gethandler()->root->ColumnCount();
95 }
96}
int ColumnCount() const
Definition treenode.cpp:126

◆ data()

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

Definition at line 121 of file tree.cpp.

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

◆ fetchMore()

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

Definition at line 220 of file tree.cpp.

221{
222 if ( parent.isValid() )
223 {
224 treenode * ParentNode = getnode ( parent );
225
226 if ( !ParentNode->GetWasFetched() )
227 {
228 insertRows ( 0, 0, parent );
229 ParentNode->SetWasFetched ( true );
230 }
231 }
232}
bool insertRows(int position, int rows, const type_index &parent) override
Definition tree.cpp:179

◆ flags()

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

Definition at line 98 of file tree.cpp.

99{
100 treenode * node = getnode ( index );
101
102 if ( ClassNode * classnode = dynamic_cast<ClassNode *> ( node ) )
103 {
104 dunedaq::conffwk::class_t classinfo = classnode->GetClassInfo();
105
106 if ( classinfo.p_abstract )
107 {
108 return
110 ( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) : ( Qt::ItemIsSelectable );
111 }
112 else
113 {
114 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
115 }
116 }
117
118 return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
119}

◆ getindex()

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

Definition at line 291 of file tree.cpp.

293{
294 for ( int i = 0; i < rowCount ( RootIndex ); ++i )
295 {
296 QModelIndex ChildIndex = index ( i, 0, RootIndex );
297 treenode * ChildNode = getnode ( ChildIndex );
298
299 if ( NodeItem == ChildNode )
300 {
301 return ChildIndex;
302 }
303
304 QModelIndex ChildChildIndex = getindex ( NodeItem, ChildIndex );
305
306 if ( ChildChildIndex.isValid() )
307 {
308 return ChildChildIndex;
309 }
310 }
311
312 return QModelIndex();
313}
type_index getindex(treenode *NodeItem, type_index const &RootIndex=QModelIndex()) const
Definition tree.cpp:291
int rowCount(const type_index &parent) const override
Definition tree.cpp:68

◆ getnode()

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

Definition at line 321 of file tree.cpp.

323{
324 if ( index.isValid() )
325 {
326 return static_cast<treenode *> ( index.internalPointer() );
327 }
328
329 return confaccessor::gethandler()->root;
330}

◆ hasChildren()

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

Definition at line 234 of file tree.cpp.

235{
236 if ( parent.isValid() )
237 {
238 treenode * ParentNode = getnode ( parent );
239 return ( ParentNode->GetHasStructure() );
240 }
241
242 return true;
243}

◆ headerData()

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

Definition at line 168 of file tree.cpp.

170{
171 if ( ( orientation == Qt::Horizontal ) && ( role == Qt::DisplayRole ) )
172 {
173 return confaccessor::gethandler()->root->GetData ( section );
174 }
175
176 return QVariant();
177}

◆ index()

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

Definition at line 37 of file tree.cpp.

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

◆ insertRows()

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

Definition at line 179 of file tree.cpp.

180{
181 if ( ClassNode * onode = dynamic_cast<ClassNode *> ( getnode ( parent ) ) )
182 {
183 rows = onode->ChildCount();
184
185 beginInsertRows ( parent, position, position + rows - 1 );
186
187 std::string const & classname = onode->GetData (
188 static_cast<int> ( tablepositions::classname ) ).toString().toStdString();
189
190 std::vector<tref> const & objects = config::api::info::onclass::objects ( classname,
191 false );
192
193 for ( auto const & i : objects )
194 {
195 new ObjectNode ( i, false, onode );
196 emit ObjectFile(QString::fromStdString(i.contained_in()));
197 }
198
199 endInsertRows();
200
201 return true;
202 }
203 else
204 {
205 return false;
206 }
207}
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 48 of file tree.hpp.

49 {
50 return i;
51 }

◆ mimeData()

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

Definition at line 262 of file tree.cpp.

263{
264 QMimeData * mimeData = new QMimeData();
265 QByteArray encodedData;
266
267 QDataStream stream ( &encodedData, QIODevice::WriteOnly );
268
269 foreach ( QModelIndex index, indexes )
270 {
271 if ( index.isValid() && index.column() == 0 )
272 {
273 QStringList Text;
274 treenode * NodeObject = getnode ( index );
275
276 tref Object = NodeObject->GetObject();
277 QString ObjectUid = QString::fromStdString ( Object.UID() );
278 QString ObjectClassName = QString::fromStdString ( Object.class_name() );
279
280 Text.append ( ObjectUid );
281 Text.append ( ObjectClassName );
282
283 stream << Text;
284 }
285 }
286
287 mimeData->setData ( "application/vnd.text.list", encodedData );
288 return mimeData;
289}
QMimeData * mimeData(const QModelIndexList &indexes) const override
Definition tree.cpp:262

◆ mimeTypes()

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

Definition at line 255 of file tree.cpp.

256{
257 QStringList types;
258 types << "application/vnd.text.list";
259 return types;
260}

◆ ObjectFile

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

◆ objectsUpdated()

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

Definition at line 391 of file tree.cpp.

391 {
393}
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 53 of file tree.cpp.

54{
55 if ( child.isValid() )
56 {
57 dbe::treenode * up = getnode ( child )->GetParent();
58
59 if ( up != confaccessor::gethandler()->root )
60 {
61 return createIndex ( up->GetRow(), 0, up );
62 }
63 }
64
65 return QModelIndex();
66}
treenode * GetParent() const
Definition treenode.cpp:116
int GetRow() const
Definition treenode.cpp:86

◆ ResetModel()

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

Definition at line 315 of file tree.cpp.

316{
317 beginResetModel();
318 endResetModel();
319}

◆ rowCount()

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

Definition at line 68 of file tree.cpp.

69{
70 dbe::treenode * ParentNode;
71
72 if ( !parent.isValid() )
73 {
74 ParentNode = confaccessor::gethandler()->getnode();
75 }
76 else
77 {
78 ParentNode = getnode ( parent );
79 }
80
81 return ParentNode->ChildCount();
82}
int ChildCount() const
Definition treenode.cpp:121

◆ setData()

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

Definition at line 245 of file tree.cpp.

247{
248 Q_UNUSED ( index )
249 Q_UNUSED ( value )
250 Q_UNUSED ( role )
251
252 return true;
253}

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

386{
388 ResetModel();
389}
void ResetModel()
Definition tree.cpp:315

Member Data Documentation

◆ abstract_classes_selectable

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

Definition at line 91 of file tree.hpp.


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