Skip to content

Commit

Permalink
GRASS plugin: fix deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault authored and nyalldawson committed Jan 26, 2021
1 parent 57c5a6f commit 0c04b2d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 30 deletions.
14 changes: 13 additions & 1 deletion src/plugins/grass/qgsgrassmapcalc.cpp
Expand Up @@ -1452,7 +1452,7 @@ void QgsGrassMapcalcObject::paint( QPainter *painter,
int xRound = ( int )( 100 * mRound / mRect.width() );
int yRound = ( int )( 100 * mRound / mRect.height() );

painter->drawRoundRect( mRect, xRound, yRound );
painter->drawRoundedRect( mRect, xRound, yRound );

// Input sockets
for ( int i = 0; i < mInputCount; i++ )
Expand Down Expand Up @@ -1496,7 +1496,11 @@ void QgsGrassMapcalcObject::paint( QPainter *painter,

int lx = mRect.x() + mSpace;
int ly = mRect.y() + mSpace + i * ( mTextHeight + mSpace );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
QRect lr( lx, ly, metrics.width( l ), mTextHeight );
#else
QRect lr( lx, ly, metrics.horizontalAdvance( l ), mTextHeight );
#endif

painter->drawText( lr, Qt::AlignCenter | Qt::TextSingleLine, l );
}
Expand Down Expand Up @@ -1548,13 +1552,21 @@ void QgsGrassMapcalcObject::resetSize()
for ( int i = 0; i < mFunction.inputLabels().size(); i++ )
{
QString l = mFunction.inputLabels().at( i );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int len = metrics.width( l );
#else
int len = metrics.horizontalAdvance( l );
#endif
if ( len > mInputTextWidth )
mInputTextWidth = len;
}
}

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int labelTextWidth = metrics.width( mLabel );
#else
int labelTextWidth = metrics.horizontalAdvance( mLabel );
#endif
if ( mType == Function && !mFunction.drawlabel() )
{
labelTextWidth = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrasstools.cpp
Expand Up @@ -430,7 +430,7 @@ void QgsGrassTools::addModules( QStandardItem *parent, QDomElement &element, QSt
myData.setIcon( pixmap );
myData.setCheckable( false );
myData.setRenderAsWidget( false );
QVariant myVariant = qVariantFromValue( myData );
QVariant myVariant = QVariant::fromValue( myData );
listItem->setData( myVariant, Qt::UserRole );
modulesListModel->appendRow( listItem );
}
Expand Down
22 changes: 9 additions & 13 deletions src/plugins/grass/qtermwidget/Session.cpp
Expand Up @@ -108,7 +108,7 @@ Session::Session(QObject* parent) :
connect( _emulation,&Emulation::lockPtyRequest,_shellProcess,&Pty::lockPty );
connect( _emulation,&Emulation::useUtf8Request,_shellProcess,&Pty::setUtf8Mode );

connect( _shellProcess,static_cast<void ( QProcess::* )( int )>( &QProcess::finished ), this, &Session::done );
connect( _shellProcess,static_cast<void ( QProcess::* )( int, QProcess::ExitStatus)>( &QProcess::finished ), this, &Session::done );
// not in kprocess anymore connect( _shellProcess,SIGNAL(done(int)), this, SLOT(done(int)) );

//setup timer for monitoring session activity
Expand Down Expand Up @@ -485,8 +485,7 @@ void Session::monitorTimerDone()
void Session::activityStateSet(int state)
{
if (state==NOTIFYBELL) {
QString s;
s.sprintf("Bell in session '%s'",_nameTitle.toUtf8().constData());
QString s = QStringLiteral("Bell in session '%1'").arg(_nameTitle);

emit bellRequest( s );
} else if (state==NOTIFYACTIVITY) {
Expand Down Expand Up @@ -619,7 +618,7 @@ QString Session::profileKey() const
return _profileKey;
}

void Session::done(int exitStatus)
void Session::done(int exitCode, QProcess::ExitStatus exitStatus)
{
if (!_autoClose) {
_userTitle = ("This session is done. Finished");
Expand All @@ -628,20 +627,17 @@ void Session::done(int exitStatus)
}

QString message;
if (!_wantedClose || exitStatus != 0) {
if (!_wantedClose || exitCode != 0) {

if (_shellProcess->exitStatus() == QProcess::NormalExit) {
message.sprintf("Session '%s' exited with status %d.",
_nameTitle.toUtf8().constData(), exitStatus);
if (exitStatus == QProcess::NormalExit) {
message = QStringLiteral("Session '%1' exited with code %2.").arg(_nameTitle).arg(exitCode);
} else {
message.sprintf("Session '%s' crashed.",
_nameTitle.toUtf8().constData());
message = QStringLiteral("Session '%1' crashed.").arg(_nameTitle);
}
}

if ( !_wantedClose && _shellProcess->exitStatus() != QProcess::NormalExit )
message.sprintf("Session '%s' exited unexpectedly.",
_nameTitle.toUtf8().constData());
if ( !_wantedClose && exitStatus != QProcess::NormalExit )
message = QStringLiteral("Session '%1' exited unexpectedly.").arg(_nameTitle);
else
emit finished();

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/grass/qtermwidget/Session.h
Expand Up @@ -25,6 +25,7 @@
#ifndef SESSION_H
#define SESSION_H

#include <QProcess>
#include <QStringList>
#include <QWidget>

Expand Down Expand Up @@ -478,7 +479,7 @@ public slots:
void activity();

private slots:
void done(int);
void done(int, QProcess::ExitStatus );

// void fireZModemDetected();

Expand Down
33 changes: 21 additions & 12 deletions src/plugins/grass/qtermwidget/TerminalDisplay.cpp
Expand Up @@ -216,6 +216,15 @@ unsigned short Konsole::vt100_graphics[32] =
0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7
};

template<class T> inline int horizontalAdvance(const QFontMetrics& fm, T t)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
return fm.width( t );
#else
return fm.horizontalAdvance( t );
#endif
}

void TerminalDisplay::fontChange( const QFont & )
{
QFontMetrics fm( font() );
Expand All @@ -225,14 +234,14 @@ void TerminalDisplay::fontChange( const QFont & )
// "Base character width on widest ASCII character. This prevents too wide
// characters in the presence of double wide (e.g. Japanese) characters."
// Get the width from representative normal width characters
_fontWidth = qRound( static_cast<double>(fm.width( REPCHAR )) / static_cast<double>(strlen( REPCHAR )) );
_fontWidth = qRound( static_cast<double>(horizontalAdvance(fm, REPCHAR )) / static_cast<double>(strlen( REPCHAR )) );

_fixedFont = true;

int fw = fm.width( REPCHAR[0] );
int fw = horizontalAdvance(fm, REPCHAR[0] );
for ( unsigned int i = 1; i < strlen( REPCHAR ); i++ )
{
if ( fw != fm.width( REPCHAR[i] ) )
if ( fw != horizontalAdvance(fm, REPCHAR[i] ) )
{
_fixedFont = false;
break;
Expand Down Expand Up @@ -627,7 +636,7 @@ void TerminalDisplay::drawBackground( QPainter &painter, const QRect &rect, cons
else
painter.fillRect( contentsRect, backgroundColor );

painter.fillRect( scrollBarArea, _scrollBar->palette().background() );
painter.fillRect( scrollBarArea, _scrollBar->palette().window() );
}

void TerminalDisplay::drawCursor( QPainter &painter,
Expand Down Expand Up @@ -754,7 +763,7 @@ void TerminalDisplay::drawTextFragment( QPainter &painter,
const QColor backgroundColor = style->backgroundColor.color( _colorTable );

// draw background if different from the display's background color
if ( backgroundColor != palette().background().color() )
if ( backgroundColor != palette().window().color() )
drawBackground( painter, rect, backgroundColor,
false /* do not use transparency */ );

Expand Down Expand Up @@ -1159,7 +1168,7 @@ void TerminalDisplay::showResizeNotification()
if ( !_resizeWidget )
{
_resizeWidget = new QLabel( QStringLiteral( "Size: XXX x XXX" ), this );
_resizeWidget->setMinimumWidth( _resizeWidget->fontMetrics().width( QStringLiteral( "Size: XXX x XXX" ) ) );
_resizeWidget->setMinimumWidth( horizontalAdvance(_resizeWidget->fontMetrics(), QStringLiteral( "Size: XXX x XXX" ) ) );
_resizeWidget->setMinimumHeight( _resizeWidget->sizeHint().height() );
_resizeWidget->setAlignment( Qt::AlignCenter );

Expand Down Expand Up @@ -1241,9 +1250,9 @@ void TerminalDisplay::paintEvent( QPaintEvent *pe )
{
QPainter paint( this );

foreach ( const QRect &rect, ( pe->region() & contentsRect() ).rects() )
for ( const QRect &rect: pe->region() & contentsRect() )
{
drawBackground( paint, rect, palette().background().color(),
drawBackground( paint, rect, palette().window().color(),
true /* use opacity setting */ );
drawContents( paint, rect );
}
Expand Down Expand Up @@ -1421,7 +1430,7 @@ int TerminalDisplay::textWidth( const int startColumn, const int length, const i
int result = 0;
for ( int column = 0; column < length; column++ )
{
result += fm.width( _image[loc( startColumn + column, line )].character );
result += horizontalAdvance( fm, _image[loc( startColumn + column, line )].character );
}
return result;
}
Expand Down Expand Up @@ -1532,7 +1541,7 @@ void TerminalDisplay::drawContents( QPainter &paint, const QRect &rect )
}

//Apply text scaling matrix.
paint.setWorldMatrix( textScale, true );
paint.setWorldTransform(QTransform(textScale), true );

//calculate the area in which the text will be drawn
QRect textArea = calculateTextArea( tLx, tLy, x, y, len );
Expand All @@ -1556,7 +1565,7 @@ void TerminalDisplay::drawContents( QPainter &paint, const QRect &rect )
_fixedFont = save__fixedFont;

//reset back to single-width, single-height _lines
paint.setWorldMatrix( textScale.inverted(), true );
paint.setWorldTransform(QTransform(textScale.inverted()), true );

if ( y < _lineProperties.size() - 1 )
{
Expand Down Expand Up @@ -3029,7 +3038,7 @@ void TerminalDisplay::doDrag()
QMimeData *mimeData = new QMimeData;
mimeData->setText( QApplication::clipboard()->text( QClipboard::Selection ) );
dragInfo.dragObject->setMimeData( mimeData );
dragInfo.dragObject->start( Qt::CopyAction );
dragInfo.dragObject->exec( Qt::CopyAction );
// Don't delete the QTextDrag object. Qt will delete it when it's done with it.
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/grass/qtermwidget/kpty.cpp
Expand Up @@ -271,8 +271,8 @@ bool KPty::open()
// Linux device names, FIXME: Trouble on other systems?
for (const char * s3 = "pqrstuvwxyzabcde"; *s3; s3++) {
for (const char * s4 = "0123456789abcdef"; *s4; s4++) {
ptyName = QString().sprintf("/dev/pty%c%c", *s3, *s4).toUtf8();
d->ttyName = QString().sprintf("/dev/tty%c%c", *s3, *s4).toUtf8();
ptyName = QStringLiteral("/dev/pty%1%2").arg(*s3).arg(*s4).toUtf8();
d->ttyName = QStringLiteral("/dev/tty%1%2").arg(*s3).arg(*s4).toUtf8();

d->masterFd = ::open(ptyName.data(), O_RDWR);
if (d->masterFd >= 0) {
Expand Down

0 comments on commit 0c04b2d

Please sign in to comment.