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 SKGTREEVIEW_H 0007 #define SKGTREEVIEW_H 0008 /** @file 0009 * A tree view with more features. 0010 * 0011 * @author Stephane MANKOWSKI / Guillaume DE BURE 0012 */ 0013 #include <qmenu.h> 0014 #include <qstringlist.h> 0015 #include <qtreeview.h> 0016 0017 #include "skgbasegui_export.h" 0018 #include "skgmainpanel.h" 0019 #include "skgobjectbase.h" 0020 #include "skgservices.h" 0021 #include "skgtraces.h" 0022 0023 class SKGObjectModelBase; 0024 class SKGDocument; 0025 class QTextBrowser; 0026 class SKGSortFilterProxyModel; 0027 class QTimer; 0028 0029 0030 /** 0031 * This file is a tab widget used by plugins 0032 */ 0033 class SKGBASEGUI_EXPORT SKGTreeView : public QTreeView 0034 { 0035 Q_OBJECT 0036 0037 /** 0038 * Text resizable by CTRL+wheel 0039 */ 0040 Q_PROPERTY(bool textResizable READ isTextResizable WRITE setTextResizable NOTIFY modified) 0041 /** 0042 * Auto resize mode of the view 0043 */ 0044 Q_PROPERTY(bool autoResized READ isAutoResized CONSTANT) 0045 0046 public: 0047 /** 0048 * Default Constructor 0049 * @param iParent the parent 0050 */ 0051 explicit SKGTreeView(QWidget* iParent); 0052 0053 /** 0054 * Default Destructor 0055 */ 0056 ~SKGTreeView() override; 0057 0058 /** 0059 * Get the current state 0060 * @return a string containing all information needed to set the same state. 0061 * Could be an XML stream 0062 */ 0063 virtual QString getState(); 0064 0065 /** 0066 * Set the current state 0067 * MUST BE OVERWRITTEN 0068 * @param iState must be interpreted to set the state of the widget 0069 */ 0070 virtual void setState(const QString& iState); 0071 0072 /** 0073 * To know if the autoresized mode is enable 0074 */ 0075 virtual bool isAutoResized(); 0076 0077 /** 0078 * Set parameter to activate and save default state of this table 0079 * @param iDocument document pointer 0080 * @param iParameterName parameter name in this document 0081 */ 0082 virtual void setDefaultSaveParameters(SKGDocument* iDocument, const QString& iParameterName); 0083 0084 /** 0085 * Get the table content as QTextBrowser 0086 * @return the table content (MUST BE DELETED) 0087 */ 0088 virtual QTextBrowser* getTextBrowser() const; 0089 0090 /** 0091 * Get the table content 0092 * @param iIndex the line index 0093 * @return the table content 0094 */ 0095 virtual SKGStringListList getTable(const QModelIndex& iIndex = QModelIndex()) const; 0096 0097 /** 0098 * Get the current selection 0099 * @return selected objects 0100 */ 0101 virtual SKGObjectBase::SKGListSKGObjectBase getSelectedObjects(); 0102 0103 /** 0104 * Get the first selected object 0105 * @return first selected object 0106 */ 0107 virtual SKGObjectBase getFirstSelectedObject(); 0108 0109 /** 0110 * Get the number of selected object 0111 * @return number of selected objects 0112 */ 0113 virtual int getNbSelectedObjects(); 0114 0115 /** 0116 * Sets the current selection model to the given selectionModel. 0117 * @param iSelectionModel the selection model 0118 */ 0119 void setSelectionModel(QItemSelectionModel* iSelectionModel) override; 0120 0121 /** 0122 * Insert a registered action 0123 * @see SKGMainPanel::registerGlobalAction 0124 * @param iRegisteredAction the registered action. "" means separator 0125 */ 0126 virtual void insertGlobalAction(const QString& iRegisteredAction = QString()); 0127 0128 /** 0129 * @brief Set model 0130 * 0131 * @param iModel the model 0132 * @return void 0133 **/ 0134 void setModel(QAbstractItemModel* iModel) override; 0135 0136 /** 0137 * @brief Get the header menu 0138 * @return the header menu 0139 **/ 0140 virtual QMenu* getHeaderMenu() const; 0141 0142 /** 0143 * Export to a file 0144 * @param iFileName the file name 0145 * @return an object managing the error 0146 * @see SKGError 0147 */ 0148 virtual SKGError exportInFile(const QString& iFileName); 0149 0150 /** 0151 * Get the current schema 0152 * @return the current schema 0153 */ 0154 virtual QStringList getCurrentSchema() const; 0155 0156 /** 0157 * Get the property to know if text is resizable 0158 * @return the property 0159 */ 0160 virtual bool isTextResizable() const; 0161 0162 public Q_SLOTS: 0163 /** 0164 * This property holds whether to autorize text size modification by CTRL+wheel. 0165 * @param resizable true of false 0166 */ 0167 virtual void setTextResizable(bool resizable); 0168 0169 /** 0170 * Set the zoom position. 0171 * @param iZoomPosition zoom position (-10<=zoom position<=10) 0172 */ 0173 virtual void setZoomPosition(int iZoomPosition); 0174 0175 /** 0176 * Get zoom position 0177 * @return zoom position (-10<=zoom position<=10) 0178 */ 0179 virtual int zoomPosition(); 0180 0181 /** 0182 * Save the selection 0183 */ 0184 virtual void saveSelection(); 0185 0186 /** 0187 * Reset the selection 0188 */ 0189 virtual void resetSelection(); 0190 0191 /** 0192 * Scroll on selected lines. 0193 */ 0194 virtual void scroolOnSelection(); 0195 0196 /** 0197 * Select an object and focus on it 0198 * @param iUniqueID unique ID of the object 0199 */ 0200 virtual void selectObject(const QString& iUniqueID); 0201 0202 /** 0203 * Select objects and focus on the first one 0204 * @param iUniqueIDs unique IDs of objects 0205 * @param iFocusOnFirstOne set the focus on the first one 0206 */ 0207 virtual void selectObjects(const QStringList& iUniqueIDs, bool iFocusOnFirstOne = false); 0208 0209 /** 0210 * This property holds whether to draw the background using alternating colors. 0211 * @param enable true of false 0212 */ 0213 virtual void setAlternatingRowColors(bool enable); 0214 0215 /** 0216 * Reset columns order 0217 */ 0218 virtual void resetColumnsOrder(); 0219 0220 /** 0221 * Resizes all columns based on the size hints of the delegate used to render each item in the columns. 0222 */ 0223 virtual void resizeColumnsToContents(); 0224 0225 /** 0226 * Resizes all columns based on the size hints of the delegate used to render each item in the columns. 0227 */ 0228 virtual void resizeColumnsToContentsDelayed(); 0229 0230 /** 0231 * When the selection changed 0232 */ 0233 virtual void onSelectionChanged(); 0234 0235 /** 0236 * Expand all and resize columns if needed 0237 */ 0238 virtual void expandAll(); 0239 0240 /** 0241 * Copy selection in clipboard 0242 */ 0243 virtual void copy(); 0244 0245 /** 0246 * Switch auto resize 0247 */ 0248 virtual void switchAutoResize(); 0249 0250 protected: 0251 /** 0252 * This function is called with the given event when a mouse button is pressed while the cursor is inside the widget. 0253 * If a valid item is pressed on it is made into the current item. This function emits the pressed() signal. 0254 * @param iEvent the event 0255 */ 0256 void mousePressEvent(QMouseEvent* iEvent) override; 0257 0258 Q_SIGNALS: 0259 /** 0260 * Emitted when the empty area 0261 */ 0262 void clickEmptyArea(); 0263 0264 /** 0265 * Emitted 300ms after selection changed 0266 */ 0267 void selectionChangedDelayed(); 0268 0269 /** 0270 * Emitted when zoom changed 0271 * @param iZoomPosition zoom position (-10<=zoom position<=10) 0272 */ 0273 void zoomChanged(int iZoomPosition); 0274 0275 /** 0276 * When properties are modified 0277 */ 0278 void modified(); 0279 0280 protected: 0281 /** 0282 * Event filtering 0283 * @param iObject object 0284 * @param iEvent event 0285 * @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. 0286 */ 0287 bool eventFilter(QObject* iObject, QEvent* iEvent) override; 0288 0289 private Q_SLOTS: 0290 void onExport(); 0291 void setupHeaderMenu(); 0292 void showHeaderMenu(); 0293 void showHeaderMenu(QPoint iPos); 0294 void showHideColumn(); 0295 void respanFirstColumns(); 0296 void refreshExpandCollapse(); 0297 void changeSchema(); 0298 void saveDefaultClicked(); 0299 void groupByChanged(QAction* /*iAction*/); 0300 0301 void onSortChanged(int /*iIndex*/, Qt::SortOrder /*iOrder*/); 0302 0303 void onExpand(const QModelIndex& index); 0304 void onCollapse(const QModelIndex& index); 0305 void onClick(const QModelIndex& index); 0306 void onActionTriggered(int action); 0307 void onRangeChanged(); 0308 0309 void rebuildContextualMenu(); 0310 0311 private: 0312 Q_DISABLE_COPY(SKGTreeView) 0313 0314 QMenu* m_headerMenu; 0315 bool m_autoResize; 0316 bool m_autoResizeDone; 0317 QAction* m_actAutoResize; 0318 QAction* m_actCopy; 0319 QAction* m_actExpandAll; 0320 QAction* m_actCollapseAll; 0321 SKGDocument* m_document; 0322 QString m_parameterName; 0323 QStringList m_selection; 0324 QStringList m_expandedNodes; 0325 QString m_groupby; 0326 0327 QTimer m_timerDelayedResize; 0328 QTimer m_timerSelectionChanged; 0329 QTimer m_timerScrollSelection; 0330 bool m_textResizable; 0331 int m_fontOriginalPointSize; 0332 int m_iconOriginalSize; 0333 0334 SKGObjectModelBase* m_model; 0335 SKGSortFilterProxyModel* m_proxyModel; 0336 0337 QAction* m_actGroupByNone; 0338 0339 SKGObjectBase::SKGListSKGObjectBase m_lastSelection; 0340 SKGObjectBase::SKGListSKGObjectBase m_lastSelection_if_deleted; 0341 QString m_lastSelection_previous; 0342 0343 bool stickH; 0344 bool stickV; 0345 }; 0346 0347 #endif // SKGTREEVIEW_H