Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RElement.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#ifndef ROOT7_Browsable_RElement
10#define ROOT7_Browsable_RElement
11
13
14#include <string>
15#include <vector>
16
17namespace ROOT {
18namespace Experimental {
19namespace Browsable {
20
21using RElementPath_t = std::vector<std::string>;
22
23class RLevelIter;
24
25class RItem;
26
27/** \class RElement
28\ingroup rbrowser
29\brief Basic element of browsable hierarchy. Provides access to data, creates iterator if any
30\author Sergey Linev <S.Linev@gsi.de>
31\date 2019-10-14
32\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
33*/
34
35class RElement {
36public:
37
39 kNone, ///< not recognized
40 kText, ///< "text" - plain text for code editor
41 kImage, ///< "image64" - base64 for supported image formats (png/gif/gpeg)
42 kPng, ///< "png" - plain png binary code, returned inside std::string
43 kJpeg, ///< "jpg" or "jpeg" - plain jpg binary code, returned inside std::string
44 kJson, ///< "json" representation of object, can be used in code editor
45 kFileName ///< "filename" - file name if applicable
46 };
47
48 static EContentKind GetContentKind(const std::string &kind);
49
50 /** Possible actions on double-click */
52 kActNone, ///< do nothing
53 kActBrowse, ///< just browse (expand) item
54 kActEdit, ///< can provide data for text editor
55 kActImage, ///< can be shown in image viewer, can provide image
56 kActDraw6, ///< can be drawn inside ROOT6 canvas
57 kActDraw7, ///< can be drawn inside ROOT7 canvas
58 kActCanvas, ///< indicate that it is canvas and should be drawn directly
59 kActTree, ///< can be shown in tree viewer
60 kActGeom ///< can be shown in geometry viewer
61 };
62
63 virtual ~RElement() = default;
64
65 /** Name of browsable, must be provided in derived classes */
66 virtual std::string GetName() const = 0;
67
68 /** Checks if element name match to provided value */
69 virtual bool MatchName(const std::string &name) const { return name == GetName(); }
70
71 /** Title of browsable (optional) */
72 virtual std::string GetTitle() const { return ""; }
73
74 /** Create iterator for childs elements if any */
75 virtual std::unique_ptr<RLevelIter> GetChildsIter();
76
77 /** Returns element content, depends from kind. Can be "text" or "image64" or "json" */
78 virtual std::string GetContent(const std::string & = "text");
79
80 /** Access object */
81 virtual std::unique_ptr<RHolder> GetObject() { return nullptr; }
82
83 /** Check if element contains provided pointer */
84 virtual bool IsObject(void *) { return false; }
85
86 /** Check if element can have childs */
87 virtual bool IsFolder() const { return false; }
88
89 virtual int GetNumChilds();
90
91 /** Check if element still contains valid content */
92 virtual bool CheckValid() { return true; }
93
94 /** Get default action */
95 virtual EActionKind GetDefaultAction() const { return kActNone; }
96
97 /** Check if want to perform action */
98 virtual bool IsCapable(EActionKind action) const { return action == GetDefaultAction(); }
99
100 /** Should item representing element be expand by default */
101 virtual bool IsExpandByDefault() const { return false; }
102
103 /** Select element as active */
104 virtual bool cd() { return false; }
105
106 virtual std::unique_ptr<RItem> CreateItem() const;
107
108 static std::shared_ptr<RElement> GetSubElement(std::shared_ptr<RElement> &elem, const RElementPath_t &path);
109
110 static RElementPath_t ParsePath(const std::string &str);
111
112 static int ComparePaths(const RElementPath_t &path1, const RElementPath_t &path2);
113
114 static std::string GetPathAsString(const RElementPath_t &path);
115
116 static int ExtractItemIndex(std::string &name);
117};
118
119} // namespace Browsable
120} // namespace Experimental
121} // namespace ROOT
122
123#endif
char name[80]
Definition TGX11.cxx:110
Basic element of browsable hierarchy.
Definition RElement.hxx:35
virtual bool MatchName(const std::string &name) const
Checks if element name match to provided value.
Definition RElement.hxx:69
@ kFileName
"filename" - file name if applicable
Definition RElement.hxx:45
@ kJson
"json" representation of object, can be used in code editor
Definition RElement.hxx:44
@ kImage
"image64" - base64 for supported image formats (png/gif/gpeg)
Definition RElement.hxx:41
@ kJpeg
"jpg" or "jpeg" - plain jpg binary code, returned inside std::string
Definition RElement.hxx:43
@ kPng
"png" - plain png binary code, returned inside std::string
Definition RElement.hxx:42
@ kText
"text" - plain text for code editor
Definition RElement.hxx:40
static EContentKind GetContentKind(const std::string &kind)
Find item with specified name Default implementation, should work for all.
Definition RElement.cxx:51
virtual std::string GetName() const =0
Name of browsable, must be provided in derived classes.
virtual bool IsCapable(EActionKind action) const
Check if want to perform action.
Definition RElement.hxx:98
virtual bool IsExpandByDefault() const
Should item representing element be expand by default.
Definition RElement.hxx:101
virtual std::string GetContent(const std::string &="text")
Returns element content, depends from kind.
Definition RElement.cxx:89
virtual std::unique_ptr< RLevelIter > GetChildsIter()
Create iterator for childs elements if any.
Definition RElement.cxx:29
virtual int GetNumChilds()
Returns number of childs By default creates iterator and iterates over all items.
Definition RElement.cxx:38
virtual bool CheckValid()
Check if element still contains valid content.
Definition RElement.hxx:92
static int ExtractItemIndex(std::string &name)
Extract index from name Index coded by client with ###<indx>$$$ suffix Such coding used by browser to...
Definition RElement.cxx:177
static int ComparePaths(const RElementPath_t &path1, const RElementPath_t &path2)
Compare two paths, Returns number of elements matches in both paths.
Definition RElement.cxx:144
static std::string GetPathAsString(const RElementPath_t &path)
Converts element path back to string.
Definition RElement.cxx:159
virtual bool cd()
Select element as active.
Definition RElement.hxx:104
static std::shared_ptr< RElement > GetSubElement(std::shared_ptr< RElement > &elem, const RElementPath_t &path)
Returns sub element.
Definition RElement.cxx:68
EActionKind
Possible actions on double-click.
Definition RElement.hxx:51
@ kActEdit
can provide data for text editor
Definition RElement.hxx:54
@ kActCanvas
indicate that it is canvas and should be drawn directly
Definition RElement.hxx:58
@ kActBrowse
just browse (expand) item
Definition RElement.hxx:53
@ kActGeom
can be shown in geometry viewer
Definition RElement.hxx:60
@ kActDraw7
can be drawn inside ROOT7 canvas
Definition RElement.hxx:57
@ kActTree
can be shown in tree viewer
Definition RElement.hxx:59
@ kActImage
can be shown in image viewer, can provide image
Definition RElement.hxx:55
@ kActDraw6
can be drawn inside ROOT6 canvas
Definition RElement.hxx:56
virtual std::unique_ptr< RHolder > GetObject()
Access object.
Definition RElement.hxx:81
virtual bool IsFolder() const
Check if element can have childs.
Definition RElement.hxx:87
virtual EActionKind GetDefaultAction() const
Get default action.
Definition RElement.hxx:95
virtual std::unique_ptr< RItem > CreateItem() const
Returns item with element description.
Definition RElement.cxx:104
static RElementPath_t ParsePath(const std::string &str)
Parse string path to produce RElementPath_t One should avoid to use string pathes as much as possible...
Definition RElement.cxx:115
virtual bool IsObject(void *)
Check if element contains provided pointer.
Definition RElement.hxx:84
virtual std::string GetTitle() const
Title of browsable (optional)
Definition RElement.hxx:72
Representation of single item in the browser.
Definition RItem.hxx:24
Iterator over single level hierarchy like any array, keys list, ...
std::vector< std::string > RElementPath_t
Definition RElement.hxx:21
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.