source: tags/ms_r16q2/SL/ITEMS/item_sel_list.h

Last change on this file was 14960, checked in by westram, 8 years ago
  • mark possible optimization
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1// ==================================================================== //
2//                                                                      //
3//   File      : item_sel_list.h                                        //
4//   Purpose   : selection lists for items (ItemSelector)               //
5//                                                                      //
6//                                                                      //
7// Coded by Ralf Westram (coder@reallysoft.de) in May 2005              //
8// Copyright Department of Microbiology (Technical University Munich)   //
9//                                                                      //
10// Visit our web site at: http://www.arb-home.de/                       //
11//                                                                      //
12// ==================================================================== //
13
14#ifndef ITEM_SEL_LIST_H
15#define ITEM_SEL_LIST_H
16
17#ifndef AW_SELECT_HXX
18#include <aw_select.hxx>
19#endif
20#ifndef ITEMS_H
21#include "items.h"
22#endif
23#ifndef _GLIBCXX_STRING
24#include <string>
25#endif
26
27#define PSEUDO_FIELD_ANY_FIELD  "[any field]"
28#define PSEUDO_FIELD_ALL_FIELDS "[all fields]"
29
30enum SelectableFields {
31    SF_STANDARD  = 0,  // normal fields
32    SF_PSEUDO    = 1,  // pseudo-fields (see defines above)
33    SF_HIDDEN    = 2,  // fields hidden by user
34    SF_ALLOW_NEW = 4,  // allow on-the-fly creation of new fields
35    SF_SHOW_TYPE = 8,  // show fieldtype prefix
36};
37
38
39CONSTEXPR long FIELD_FILTER_STRING           = (1<<GB_STRING);
40CONSTEXPR long FIELD_FILTER_STRING_WRITEABLE = (1<<GB_STRING);
41CONSTEXPR long FIELD_FILTER_INT_WRITEABLE    = (1<<GB_STRING) | (1<<GB_INT);
42CONSTEXPR long FIELD_FILTER_BYTE_WRITEABLE   = (1<<GB_STRING) | (1<<GB_INT) | (1<<GB_BYTE) | (1<<GB_FLOAT);
43CONSTEXPR long FIELD_FILTER_FLOAT_WRITEABLE  = (1<<GB_STRING) | (1<<GB_FLOAT);
44
45CONSTEXPR long FIELD_FILTER_STRING_READABLE = (1<<GB_BYTE)|(1<<GB_INT)|(1<<GB_FLOAT)|(1<<GB_STRING)|(1<<GB_BITS)|(1<<GB_LINK); // as supported by GB_read_as_string()
46
47CONSTEXPR long FIELD_UNFILTERED       = -1L;                             // any field or container
48CONSTEXPR long FIELD_FILTER_ANY_FIELD = (FIELD_UNFILTERED ^ (1<<GB_DB)); // no containers
49
50CONSTEXPR long FIELD_FILTER_NDS = FIELD_FILTER_STRING_READABLE;
51
52
53class Itemfield_Selection : public AW_DB_selection { // derived from a Noncopyable
54    long             type_filter;
55    SelectableFields field_filter;
56    ItemSelector&    selector;
57
58    bool shall_display_type(GB_TYPES key_type) const { return type_filter & (1 << key_type); }
59
60public:
61    Itemfield_Selection(AW_selection_list *sellist_,
62                        GBDATA            *gb_key_data,
63                        long               type_filter_,
64                        SelectableFields   field_filter_,
65                        ItemSelector&      selector_);
66
67    void fill() OVERRIDE;
68
69    ItemSelector& get_selector() const { return selector; }
70    long get_type_filter() const { return type_filter; }
71};
72
73class FieldSelDef {
74    std::string       awar_name;
75    std::string       purpose;
76    GBDATA           *gb_main;
77    ItemSelector&     selector; // @@@ gb_main + selector = BoundItemSel!
78    long              type_filter;
79    SelectableFields  field_filter;
80
81public:
82    FieldSelDef(const char *awar_name_, GBDATA *gb_main_, ItemSelector& selector_, long type_filter_, const char *purpose_ = "field", SelectableFields field_filter_ = SF_STANDARD)
83    /*! parameter collection for itemfield-selections
84     * @param awar_name_           the name of the awar bound to the selection list
85     * @param gb_main_             the database
86     * @param selector_            describes the item type, for which fields are shown
87     * @param type_filter_         is a bitstring which controls what types will be shown in the selection list (several filters are predefined: 'FIELD_FILTER_...', FIELD_UNFILTERED)
88     * @param purpose_             describes purpose of field (defaults to 'field'; appears in popup-title and error-messages)
89     * @param field_filter_        controls if pseudo-fields and/or hidden fields are added and whether new fields are allowed (defaults to SF_STANDARD)
90     */
91        : awar_name(awar_name_),
92          purpose(purpose_),
93          gb_main(gb_main_),
94          selector(selector_),
95          type_filter(type_filter_),
96          field_filter(field_filter_)
97    {}
98    FieldSelDef(const FieldSelDef& other)
99        : awar_name(other.awar_name),
100          purpose(other.purpose),
101          gb_main(other.gb_main),
102          selector(other.selector),
103          type_filter(other.type_filter),
104          field_filter(other.field_filter)
105    {}
106    DECLARE_ASSIGNMENT_OPERATOR(FieldSelDef);
107
108    const std::string& get_awarname() const { return awar_name; }
109    const std::string& get_described_field() const { return purpose; }
110    long get_type_filter() const { return type_filter; }
111    SelectableFields get_field_filter() const { return field_filter; }
112    GBDATA *get_gb_main() const { return gb_main; }
113    ItemSelector& get_itemtype() const { return selector; }
114
115    // for internal use only:
116    bool new_fields_allowed() const { return field_filter & SF_ALLOW_NEW; }
117    Itemfield_Selection *build_sel(AW_selection_list *from_sellist) const;
118    bool matches4reuse(const FieldSelDef& other) const;
119};
120
121enum FailIfField {
122    FIF_NAME_SELECTED     = 1, // fail if 'name' field selected
123    FIF_NO_FIELD_SELECTED = 2, // fail if NO_FIELD_SELECTED
124
125    // use-cases:
126    FIF_STANDARD   = FIF_NAME_SELECTED|FIF_NO_FIELD_SELECTED,
127    FIF_ALLOW_NONE = FIF_STANDARD^FIF_NO_FIELD_SELECTED,
128};
129
130Itemfield_Selection *create_itemfield_selection_list(  AW_window *aws, const FieldSelDef& selDef, const char *at);
131void                 create_itemfield_selection_button(AW_window *aws, const FieldSelDef& selDef, const char *at);
132const char          *prepare_and_get_selected_itemfield(AW_root *awr, const char *awar_name, GBDATA *gb_main, const ItemSelector& itemtype, FailIfField failIf = FIF_STANDARD);
133const char          *get_itemfield_type_awarname(const char *itemfield_awarname);
134
135enum RescanMode {
136    RESCAN_REFRESH  = 1, // scan database for unregistered/unused fields and update the field list
137    RESCAN_SHOW_ALL = 2, // unhide all hidden fields
138};
139
140// @@@ generalize (use BoundItemSel)
141
142void species_field_selection_list_rescan(GBDATA *gb_main, RescanMode mode);
143void gene_field_selection_list_rescan   (GBDATA *gb_main, RescanMode mode);
144
145void species_field_selection_list_unhide_all_cb(AW_window*, GBDATA *gb_main);
146void species_field_selection_list_update_cb    (AW_window*, GBDATA *gb_main);
147
148void gene_field_selection_list_unhide_all_cb(AW_window*, GBDATA *gb_main);
149void gene_field_selection_list_update_cb    (AW_window*, GBDATA *gb_main);
150
151void experiment_field_selection_list_unhide_all_cb(AW_window*, GBDATA *gb_main);
152void experiment_field_selection_list_update_cb    (AW_window*, GBDATA *gb_main);
153
154#else
155#error item_sel_list.h included twice
156#endif // ITEM_SEL_LIST_H
157
Note: See TracBrowser for help on using the repository browser.