KiCad PCB EDA Suite
Loading...
Searching...
No Matches
properties_panel.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 CERN
5 * @author Maciej Suminski <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20#ifndef PROPERTIES_PANEL_H
21#define PROPERTIES_PANEL_H
22
23#include <wx/panel.h>
24#include <wx/propgrid/propgrid.h>
25
27#include <vector>
28#include <memory>
29#include <functional>
30
31class EDA_BASE_FRAME;
32class EDA_ITEM;
33class SELECTION;
34class PROPERTY_BASE;
35class BITMAP_BUTTON;
36class wxPropertyGridEvent;
37class wxStaticText;
38
46
47class PROPERTIES_PANEL : public wxPanel
48{
50
51public:
52 PROPERTIES_PANEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame );
53 virtual ~PROPERTIES_PANEL();
54
55 virtual void UpdateData() = 0;
56
57 virtual void AfterCommit() {}
58
59 wxPropertyGrid* GetPropertyGrid()
60 {
61 return m_grid;
62 }
63
64 int PropertiesCount() const
65 {
66 return m_displayed.size();
67 }
68
69 const std::vector<PROPERTY_BASE*>& Properties() const
70 {
71 return m_displayed;
72 }
73
75
76 void SetSplitterProportion( float aProportion );
78
79protected:
85 virtual void rebuildProperties( const SELECTION& aSelection );
86
87 virtual wxPGProperty* createPGProperty( const PROPERTY_BASE* aProperty ) const = 0;
88
89 // Event handlers
90 virtual void valueChanging( wxPropertyGridEvent& aEvent ) { aEvent.Skip(); }
91 virtual void valueChanged( wxPropertyGridEvent& aEvent ) { aEvent.Skip(); }
92 void onCharHook( wxKeyEvent& aEvent );
93 void onShow( wxShowEvent& aEvent );
94
95 virtual void OnLanguageChanged( wxCommandEvent& aEvent );
96
97 virtual bool isKeyEditable( const wxPGProperty* aPGProp ) const { return false; }
98 virtual bool isKeyNameInUse( const wxString& aName ) const { return false; }
99 virtual void onKeyRenamed( const wxString& aOldName, const wxString& aNewName ) {}
100
101 virtual void onLabelEditBegin( wxPropertyGridEvent& aEvent );
102 virtual void onLabelEditEnding( wxPropertyGridEvent& aEvent );
103
104 virtual bool buildContextMenu( wxMenu& aMenu, wxPGProperty* aPGProp ) { return false; }
105 virtual void onNewItemLeftBlank( const wxString& aKey ) {}
106 void onRightClick( wxPropertyGridEvent& aEvent );
107
108 void beginLabelEdit( const wxString& aKey, bool aStartBlank = false );
109
112
118 virtual bool getItemValue( EDA_ITEM* aItem, PROPERTY_BASE* aProperty, wxVariant& aValue );
119
129 bool extractValueAndWritability( const SELECTION& aSelection, const wxString& aPropName,
130 wxVariant& aValue, bool& aWritable, wxPGChoices& aChoices );
131
148 void addCategoryButton( const wxString& aGroupKey, const wxString& aTooltip,
149 BITMAPS aBitmap, std::function<void()> aAction,
150 std::function<bool()> aEnableFunc = nullptr,
151 bool aForceCategory = false );
152
155
157 void hideCategoryButtons();
158
160
162 wxPGProperty* categoryForGroup( const wxString& aGroupKey ) const;
163
164 wxStaticText* m_caption;
165
166public:
168
169protected:
170 std::vector<PROPERTY_BASE*> m_displayed; // no ownership of pointers
171 wxPropertyGrid* m_grid;
173
176
178
180
182 {
184 wxString groupKey;
185 std::function<void()> action;
186 std::function<bool()> enableFunc;
187
190 bool forceCategory = false;
191 };
192
193 std::vector<CATEGORY_BUTTON> m_categoryButtons;
194
197
200};
201
202
212
213#endif /* PROPERTIES_PANEL_H */
BITMAPS
A list of all bitmap identifiers.
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
The base frame for deriving all KiCad main window classes.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
wxString m_contextMenuPropertyName
float m_splitter_key_proportion
Proportion of the grid column splitter that is used for the key column (0.0 - 1.0)
virtual bool isKeyEditable(const wxPGProperty *aPGProp) const
virtual void onKeyRenamed(const wxString &aOldName, const wxString &aNewName)
PROPERTIES_PANEL(wxWindow *aParent, EDA_BASE_FRAME *aFrame)
virtual void valueChanging(wxPropertyGridEvent &aEvent)
wxPropertyGrid * m_grid
float SplitterProportion() const
wxString m_editingOriginalLabel
const std::vector< PROPERTY_BASE * > & Properties() const
virtual void onLabelEditEnding(wxPropertyGridEvent &aEvent)
virtual bool buildContextMenu(wxMenu &aMenu, wxPGProperty *aPGProp)
void beginLabelEdit(const wxString &aKey, bool aStartBlank=false)
wxPropertyGrid * GetPropertyGrid()
virtual bool isKeyNameInUse(const wxString &aName) const
bool m_resolvingPendingKey
True while settling a pending label edit synchronously (see settlePendingLabelEdit).
wxStaticText * m_caption
void SetSplitterProportion(float aProportion)
void onRightClick(wxPropertyGridEvent &aEvent)
int PropertiesCount() const
void settlePendingLabelEdit()
Synchronously ends any in-progress label edit; potentially canceling a newly added row.
std::vector< PROPERTY_BASE * > m_displayed
virtual void AfterCommit()
virtual void OnLanguageChanged(wxCommandEvent &aEvent)
virtual void UpdateData()=0
friend class PROPERTIES_PANEL_GRID
virtual void onLabelEditBegin(wxPropertyGridEvent &aEvent)
virtual void valueChanged(wxPropertyGridEvent &aEvent)
virtual void onNewItemLeftBlank(const wxString &aKey)
bool extractValueAndWritability(const SELECTION &aSelection, const wxString &aPropName, wxVariant &aValue, bool &aWritable, wxPGChoices &aChoices)
Processes a selection and determines whether the given property should be available or not and what t...
virtual bool getItemValue(EDA_ITEM *aItem, PROPERTY_BASE *aProperty, wxVariant &aValue)
Utility to fetch a property value and convert to wxVariant Precondition: aItem is known to have prope...
wxPGProperty * categoryForGroup(const wxString &aGroupKey) const
virtual void rebuildProperties(const SELECTION &aSelection)
Generates the property grid for a given selection of items.
void onCharHook(wxKeyEvent &aEvent)
virtual wxPGProperty * createPGProperty(const PROPERTY_BASE *aProperty) const =0
void addCategoryButton(const wxString &aGroupKey, const wxString &aTooltip, BITMAPS aBitmap, std::function< void()> aAction, std::function< bool()> aEnableFunc=nullptr, bool aForceCategory=false)
Registers an overlay button on a category caption row.
void onShow(wxShowEvent &aEvent)
void hideCategoryButtons()
Hides all overlay buttons (used when no selection or a rebuild is deferred).
std::vector< CATEGORY_BUTTON > m_categoryButtons
void positionCategoryButtons()
Find the caption row for the given untranslated group name, if present.
void updateCategoryButtons()
Updates overlay button visibility/positions; called after rebuilds and on scroll.
EDA_BASE_FRAME * m_frame
wxString m_pendingNewKey
Key of a freshly-added blank field/custom property awaiting a name from the user.
SUPPRESS_GRID_CHANGED_EVENTS(PROPERTIES_PANEL *aPanel)
PROPERTIES_PANEL_CONTEXT_MENU_IDS
@ ID_CTX_REMOVE_CUSTOM_PROPERTY
@ ID_CTX_REMOVE_FIELD
@ ID_CTX_ADD_CUSTOM_PROPERTY
@ ID_CTX_ADD_FIELD
std::function< bool()> enableFunc
optional extra enable predicate
wxString groupKey
untranslated group name of host category