mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Add adjustScrollWidth method
This commit is contained in:
parent
9e1be4bb53
commit
86bd2c5353
@ -499,6 +499,16 @@ This is only supported for editors which return the :py:class:`Qgis`.ScriptLangu
|
||||
.. versionadded:: 3.32
|
||||
%End
|
||||
|
||||
void adjustScrollWidth();
|
||||
%Docstring
|
||||
Adjust the width of the scroll bar to fit the content.
|
||||
|
||||
.. versionadded:: 3.42
|
||||
%End
|
||||
|
||||
virtual void setText( const QString &text );
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
void sessionHistoryCleared();
|
||||
|
@ -499,6 +499,16 @@ This is only supported for editors which return the :py:class:`Qgis`.ScriptLangu
|
||||
.. versionadded:: 3.32
|
||||
%End
|
||||
|
||||
void adjustScrollWidth();
|
||||
%Docstring
|
||||
Adjust the width of the scroll bar to fit the content.
|
||||
|
||||
.. versionadded:: 3.42
|
||||
%End
|
||||
|
||||
virtual void setText( const QString &text );
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
void sessionHistoryCleared();
|
||||
|
@ -817,6 +817,34 @@ void QgsCodeEditor::toggleComment()
|
||||
{
|
||||
}
|
||||
|
||||
void QgsCodeEditor::adjustScrollWidth()
|
||||
{
|
||||
// A zero width would make setScrollWidth crash
|
||||
long maxWidth = 10;
|
||||
|
||||
// Get the number of lines
|
||||
int lineCount = lines();
|
||||
|
||||
// Loop through all the lines to get the longest one
|
||||
for ( int line = 0; line < lineCount; line++ )
|
||||
{
|
||||
// Get the linear position at the end of the current line
|
||||
const long endLine = SendScintilla( SCI_GETLINEENDPOSITION, line );
|
||||
// Get the x coordinates of the end of the line
|
||||
const long x = SendScintilla( SCI_POINTXFROMPOSITION, 0, endLine );
|
||||
maxWidth = std::max( maxWidth, x );
|
||||
}
|
||||
|
||||
// Use the longest line width as the new scroll width
|
||||
setScrollWidth( maxWidth );
|
||||
}
|
||||
|
||||
void QgsCodeEditor::setText( const QString &text )
|
||||
{
|
||||
QsciScintilla::setText( text );
|
||||
adjustScrollWidth();
|
||||
}
|
||||
|
||||
QStringList QgsCodeEditor::history() const
|
||||
{
|
||||
return mHistory;
|
||||
|
@ -531,6 +531,16 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
|
||||
*/
|
||||
virtual void toggleComment();
|
||||
|
||||
/**
|
||||
* Adjust the width of the scroll bar to fit the content.
|
||||
*
|
||||
* \since QGIS 3.42
|
||||
*/
|
||||
void adjustScrollWidth();
|
||||
|
||||
// Override QsciScintilla::setText to adjust the scroll width
|
||||
void setText( const QString &text ) override;
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user