diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2015-10-07 12:03:05 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-10-09 15:59:21 +0000 |
commit | c8cd9f1b9a3d338a12bdccce957d74d515eb9c32 (patch) | |
tree | fca6b64875083ce22716c1ed3c6633459bfb93c2 /examples/widgets/draganddrop/dropsite | |
parent | c55a36cb9015cf1eebd49eaa5b1b4f4ec9b28451 (diff) |
Polish DnD Examples.
- Remove class DragLabel in draggabletext and add a static creation
function instead since it only has a constructor setting some
properties.
- Use QRegularExpression instead of QRegExp
- Use new connection syntax.
- Ensure compilation with
DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
demonstrating use of QLatin1String vs QStringLiteral.
- Streamline code.
Change-Id: I2e2ddeb40837dba379990836c77fb72ad7263e2d
Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
Diffstat (limited to 'examples/widgets/draganddrop/dropsite')
-rw-r--r-- | examples/widgets/draganddrop/dropsite/droparea.cpp | 6 | ||||
-rw-r--r-- | examples/widgets/draganddrop/dropsite/dropsitewindow.cpp | 27 |
2 files changed, 13 insertions, 20 deletions
diff --git a/examples/widgets/draganddrop/dropsite/droparea.cpp b/examples/widgets/draganddrop/dropsite/droparea.cpp index d3d2bb10ca..0016434cc3 100644 --- a/examples/widgets/draganddrop/dropsite/droparea.cpp +++ b/examples/widgets/draganddrop/dropsite/droparea.cpp @@ -92,10 +92,8 @@ void DropArea::dropEvent(QDropEvent *event) } else if (mimeData->hasUrls()) { QList<QUrl> urlList = mimeData->urls(); QString text; - for (int i = 0; i < urlList.size() && i < 32; ++i) { - QString url = urlList.at(i).path(); - text += url + QString("\n"); - } + for (int i = 0; i < urlList.size() && i < 32; ++i) + text += urlList.at(i).path() + QLatin1Char('\n'); setText(text); } else { setText(tr("Cannot display data")); diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp index 5f0e689fc9..5d48be1c34 100644 --- a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp +++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp @@ -55,8 +55,8 @@ DropSiteWindow::DropSiteWindow() //! [constructor part2] dropArea = new DropArea; - connect(dropArea, SIGNAL(changed(const QMimeData*)), - this, SLOT(updateFormatsTable(const QMimeData*))); + connect(dropArea, &DropArea::changed, + this, &DropSiteWindow::updateFormatsTable); //! [constructor part2] //! [constructor part3] @@ -78,17 +78,16 @@ DropSiteWindow::DropSiteWindow() buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole); buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); - connect(quitButton, SIGNAL(pressed()), this, SLOT(close())); - connect(clearButton, SIGNAL(pressed()), dropArea, SLOT(clear())); + connect(quitButton, &QAbstractButton::pressed, this, &QWidget::close); + connect(clearButton, &QAbstractButton::pressed, dropArea, &DropArea::clear); //! [constructor part4] //! [constructor part5] - QVBoxLayout *mainLayout = new QVBoxLayout; + QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addWidget(abstractLabel); mainLayout->addWidget(dropArea); mainLayout->addWidget(formatsTable); mainLayout->addWidget(buttonBox); - setLayout(mainLayout); setWindowTitle(tr("Drop Site")); setMinimumSize(350, 500); @@ -112,22 +111,18 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData) //! [updateFormatsTable() part3] QString text; - if (format == "text/plain") { + if (format == QLatin1String("text/plain")) { text = mimeData->text().simplified(); - } else if (format == "text/html") { + } else if (format == QLatin1String("text/html")) { text = mimeData->html().simplified(); - } else if (format == "text/uri-list") { + } else if (format == QLatin1String("text/uri-list")) { QList<QUrl> urlList = mimeData->urls(); for (int i = 0; i < urlList.size() && i < 32; ++i) - text.append(urlList[i].toString() + " "); + text.append(urlList.at(i).toString() + QLatin1Char(' ')); } else { QByteArray data = mimeData->data(format); - for (int i = 0; i < data.size() && i < 32; ++i) { - QString hex = QString("%1").arg(uchar(data[i]), 2, 16, - QChar('0')) - .toUpper(); - text.append(hex + " "); - } + for (int i = 0; i < data.size() && i < 32; ++i) + text.append(QStringLiteral("%1 ").arg(uchar(data[i]), 2, 16, QLatin1Char('0')).toUpper()); } //! [updateFormatsTable() part3] |