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#include <wx/timer.h>
26
27#include <tool/selection.h>
28
30#include <vector>
31#include <memory>
32#include <functional>
33
34class EDA_BASE_FRAME;
35class EDA_ITEM;
36class PROPERTY_BASE;
37class BITMAP_BUTTON;
38class wxPropertyGridEvent;
39class wxStaticText;
40
48
49class PROPERTIES_PANEL : public wxPanel
50{
52
53public:
54 PROPERTIES_PANEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame );
55 virtual ~PROPERTIES_PANEL();
56
57 virtual void UpdateData() = 0;
58
59 virtual void AfterCommit() {}
60
61 wxPropertyGrid* GetPropertyGrid()
62 {
63 return m_grid;
64 }
65
66 int PropertiesCount() const
67 {
68 return m_displayed.size();
69 }
70
71 const std::vector<PROPERTY_BASE*>& Properties() const
72 {
73 return m_displayed;
74 }
75
77
78 void SetSplitterProportion( float aProportion );
80
81protected:
87 virtual void rebuildProperties( const SELECTION& aSelection );
88
89 virtual wxPGProperty* createPGProperty( const PROPERTY_BASE* aProperty ) const = 0;
90
91 // Event handlers
92 virtual void valueChanging( wxPropertyGridEvent& aEvent ) { aEvent.Skip(); }
93 virtual void valueChanged( wxPropertyGridEvent& aEvent ) { aEvent.Skip(); }
94 void onCharHook( wxKeyEvent& aEvent );
95 void onShow( wxShowEvent& aEvent );
96
97 virtual void OnLanguageChanged( wxCommandEvent& aEvent );
98
99 virtual bool isKeyEditable( const wxPGProperty* aPGProp ) const { return false; }
100 virtual bool isKeyNameInUse( const wxString& aName ) const { return false; }
101 virtual void onKeyRenamed( const wxString& aOldName, const wxString& aNewName ) {}
102
103 virtual void onLabelEditBegin( wxPropertyGridEvent& aEvent );
104 virtual void onLabelEditEnding( wxPropertyGridEvent& aEvent );
105
106 virtual bool buildContextMenu( wxMenu& aMenu, wxPGProperty* aPGProp ) { return false; }
107 virtual void onNewItemLeftBlank( const wxString& aKey ) {}
108 void onRightClick( wxPropertyGridEvent& aEvent );
109
110 void beginLabelEdit( const wxString& aKey, bool aStartBlank = false );
111
114
120 virtual bool getItemValue( EDA_ITEM* aItem, PROPERTY_BASE* aProperty, wxVariant& aValue );
121
133 bool extractValueAndWritability( const SELECTION& aSelection, const wxString& aPropName,
134 wxVariant& aValue, bool& aWritable, wxPGChoices& aChoices );
135
152 void addCategoryButton( const wxString& aGroupKey, const wxString& aTooltip,
153 BITMAPS aBitmap, std::function<void()> aAction,
154 std::function<bool()> aEnableFunc = nullptr,
155 bool aForceCategory = false );
156
159
161 void hideCategoryButtons();
162
164
166 wxPGProperty* categoryForGroup( const wxString& aGroupKey ) const;
167
168 wxStaticText* m_caption;
169
170public:
172
173protected:
174 std::vector<PROPERTY_BASE*> m_displayed; // no ownership of pointers
175 wxPropertyGrid* m_grid;
177
180
185
187
189
191 {
193 wxString groupKey;
194 std::function<void()> action;
195 std::function<bool()> enableFunc;
196
199 bool forceCategory = false;
200 };
201
202 std::vector<CATEGORY_BUTTON> m_categoryButtons;
203
206
209};
210
211
221
222#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...
wxTimer m_deferredRebuildTimer
Not CallAfter(): on macOS the pending-event queue is drained from inside tool events,...
SELECTION m_deferredSelection
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
Find the caption row for the given untranslated group name, if present.
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 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
bool forceCategory
Emit the category caption row even when it has no properties; the row is only forced on rebuilds wher...
wxString groupKey
untranslated group name of host category