File indexing completed on 2024-05-05 17:19:09
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr 0003 * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 ***************************************************************************/ 0006 #ifndef SKGWIDGET_H 0007 #define SKGWIDGET_H 0008 /** @file 0009 * This file is a class managing widget. 0010 * 0011 * @author Stephane MANKOWSKI / Guillaume DE BURE 0012 */ 0013 #include <qwidget.h> 0014 0015 0016 0017 #include "skgbasegui_export.h" 0018 #include "skgobjectbase.h" 0019 0020 class SKGDocument; 0021 0022 /** 0023 * This file is a tab widget used by plugins 0024 */ 0025 class SKGBASEGUI_EXPORT SKGWidget : public QWidget 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 /** 0031 * Default Constructor 0032 * @param iParent the parent widget 0033 * @param iDocument the document 0034 */ 0035 explicit SKGWidget(QWidget* iParent, SKGDocument* iDocument); 0036 0037 /** 0038 * Default Destructor 0039 */ 0040 ~SKGWidget() override; 0041 0042 /** 0043 * Get main document 0044 * @return pointer on main document 0045 */ 0046 virtual SKGDocument* getDocument() const; 0047 0048 /** 0049 * Get the current state 0050 * MUST BE OVERWRITTEN 0051 * @return a string containing all information needed to set the same state. 0052 * Could be an XML stream 0053 */ 0054 virtual QString getState(); 0055 0056 /** 0057 * Set the current state 0058 * MUST BE OVERWRITTEN 0059 * @param iState must be interpreted to set the state of the widget 0060 */ 0061 virtual void setState(const QString& iState); 0062 0063 /** 0064 * Get attribute name to save the default state 0065 * MUST BE OVERWRITTEN 0066 * @return attribute name to save the default state. 0067 */ 0068 virtual QString getDefaultStateAttribute(); 0069 0070 /** 0071 * Get the current selection 0072 * MUST BE OVERWRITTEN 0073 * @return selected objects 0074 */ 0075 virtual SKGObjectBase::SKGListSKGObjectBase getSelectedObjects(); 0076 0077 /** 0078 * Get the first selected object 0079 * @return first selected object 0080 */ 0081 virtual SKGObjectBase getFirstSelectedObject(); 0082 0083 /** 0084 * Get the number of selected object 0085 * CAN BE OVERWRITTEN FOR OPTIMIZATION 0086 * @return number of selected objects 0087 */ 0088 virtual int getNbSelectedObjects(); 0089 0090 /** 0091 * To know if the widget having the selection has the focus 0092 * Default implementation is based on mainWidget 0093 * Don't forget to do mainWidget()->installEventFilter(this); 0094 * @return true of false 0095 */ 0096 virtual bool hasSelectionWithFocus(); 0097 0098 /** 0099 * Get the main widget 0100 * @return a widget 0101 */ 0102 virtual QWidget* mainWidget(); 0103 0104 Q_SIGNALS: 0105 /** 0106 * This signal must be launched when the selection is modified 0107 */ 0108 void selectionChanged(); 0109 0110 /** 0111 * This signal must be launched when the widget having the selection has win or lost the focus 0112 */ 0113 void selectionFocusChanged(); 0114 protected: 0115 /** 0116 * Event filtering 0117 * @param iObject object 0118 * @param iEvent event 0119 * @return In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false. 0120 */ 0121 bool eventFilter(QObject* iObject, QEvent* iEvent) override; 0122 0123 private: 0124 Q_DISABLE_COPY(SKGWidget) 0125 0126 SKGDocument* m_document; 0127 }; 0128 0129 #endif // SKGWIDGET_H