Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TWebMenuItem.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Author:  Sergey Linev, GSI  29/06/2017
0002 
0003 /*************************************************************************
0004  * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers.               *
0005  * All rights reserved.                                                  *
0006  *                                                                       *
0007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0009  *************************************************************************/
0010 
0011 #ifndef ROOT_TWebMenuItem
0012 #define ROOT_TWebMenuItem
0013 
0014 #include "TString.h"
0015 #include "TClass.h"
0016 
0017 #include <string>
0018 #include <vector>
0019 #include <memory>
0020 
0021 class TClass;
0022 
0023 /** \class TWebMenuItem
0024 \ingroup webgui6
0025 
0026 Class contains info for producing menu item on the JS side.
0027 
0028 */
0029 
0030 class TWebMenuItem {
0031 protected:
0032    std::string fName;       ///<  name of the menu item
0033    std::string fTitle;      ///<  title of menu item
0034    std::string fExec;       ///< execute when item is activated
0035    std::string fClassName;  ///< class name
0036 public:
0037 
0038    TWebMenuItem(const std::string &name, const std::string &title) : fName(name), fTitle(title), fExec(), fClassName() {}
0039    TWebMenuItem(const TWebMenuItem &rhs) : fName(rhs.fName), fTitle(rhs.fTitle), fExec(rhs.fExec), fClassName(rhs.fClassName) {}
0040    virtual ~TWebMenuItem() = default;
0041 
0042    /** Set execution string with all required arguments,
0043     * which will be executed when menu item is selected  */
0044    void SetExec(const std::string &exec) { fExec = exec; }
0045 
0046    /** Set class name, to which method belongs to  */
0047    void SetClassName(const std::string &clname) { fClassName = clname; }
0048 
0049    /** Returns menu item name */
0050    const std::string &GetName() const { return fName; }
0051 
0052    /** Returns execution string for the menu item */
0053    const std::string &GetExec() const { return fExec; }
0054 };
0055 
0056 ////////////////////////////////////////////////////////////////////////////
0057 
0058 class TWebCheckedMenuItem : public TWebMenuItem {
0059 protected:
0060    bool fChecked{false}; ///<
0061 public:
0062    /** Create checked menu item  */
0063    TWebCheckedMenuItem(const std::string &name, const std::string &title, bool checked = false)
0064       : TWebMenuItem(name, title), fChecked(checked)
0065    {
0066    }
0067 
0068    /** virtual destructor need for vtable, used when vector of TMenuItem* is stored */
0069    ~TWebCheckedMenuItem() override = default;
0070 
0071    /** Set checked state for the item, default is none */
0072    void SetChecked(bool on = true) { fChecked = on; }
0073 
0074    bool IsChecked() const { return fChecked; }
0075 };
0076 
0077 ////////////////////////////////////////////////////////////////////////////
0078 
0079 class TWebMenuArgument {
0080 protected:
0081    std::string fName;     ///<  name of call argument
0082    std::string fTitle;    ///<  title of call argument
0083    std::string fTypeName; ///<  typename
0084    std::string fDefault;  ///<  default value
0085 public:
0086    TWebMenuArgument() = default;
0087 
0088    TWebMenuArgument(const std::string &name, const std::string &title, const std::string &typname,
0089                     const std::string &dflt = "")
0090       : fName(name), fTitle(title), fTypeName(typname), fDefault(dflt)
0091    {
0092    }
0093 
0094    void SetDefault(const std::string &dflt) { fDefault = dflt; }
0095 };
0096 
0097 ////////////////////////////////////////////////////////////////////////////
0098 
0099 class TWebArgsMenuItem : public TWebMenuItem {
0100 protected:
0101    std::vector<TWebMenuArgument> fArgs;
0102 
0103 public:
0104 
0105    TWebArgsMenuItem(const std::string &name, const std::string &title) : TWebMenuItem(name, title) {}
0106 
0107    /** virtual destructor need for vtable, used when vector of TMenuItem* is stored */
0108    ~TWebArgsMenuItem() override = default;
0109 
0110    std::vector<TWebMenuArgument> &GetArgs() { return fArgs; }
0111 
0112 };
0113 
0114 ///////////////////////////////////////////////////////////////////////
0115 
0116 class TWebMenuItems {
0117 protected:
0118    std::string fId;                                   ///< object identifier
0119    std::vector<std::unique_ptr<TWebMenuItem>> fItems; ///< list of items in the menu
0120 public:
0121    TWebMenuItems() = default;
0122    TWebMenuItems(const std::string &snapid) : fId(snapid) {}
0123 
0124    void Add(TWebMenuItem *item) { fItems.emplace_back(item); }
0125 
0126    void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec, TClass *cl = nullptr)
0127    {
0128       TWebMenuItem *item = new TWebMenuItem(name, title);
0129       item->SetExec(exec);
0130       if (cl) item->SetClassName(cl->GetName());
0131       Add(item);
0132    }
0133 
0134    void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle, TClass *cl = nullptr)
0135    {
0136       TWebCheckedMenuItem *item = new TWebCheckedMenuItem(name, title, checked);
0137       item->SetExec(toggle);
0138       if (cl) item->SetClassName(cl->GetName());
0139       Add(item);
0140    }
0141 
0142    std::size_t Size() const { return fItems.size(); }
0143 
0144    void PopulateObjectMenu(void *obj, TClass *cl);
0145 };
0146 
0147 #endif