Use QSharedPointer::create() more

This is the result of running the (experimental) clang-tidy check
   qt-modernize-qsharedpointer-create

Discarded changes:

- tst_qsharedpointer.cpp: not sure we want these replacements there
  (→ separate change)
- tst_collations.cpp: hit in a template specialization that is
  instantiated with both QSharedPointer and QSharedDataPointer.

Change-Id: I203c2646e91d026735d923473af3d151d19e3820
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2017-07-13 17:19:49 +02:00
parent ad68bf51e7
commit 94cf203f36
9 changed files with 19 additions and 19 deletions

View File

@ -228,7 +228,7 @@ QByteArray const &tst_LargeFile::getDataBlock(int index, qint64 position)
void tst_LargeFile::initTestCase()
{
m_previousCurrent = QDir::currentPath();
m_tempDir = QSharedPointer<QTemporaryDir>(new QTemporaryDir);
m_tempDir = QSharedPointer<QTemporaryDir>::create();
QVERIFY2(!m_tempDir.isNull(), qPrintable("Could not create temporary directory."));
QVERIFY2(QDir::setCurrent(m_tempDir->path()), qPrintable("Could not switch current directory"));

View File

@ -466,7 +466,7 @@ protected:
if (create) {
QSharedPointer<File> &p = fileSystem[fileName_];
if (p.isNull())
p = QSharedPointer<File>(new File);
p = QSharedPointer<File>::create();
return p;
}
@ -564,7 +564,7 @@ class FileEngineHandler
void tst_QAbstractFileEngine::initTestCase()
{
m_previousCurrent = QDir::currentPath();
m_currentDir = QSharedPointer<QTemporaryDir>(new QTemporaryDir());
m_currentDir = QSharedPointer<QTemporaryDir>::create();
QVERIFY2(!m_currentDir.isNull(), qPrintable("Could not create current directory."));
QDir::setCurrent(m_currentDir->path());
}

View File

@ -300,7 +300,7 @@ void tst_QDataStream::getSetCheck()
void tst_QDataStream::initTestCase()
{
m_previousCurrent = QDir::currentPath();
m_tempDir = QSharedPointer<QTemporaryDir>(new QTemporaryDir);
m_tempDir = QSharedPointer<QTemporaryDir>::create();
QVERIFY2(!m_tempDir.isNull(), qPrintable("Could not create temporary directory."));
QVERIFY2(QDir::setCurrent(m_tempDir->path()), qPrintable("Could not switch current directory"));
}

View File

@ -71,7 +71,7 @@ void tst_QIODevice::initTestCase()
|| QFile::copy(QStringLiteral(":/tst_qiodevice.cpp"), QStringLiteral("./tst_qiodevice.cpp")));
#endif
m_previousCurrent = QDir::currentPath();
m_tempDir = QSharedPointer<QTemporaryDir>(new QTemporaryDir);
m_tempDir = QSharedPointer<QTemporaryDir>::create();
QVERIFY2(!m_tempDir.isNull(), qPrintable("Could not create temporary directory."));
QVERIFY2(QDir::setCurrent(m_tempDir->path()), qPrintable("Could not switch current directory"));
}

View File

@ -56,7 +56,7 @@ class tst_QDBusAbstractInterface: public QObject
return Pinger();
if (service.isEmpty() && !service.isNull())
service = con.baseService();
return Pinger(new org::qtproject::QtDBus::Pinger(service, path, con));
return Pinger::create(service, path, con);
}
Pinger getPingerPeer(const QString &path = "/", const QString &service = "")
@ -64,7 +64,7 @@ class tst_QDBusAbstractInterface: public QObject
QDBusConnection con = QDBusConnection("peer");
if (!con.isConnected())
return Pinger();
return Pinger(new org::qtproject::QtDBus::Pinger(service, path, con));
return Pinger::create(service, path, con);
}
void resetServer()

View File

@ -205,7 +205,7 @@ void tst_QFtp::initTestCase()
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
#ifndef QT_NO_BEARERMANAGEMENT
QNetworkConfigurationManager manager;
networkSessionImplicit = QSharedPointer<QNetworkSession>(new QNetworkSession(manager.defaultConfiguration()));
networkSessionImplicit = QSharedPointer<QNetworkSession>::create(manager.defaultConfiguration());
networkSessionImplicit->open();
QVERIFY(networkSessionImplicit->waitForOpened(60000)); //there may be user prompt on 1st connect
#endif

View File

@ -213,7 +213,7 @@ void tst_QUdpSocket::initTestCase_data()
#ifndef QT_NO_BEARERMANAGEMENT
netConfMan = new QNetworkConfigurationManager(this);
networkConfiguration = netConfMan->defaultConfiguration();
networkSession = QSharedPointer<QNetworkSession>(new QNetworkSession(networkConfiguration));
networkSession = QSharedPointer<QNetworkSession>::create(networkConfiguration);
if (!networkSession->isOpen()) {
networkSession->open();
QVERIFY(networkSession->waitForOpened(30000));

View File

@ -3442,7 +3442,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+ */
keyPresses.clear();
keyPresses << Qt::Key_Right << Qt::Key_Down;
model.reset(new QStandardItemModel(4, 2));
model = QSharedPointer<QStandardItemModel>::create(4, 2);
QTest::newRow("row span, top down")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1);
@ -3455,7 +3455,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+ */
keyPresses.clear();
keyPresses << Qt::Key_End << Qt::Key_Down << Qt::Key_Left;
model.reset(new QStandardItemModel(3, 3));
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("row span, right to left")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1);
@ -3468,7 +3468,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+ */
keyPresses.clear();
keyPresses << Qt::Key_PageDown << Qt::Key_Right;
model.reset(new QStandardItemModel(3, 3));
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("row span, left to right")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1);
@ -3481,7 +3481,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+ */
keyPresses.clear();
keyPresses << Qt::Key_PageDown << Qt::Key_Up;
model.reset(new QStandardItemModel(3, 3));
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, bottom up")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 0) << model->index(1, 0);
@ -3494,7 +3494,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+ */
keyPresses.clear();
keyPresses << Qt::Key_PageDown << Qt::Key_Right << Qt::Key_Up;
model.reset(new QStandardItemModel(3, 3));
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, bottom up #2")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 1) << model->index(1, 0);
@ -3507,7 +3507,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+ */
keyPresses.clear();
keyPresses << Qt::Key_End << Qt::Key_Down;
model.reset(new QStandardItemModel(3, 3));
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, top down")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 2) << model->index(1, 0);
}

View File

@ -5753,14 +5753,14 @@ void tst_QWidget::testWindowIconChangeEventPropagation()
QList <EventSpyPtr> applicationEventSpies;
QList <EventSpyPtr> widgetEventSpies;
foreach (QWidget *widget, widgets) {
applicationEventSpies.append(EventSpyPtr(new EventSpy<QWidget>(widget, QEvent::ApplicationWindowIconChange)));
widgetEventSpies.append(EventSpyPtr(new EventSpy<QWidget>(widget, QEvent::WindowIconChange)));
applicationEventSpies.append(EventSpyPtr::create(widget, QEvent::ApplicationWindowIconChange));
widgetEventSpies.append(EventSpyPtr::create(widget, QEvent::WindowIconChange));
}
QList <WindowEventSpyPtr> appWindowEventSpies;
QList <WindowEventSpyPtr> windowEventSpies;
foreach (QWindow *window, windows) {
appWindowEventSpies.append(WindowEventSpyPtr(new EventSpy<QWindow>(window, QEvent::ApplicationWindowIconChange)));
windowEventSpies.append(WindowEventSpyPtr(new EventSpy<QWindow>(window, QEvent::WindowIconChange)));
appWindowEventSpies.append(WindowEventSpyPtr::create(window, QEvent::ApplicationWindowIconChange));
windowEventSpies.append(WindowEventSpyPtr::create(window, QEvent::WindowIconChange));
}
// QApplication::setWindowIcon