Commit cdae80af authored by Nicolas Vuaille's avatar Nicolas Vuaille

Remove Qt deprecations

Mainly:
* QSignalMapper -> connections with lambdas
* QRegExp -> QRegularExpressions (still some occurrences)
* QString::null -> QString::isNull()

Needs version check:
* QFontMetrics::width() -> QFontMetrics::horizontalAdvance() introduced in 5.11
* QTextEdit::setTabStopWidth() -> QTextEdit::setTabStopDistance introduced in 5.10
parent 6eab98c2
......@@ -50,7 +50,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkSMTransferFunctionProxy.h"
#include <QDebug>
#include <QSignalMapper>
namespace
{
......@@ -256,17 +255,11 @@ bool pqResetScalarRangeReaction::resetScalarRangeToDataOverTime(pqPipelineRepres
Ui::ResetScalarRangeToDataOverTime ui;
ui.setupUi(&dialog);
QSignalMapper smapper;
smapper.setMapping(ui.RescaleButton, QDialog::Accepted);
smapper.connect(ui.RescaleButton, SIGNAL(clicked()), SLOT(map()));
connect(ui.RescaleButton, &QPushButton::clicked, [&]() { dialog.done(QDialog::Accepted); });
connect(ui.RescaleAndLockButton, &QPushButton::clicked,
[&]() { dialog.done(static_cast<int>(QDialog::Accepted) + 1); });
connect(ui.CancelButton, &QPushButton::clicked, [&]() { dialog.done(QDialog::Rejected); });
smapper.setMapping(ui.RescaleAndLockButton, static_cast<int>(QDialog::Accepted) + 1);
smapper.connect(ui.RescaleAndLockButton, SIGNAL(clicked()), SLOT(map()));
smapper.setMapping(ui.CancelButton, QDialog::Rejected);
smapper.connect(ui.CancelButton, SIGNAL(clicked()), SLOT(map()));
dialog.connect(&smapper, SIGNAL(mapped(int)), SLOT(done(int)));
int retcode = dialog.exec();
if (retcode != QDialog::Rejected)
{
......
......@@ -43,7 +43,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QLineEdit>
#include <QPointer>
#include <QPushButton>
#include <QSignalMapper>
#include <QToolButton>
#include <QVBoxLayout>
#include <QtDebug>
......@@ -117,7 +116,6 @@ public:
QPointer<pqAnimationScene> Scene;
pqAnimationWidget* AnimationWidget;
pqAnimationTimeWidget* AnimationTimeWidget;
QSignalMapper KeyFramesChanged;
typedef QMap<QPointer<pqAnimationCue>, pqAnimationTrack*> TrackMapType;
TrackMapType TrackMap;
QPointer<QDialog> Editor;
......@@ -340,8 +338,6 @@ pqAnimationViewWidget::pqAnimationViewWidget(QWidget* _parent)
l->addWidget(this->Internal->CreateProperty);
l->addStretch();
QObject::connect(&this->Internal->KeyFramesChanged, SIGNAL(mapped(QObject*)), this,
SLOT(keyFramesChanged(QObject*)));
QObject::connect(this->Internal->AnimationWidget, SIGNAL(trackSelected(pqAnimationTrack*)), this,
SLOT(trackSelected(pqAnimationTrack*)));
QObject::connect(this->Internal->AnimationWidget, SIGNAL(deleteTrackClicked(pqAnimationTrack*)),
......@@ -480,9 +476,8 @@ void pqAnimationViewWidget::onSceneCuesChanged()
}
this->Internal->TrackMap.insert(cue, track);
track->setProperty(completeName);
this->Internal->KeyFramesChanged.setMapping(cue, cue);
QObject::connect(
cue, SIGNAL(keyframesModified()), &this->Internal->KeyFramesChanged, SLOT(map()));
cue, &pqAnimationCue::keyframesModified, this, [=]() { this->keyFramesChanged(cue); });
QObject::connect(cue, SIGNAL(enabled(bool)), track, SLOT(setEnabled(bool)));
track->setEnabled(cue->isEnabled());
......@@ -503,8 +498,7 @@ void pqAnimationViewWidget::onSceneCuesChanged()
this->Internal->TrackMap.remove(iter.key());
if (iter.key())
{
QObject::disconnect(
iter.key(), SIGNAL(keyframesModified()), &this->Internal->KeyFramesChanged, SLOT(map()));
QObject::disconnect(iter.key(), &pqAnimationCue::keyframesModified, nullptr, nullptr);
}
}
}
......
......@@ -42,7 +42,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QMenu>
#include <QPointer>
#include <QSignalMapper>
#include <QRegularExpression>
#include <QtDebug>
class pqCalculatorWidget::pqInternals : public Ui::CalculatorWidget
......@@ -96,36 +96,24 @@ pqCalculatorWidget::pqCalculatorWidget(
//--------------------------------------------------------------------------
// connect all buttons for which the text of the button
// is the same as what goes into the function
QRegExp regexp("^([ijk]Hat|ln|log10|sin|cos|"
"tan|asin|acos|atan|sinh|cosh|tanh|"
"sqrt|exp|ceil|floor|abs|norm|mag|"
"LeftParentheses|RightParentheses|"
"Divide|Multiply|Minus|Plus)$");
QRegularExpression regexp("^([ijk]Hat|ln|log10|sin|cos|"
"tan|asin|acos|atan|sinh|cosh|tanh|"
"sqrt|exp|ceil|floor|abs|norm|mag|"
"LeftParentheses|RightParentheses|"
"Divide|Multiply|Minus|Plus)$");
QList<QToolButton*> buttons;
buttons = this->findChildren<QToolButton*>(regexp);
foreach (QToolButton* tb, buttons)
{
QSignalMapper* mapper = new QSignalMapper(tb);
QObject::connect(tb, SIGNAL(pressed()), mapper, SLOT(map()));
mapper->setMapping(tb, tb->text());
QObject::connect(
mapper, SIGNAL(mapped(const QString&)), this, SLOT(buttonPressed(const QString&)));
QObject::connect(tb, &QToolButton::pressed, this, [=]() { this->buttonPressed(tb->text()); });
}
QToolButton* tb = this->Internals->xy;
QSignalMapper* mapper = new QSignalMapper(tb);
QObject::connect(tb, SIGNAL(pressed()), mapper, SLOT(map()));
mapper->setMapping(tb, "^");
QObject::connect(
mapper, SIGNAL(mapped(const QString&)), this, SLOT(buttonPressed(const QString&)));
tb = this->Internals->v1v2;
mapper = new QSignalMapper(tb);
QObject::connect(tb, SIGNAL(pressed()), mapper, SLOT(map()));
mapper->setMapping(tb, ".");
this->Internals->xy, &QToolButton::pressed, this, [=]() { this->buttonPressed("^"); });
QObject::connect(
mapper, SIGNAL(mapped(const QString&)), this, SLOT(buttonPressed(const QString&)));
this->Internals->v1v2, &QToolButton::pressed, this, [=]() { this->buttonPressed("."); });
//--------------------------------------------------------------------------
this->addPropertyLink(
......
......@@ -40,7 +40,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QItemDelegate>
#include <QLineEdit>
#include <QPointer>
#include <QSignalMapper>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QVBoxLayout>
......@@ -247,8 +246,6 @@ public:
pqInternal(pqKeyFrameEditor* editor)
: Editor(editor)
{
QObject::connect(
&this->CameraMapper, SIGNAL(mapped(QObject*)), editor, SLOT(useCurrentCamera(QObject*)));
}
pqKeyFrameEditor* const Editor;
Ui::pqKeyFrameEditor Ui;
......@@ -258,7 +255,6 @@ public:
QPair<double, double> TimeRange;
QPair<QVariant, QVariant> ValueRange;
pqKeyFrameEditorDelegate* EditorDelegate;
QSignalMapper CameraMapper;
double normalizedTime(double t)
{
......@@ -325,9 +321,8 @@ public:
pqCameraKeyFrameItem* item = NULL;
item = new pqCameraKeyFrameItem();
QObject::connect(
&item->CamWidget, SIGNAL(useCurrentCamera()), &this->CameraMapper, SLOT(map()));
this->CameraMapper.setMapping(&item->CamWidget, item);
QObject::connect(&item->CamWidget, &pqCameraKeyFrameWidget::useCurrentCamera, this->Editor,
[=]() { this->Editor->useCurrentCamera(item); });
// default to current view
this->Editor->useCurrentCamera(item);
item->CamWidget.setUsePathBasedMode(
......@@ -486,9 +481,8 @@ void pqKeyFrameEditor::readKeyFrameData()
if ((i < numberKeyFrames - 1) || !path_based)
{
pqCameraKeyFrameItem* item = new pqCameraKeyFrameItem();
QObject::connect(
&item->CamWidget, SIGNAL(useCurrentCamera()), &this->Internal->CameraMapper, SLOT(map()));
this->Internal->CameraMapper.setMapping(&item->CamWidget, item);
QObject::connect(&item->CamWidget, &pqCameraKeyFrameWidget::useCurrentCamera, this,
[=]() { this->Internal->Editor->useCurrentCamera(item); });
item->CamWidget.setUsePathBasedMode(path_based);
item->CamWidget.initializeUsingKeyFrame(keyFrame);
this->Internal->Model.setItem(i, 1, item);
......
......@@ -413,11 +413,19 @@ void RankData::InitializeMemoryUseWidget()
pid->setAutoFillBackground(true);
QFontMetrics fontMet(font);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int rankWid = fontMet.horizontalAdvance("555555");
#else
int rankWid = fontMet.width("555555");
#endif
rank->setMinimumWidth(rankWid);
rank->setMaximumWidth(rankWid);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int pidWid = fontMet.horizontalAdvance("555555555");
#else
int pidWid = fontMet.width("555555555");
#endif
pid->setMinimumWidth(pidWid);
pid->setMaximumWidth(pidWid);
......
......@@ -58,7 +58,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QApplication>
#include <QFont>
#include <QSignalMapper>
#include <QString>
#include <QStyle>
#include <QtDebug>
......
......@@ -360,7 +360,14 @@ pqStringVectorPropertyWidget::pqStringVectorPropertyWidget(
textEdit->setFont(textFont);
textEdit->setObjectName(smProxy->GetPropertyName(smProperty));
textEdit->setAcceptRichText(false);
textEdit->setTabStopWidth(2);
// tab is 2 spaces
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
textEdit->setTabStopDistance(this->fontMetrics().horizontalAdvance(" "));
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
textEdit->setTabStopDistance(this->fontMetrics().width(" "));
#else
textEdit->setTabStopWidth(this->fontMetrics().width(" "));
#endif
textEdit->setLineWrapMode(QTextEdit::NoWrap);
this->setChangeAvailableAsChangeFinished(false);
......
......@@ -208,7 +208,7 @@ void pqFileDialogTestWidget::emittedFiles(const QList<QStringList>& files)
void pqFileDialogTestWidget::record()
{
QString file = QFileDialog::getSaveFileName();
if (file != QString::null)
if (!file.isNull())
{
this->TestUtility.recordTests(file);
}
......
......@@ -698,7 +698,7 @@ void pqApplicationCore::registerDocumentation(const QString& filename)
// QHelpEngine doesn't like files from resource space. So we create a local
// file and use that.
QTemporaryFile* localFile = QTemporaryFile::createLocalFile(filename);
QTemporaryFile* localFile = QTemporaryFile::createNativeFile(filename);
if (localFile)
{
// localFile has autoRemove ON by default, so the file will be deleted with
......
......@@ -41,7 +41,6 @@ class pqServer;
class pqView;
class pqPipelineSource;
class vtkSMCollaborationManager;
class QSignalMapper;
class QMouseEvent;
/**
......
......@@ -396,10 +396,17 @@ pqFileDialog::pqFileDialog(pqServer* server, QWidget* p, const QString& title,
// This code is similar to QFileDialog code
// It positions different columns and orders in a standard way
QFontMetrics fm(this->font());
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
header->resizeSection(0, fm.horizontalAdvance(QLatin1String("wwwwwwwwwwwwwwwwwwwwwwwwww")));
header->resizeSection(1, fm.horizontalAdvance(QLatin1String("mp3Folder")));
header->resizeSection(2, fm.horizontalAdvance(QLatin1String("128.88 GB")));
header->resizeSection(3, fm.horizontalAdvance(QLatin1String("10/29/81 02:02PM")));
#else
header->resizeSection(0, fm.width(QLatin1String("wwwwwwwwwwwwwwwwwwwwwwwwww")));
header->resizeSection(1, fm.width(QLatin1String("mp3Folder")));
header->resizeSection(2, fm.width(QLatin1String("128.88 GB")));
header->resizeSection(3, fm.width(QLatin1String("10/29/81 02:02PM")));
#endif
impl.Ui.Files->setSortingEnabled(true);
impl.Ui.Files->header()->setSortIndicator(0, Qt::AscendingOrder);
......@@ -854,7 +861,7 @@ void pqFileDialog::onFilterChange(const QString& filter)
impl.FileFilter.setFilter(filter);
// update view
impl.FileFilter.clear();
impl.FileFilter.invalidate();
}
//-----------------------------------------------------------------------------
......
......@@ -36,7 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QDialog>
#include <QDockWidget>
#include <QFile>
#include <QGuiApplication>
#include <QMainWindow>
#include <QScreen>
#include "vtkSMProperty.h"
#include "vtkSMPropertyHelper.h"
......@@ -181,8 +183,7 @@ void pqSettings::saveInQSettings(const char* key, vtkSMProperty* smproperty)
void pqSettings::sanityCheckDock(QDockWidget* dock_widget)
{
QDesktopWidget desktop;
int screen = -1;
if (NULL == dock_widget)
if (nullptr == dock_widget)
{
return;
}
......@@ -193,14 +194,9 @@ void pqSettings::sanityCheckDock(QDockWidget* dock_widget)
QRect geometry = QRect(dockTopLeft, dock_widget->frameSize());
int titleBarHeight = geometry.height() - dockRect.height();
screen = desktop.screenNumber(dock_widget);
if (screen == -1) // Dock is at least partially on a screen
{
screen = desktop.screenNumber(dockTopLeft);
}
QRect screenRect = desktop.availableGeometry(screen);
QRect desktopRect = desktop.availableGeometry(); // SHould give us the entire Desktop geometry
QRect screenRect = desktop.availableGeometry(dock_widget);
QRect desktopRect = QGuiApplication::primaryScreen()
->availableGeometry(); // Should give us the entire Desktop geometry
// Ensure the top left corner of the window is on the screen
if (!screenRect.contains(dockTopLeft))
{
......
......@@ -45,6 +45,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QFontMetrics>
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
......@@ -61,7 +62,14 @@ pqPythonScriptEditor::pqPythonScriptEditor(QWidget* p)
{
this->pythonManager = NULL;
this->TextEdit = new QTextEdit;
this->TextEdit->setTabStopWidth(4);
// tab is 4 spaces
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
this->TextEdit->setTabStopDistance(this->fontMetrics().horizontalAdvance(" "));
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
this->TextEdit->setTabStopDistance(this->fontMetrics().width(" "));
#else
this->TextEdit->setTabStopWidth(this->fontMetrics().width(" "));
#endif
this->setCentralWidget(this->TextEdit);
this->createActions();
this->createMenus();
......
......@@ -124,7 +124,13 @@ pqPythonSyntaxHighlighter::pqPythonSyntaxHighlighter(QTextEdit* textEdit, QObjec
this->Internals->TextEdit->setFont(font);
// Set tab width equal to 4 spaces
QFontMetrics metrics = this->Internals->TextEdit->fontMetrics();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
this->Internals->TextEdit->setTabStopDistance(metrics.horizontalAdvance(" "));
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
this->TextEdit->setTabStopDistance(metrics.width(" "));
#else
this->Internals->TextEdit->setTabStopWidth(metrics.width(" "));
#endif
this->rehighlightSyntax();
}
......
......@@ -177,13 +177,25 @@ void pqAnimationKeyFrame::paint(QPainter* painter, const QStyleOptionGraphicsIte
QPointF pt(keyFrameRect.left() + 3.0,
keyFrameRect.top() + 0.5 * keyFrameRect.height() + metrics.height() / 2.0 - 1.0);
painter->drawText(pt, label);
iconWidth -= metrics.width(label);
double hAdvance;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
hAdvance = metrics.horizontalAdvance(label);
#else
hAdvance = metrics.width(label);
#endif
iconWidth -= hAdvance;
label = metrics.elidedText(endValue().toString(), Qt::ElideRight, qRound(halfWidth));
pt = QPointF(keyFrameRect.right() - metrics.width(label) - 3.0,
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
hAdvance = metrics.horizontalAdvance(label);
#else
hAdvance = metrics.width(label);
#endif
pt = QPointF(keyFrameRect.right() - hAdvance - 3.0,
keyFrameRect.top() + 0.5 * keyFrameRect.height() + metrics.height() / 2.0 - 1.0);
painter->drawText(pt, label);
iconWidth -= metrics.width(label);
iconWidth -= hAdvance;
if (iconWidth >= 16)
{
......
......@@ -160,7 +160,11 @@ QSize pqCollapsedGroup::minimumSizeHint() const
{
QStyleOptionGroupBox option = pqCollapseGroupGetStyleOption(this);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int baseWidth = fontMetrics().horizontalAdvance(this->title() + QLatin1Char(' '));
#else
int baseWidth = fontMetrics().width(this->title() + QLatin1Char(' '));
#endif
int baseHeight = fontMetrics().height();
baseWidth += this->style()->pixelMetric(QStyle::PM_IndicatorWidth);
......
......@@ -3138,8 +3138,12 @@ int pqFlatTreeView::getDataWidth(const QModelIndex& index, const QFontMetrics& f
}
else
{
// Find the font width for the string.
// Find the font width for the string.
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
return fm.horizontalAdvance(indexData.toString());
#else
return fm.width(indexData.toString());
#endif
}
}
......@@ -3764,8 +3768,7 @@ void pqFlatTreeView::drawData(QPainter& painter, int px, int py, const QModelInd
// so it fits. Use the text elide style from the options.
if (itemWidth > columnWidth)
{
text = QAbstractItemDelegate::elidedText(
options.fontMetrics, columnWidth, options.textElideMode, text);
text = options.fontMetrics.elidedText(text, options.textElideMode, columnWidth);
}
painter.drawText(px, py + fontAscent, text);
......
......@@ -148,7 +148,7 @@ void pqHelpWindow::showPage(const QUrl& url)
//-----------------------------------------------------------------------------
void pqHelpWindow::search()
{
QList<QHelpSearchQuery> query = this->HelpEngine->searchEngine()->queryWidget()->query();
QString query = this->HelpEngine->searchEngine()->queryWidget()->searchInput();
this->HelpEngine->searchEngine()->search(query);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment