QGIS API Documentation 3.41.0-Master (d5b93354e9c)
Loading...
Searching...
No Matches
qgscodeeditorwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscodeeditorwidget.h
3 --------------------------------------
4 Date : May 2024
5 Copyright : (C) 2024 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSCODEEDITORWIDGET_H
17#define QGSCODEEDITORWIDGET_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
21#include "qgspanelwidget.h"
22
23#include <QDateTime>
24
25class QgsCodeEditor;
27class QToolButton;
28class QCheckBox;
29class QgsMessageBar;
31
32SIP_IF_MODULE( HAVE_QSCI_SIP )
33
34
48class GUI_EXPORT QgsCodeEditorWidget : public QgsPanelWidget
49{
50 Q_OBJECT
51
52 public:
61 QgsCodeEditorWidget( QgsCodeEditor *editor SIP_TRANSFER, QgsMessageBar *messageBar = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
63
64 void resizeEvent( QResizeEvent *event ) override;
65 void showEvent( QShowEvent *event ) override;
66 bool eventFilter( QObject *obj, QEvent *event ) override;
67
71 QgsCodeEditor *editor() { return mEditor; }
72
76 bool isSearchBarVisible() const;
77
81 QgsMessageBar *messageBar();
82
87 QgsScrollBarHighlightController *scrollbarHighlightController();
88
97 void addWarning( int lineNumber, const QString &warning );
98
107 void clearWarnings();
108
115 QString filePath() const { return mFilePath; }
116
123 bool save( const QString &path = QString() );
124
125 public slots:
126
133 void showSearchBar();
134
141 void hideSearchBar();
142
150 void setSearchBarVisible( bool visible );
151
157 void setReplaceBarVisible( bool visible );
158
165 void triggerFind();
166
175 bool loadFile( const QString &path );
176
184 void setFilePath( const QString &path );
185
199 bool openInExternalEditor( int line = -1, int column = -1 );
200
208 bool shareOnGist( bool isPublic );
209
210 signals:
211
215 void searchBarToggled( bool visible );
216
223 void filePathChanged( const QString &path );
224
230
231 private slots:
232
233 bool findNext();
234 void findPrevious();
235 void textSearchChanged( const QString &text );
236 void updateSearch();
237 void replace();
238 void replaceSelection();
239 void replaceAll();
240
241 private:
242 void clearSearchHighlights();
243 void addSearchHighlights();
244 int searchFlags() const;
245 bool findText( bool forward, bool findFirst );
246 void updateHighlightController();
247 void searchMatchCountChanged( int matchCount );
248
249 enum HighlightCategory
250 {
251 SearchMatch = 0,
252 Warning = 1
253 };
254
255 QgsCodeEditor *mEditor = nullptr;
256 QWidget *mFindWidget = nullptr;
257 QgsFilterLineEdit *mLineEditFind = nullptr;
258 QgsFilterLineEdit *mLineEditReplace = nullptr;
259 QToolButton *mFindPrevButton = nullptr;
260 QToolButton *mFindNextButton = nullptr;
261 QToolButton *mCaseSensitiveButton = nullptr;
262 QToolButton *mWholeWordButton = nullptr;
263 QToolButton *mRegexButton = nullptr;
264 QToolButton *mWrapAroundButton = nullptr;
265 QToolButton *mShowReplaceBarButton = nullptr;
266 QToolButton *mReplaceButton = nullptr;
267 QToolButton *mReplaceAllButton = nullptr;
268 int mBlockSearching = 0;
269 QgsMessageBar *mMessageBar = nullptr;
270 std::unique_ptr<QgsScrollBarHighlightController> mHighlightController;
271 QString mFilePath;
272 QDateTime mLastModified;
273};
274
275#endif // QGSCODEEDITORWIDGET_H
A widget which wraps a QgsCodeEditor in additional functionality.
void loadedExternalChanges()
Emitted when the widget loads in text from the associated file to bring in changes made externally to...
void searchBarToggled(bool visible)
Emitted when the visibility of the search bar is changed.
void filePathChanged(const QString &path)
Emitted when the widget's associated file path is changed.
QgsCodeEditor * editor()
Returns the wrapped code editor.
QString filePath() const
Returns the widget's associated file path.
~QgsCodeEditorWidget() override
A text editor based on QScintilla2.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
A bar for displaying non-blocking messages to the user.
Base class for any widget that can be shown as a inline panel.
Adds highlights (colored markers) to a scrollbar.
#define SIP_IF_MODULE(condition)
Definition qgis_sip.h:28
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFER
Definition qgis_sip.h:36