From 75e8aaae5e8a0cbaa62fd4cd2a8235544f974a73 Mon Sep 17 00:00:00 2001 From: Stian Sandvik Thomassen Date: Thu, 18 Jun 2009 14:53:03 +1000 Subject: Made QInputDialog::getText() return null QString when rejected This reverts a behavior change introduced with Qt 4.5.0 where QInputDialog::getText() returned the line edit's text when the dialog was rejected. However, the behavior since Qt 4.0 has been to return a null QString when the dialog is rejected. Task-number: 256299 Reviewed-by: Andy Shaw --- src/gui/dialogs/qinputdialog.cpp | 6 +++--- tests/auto/qinputdialog/tst_qinputdialog.cpp | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/gui/dialogs/qinputdialog.cpp b/src/gui/dialogs/qinputdialog.cpp index 7f21d3d..d94d8fe 100644 --- a/src/gui/dialogs/qinputdialog.cpp +++ b/src/gui/dialogs/qinputdialog.cpp @@ -1129,8 +1129,8 @@ void QInputDialog::done(int result) is \a parent. The dialog will be modal and uses the specified widget \a flags. - This function returns the text which has been entered in the line - edit. It will not return an empty string. + If the dialog is accepted, this function returns the text in the dialog's + line edit. If the dialog is rejected, a null QString is returned. Use this static function like this: @@ -1159,7 +1159,7 @@ QString QInputDialog::getText(QWidget *parent, const QString &title, const QStri if (ret) { return dialog.textValue(); } else { - return text; + return QString(); } } diff --git a/tests/auto/qinputdialog/tst_qinputdialog.cpp b/tests/auto/qinputdialog/tst_qinputdialog.cpp index a658aeb..7e4b828 100644 --- a/tests/auto/qinputdialog/tst_qinputdialog.cpp +++ b/tests/auto/qinputdialog/tst_qinputdialog.cpp @@ -56,6 +56,7 @@ class tst_QInputDialog : public QObject { Q_OBJECT QWidget *parent; + QDialog::DialogCode doneCode; void (*testFunc)(QInputDialog *); static void testFuncGetInteger(QInputDialog *dialog); static void testFuncGetDouble(QInputDialog *dialog); @@ -72,6 +73,7 @@ private slots: void getText(); void getItem_data(); void getItem(); + void task256299_getTextReturnNullStringOnRejected(); }; QString stripFraction(const QString &s) @@ -245,8 +247,9 @@ void tst_QInputDialog::timerEvent(QTimerEvent *event) killTimer(event->timerId()); QInputDialog *dialog = qFindChild(parent); Q_ASSERT(dialog); - testFunc(dialog); - dialog->done(QDialog::Accepted); // cause static function call to return + if (testFunc) + testFunc(dialog); + dialog->done(doneCode); // cause static function call to return } void tst_QInputDialog::getInteger_data() @@ -266,6 +269,7 @@ void tst_QInputDialog::getInteger() QFETCH(int, max); Q_ASSERT(min < max); parent = new QWidget; + doneCode = QDialog::Accepted; testFunc = &tst_QInputDialog::testFuncGetInteger; startTimer(0); bool ok = false; @@ -305,6 +309,7 @@ void tst_QInputDialog::getDouble() QFETCH(int, decimals); Q_ASSERT(min < max && decimals >= 0 && decimals <= 13); parent = new QWidget; + doneCode = QDialog::Accepted; testFunc = &tst_QInputDialog::testFuncGetDouble; startTimer(0); bool ok = false; @@ -322,6 +327,7 @@ void tst_QInputDialog::getDouble() void tst_QInputDialog::task255502getDouble() { parent = new QWidget; + doneCode = QDialog::Accepted; testFunc = &tst_QInputDialog::testFuncGetDouble; startTimer(0); bool ok = false; @@ -347,6 +353,7 @@ void tst_QInputDialog::getText() { QFETCH(QString, text); parent = new QWidget; + doneCode = QDialog::Accepted; testFunc = &tst_QInputDialog::testFuncGetText; startTimer(0); bool ok = false; @@ -356,6 +363,19 @@ void tst_QInputDialog::getText() delete parent; } +void tst_QInputDialog::task256299_getTextReturnNullStringOnRejected() +{ + parent = new QWidget; + doneCode = QDialog::Rejected; + testFunc = 0; + startTimer(0); + bool ok = true; + const QString result = QInputDialog::getText(parent, "", "", QLineEdit::Normal, "foobar", &ok); + QVERIFY(!ok); + QVERIFY(result.isNull()); + delete parent; +} + void tst_QInputDialog::getItem_data() { QTest::addColumn("items"); @@ -373,6 +393,7 @@ void tst_QInputDialog::getItem() QFETCH(QStringList, items); QFETCH(bool, editable); parent = new QWidget; + doneCode = QDialog::Accepted; testFunc = &tst_QInputDialog::testFuncGetItem; startTimer(0); bool ok = false; -- cgit v0.12 From 472ab7c60a6ede66565166fa21d6642a918f7403 Mon Sep 17 00:00:00 2001 From: kh Date: Thu, 18 Jun 2009 12:56:54 +0200 Subject: Cleanup. Reviewed-by: kh --- .../assistant/tools/assistant/bookmarkmanager.cpp | 200 ++++++++++----------- tools/assistant/tools/assistant/bookmarkmanager.h | 16 +- 2 files changed, 99 insertions(+), 117 deletions(-) diff --git a/tools/assistant/tools/assistant/bookmarkmanager.cpp b/tools/assistant/tools/assistant/bookmarkmanager.cpp index fbd9923..336c856 100644 --- a/tools/assistant/tools/assistant/bookmarkmanager.cpp +++ b/tools/assistant/tools/assistant/bookmarkmanager.cpp @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE BookmarkDialog::BookmarkDialog(BookmarkManager *manager, const QString &title, - const QString &url, QWidget *parent) + const QString &url, QWidget *parent) : QDialog(parent) , m_url(url) , m_title(title) @@ -95,21 +95,21 @@ BookmarkDialog::BookmarkDialog(BookmarkManager *manager, const QString &title, connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(addAccepted())); connect(ui.newFolderButton, SIGNAL(clicked()), this, SLOT(addNewFolder())); connect(ui.toolButton, SIGNAL(clicked()), this, SLOT(toolButtonClicked())); - connect(ui.bookmarkEdit, SIGNAL(textChanged(const QString&)), this, - SLOT(textChanged(const QString&))); + connect(ui.bookmarkEdit, SIGNAL(textChanged(QString)), this, + SLOT(textChanged(QString))); - connect(bookmarkManager->treeBookmarkModel(), SIGNAL(itemChanged(QStandardItem*)), + connect(bookmarkManager->treeBookmarkModel(), + SIGNAL(itemChanged(QStandardItem*)), this, SLOT(itemChanged(QStandardItem*))); - connect(ui.bookmarkFolders, SIGNAL(currentIndexChanged(const QString&)), this, - SLOT(selectBookmarkFolder(const QString&))); + connect(ui.bookmarkFolders, SIGNAL(currentIndexChanged(QString)), this, + SLOT(selectBookmarkFolder(QString))); - connect(ui.treeView, SIGNAL(customContextMenuRequested(const QPoint&)), this, - SLOT(customContextMenuRequested(const QPoint&))); + connect(ui.treeView, SIGNAL(customContextMenuRequested(QPoint)), this, + SLOT(customContextMenuRequested(QPoint))); - connect(ui.treeView->selectionModel(), - SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), - this, SLOT(currentChanged(const QModelIndex&, const QModelIndex&))); + connect(ui.treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, + QModelIndex)), this, SLOT(currentChanged(QModelIndex))); } BookmarkDialog::~BookmarkDialog() @@ -118,8 +118,8 @@ BookmarkDialog::~BookmarkDialog() void BookmarkDialog::addAccepted() { - const QItemSelection selection = ui.treeView->selectionModel()->selection(); - const QModelIndexList list = selection.indexes(); + QItemSelectionModel *model = ui.treeView->selectionModel(); + const QModelIndexList &list = model->selection().indexes(); QModelIndex index; if (!list.isEmpty()) @@ -131,8 +131,8 @@ void BookmarkDialog::addAccepted() void BookmarkDialog::addNewFolder() { - const QItemSelection selection = ui.treeView->selectionModel()->selection(); - const QModelIndexList list = selection.indexes(); + QItemSelectionModel *model = ui.treeView->selectionModel(); + const QModelIndexList &list = model->selection().indexes(); QModelIndex index; if (!list.isEmpty()) @@ -143,13 +143,12 @@ void BookmarkDialog::addNewFolder() if (newFolder.isValid()) { ui.treeView->expand(index); const QModelIndex &index = proxyModel->mapFromSource(newFolder); - ui.treeView->selectionModel()->setCurrentIndex(index, - QItemSelectionModel::ClearAndSelect); + model->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); ui.bookmarkFolders->clear(); ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders()); - const QString name = index.data().toString(); + const QString &name = index.data().toString(); ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name)); } ui.treeView->setFocus(); @@ -183,14 +182,14 @@ void BookmarkDialog::itemChanged(QStandardItem *item) ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders()); QString name = tr("Bookmarks"); - const QModelIndex& index = ui.treeView->currentIndex(); + const QModelIndex &index = ui.treeView->currentIndex(); if (index.isValid()) name = index.data().toString(); ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name)); } } -void BookmarkDialog::textChanged(const QString& string) +void BookmarkDialog::textChanged(const QString &string) { ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!string.isEmpty()); } @@ -209,9 +208,12 @@ void BookmarkDialog::selectBookmarkFolder(const QString &folderName) QList list = model->findItems(folderName, Qt::MatchCaseSensitive | Qt::MatchRecursive, 0); if (!list.isEmpty()) { - QModelIndex index = model->indexFromItem(list.at(0)); - ui.treeView->selectionModel()->setCurrentIndex( - proxyModel->mapFromSource(index), QItemSelectionModel::ClearAndSelect); + const QModelIndex &index = model->indexFromItem(list.at(0)); + QItemSelectionModel *model = ui.treeView->selectionModel(); + if (model) { + model->setCurrentIndex(proxyModel->mapFromSource(index), + QItemSelectionModel::ClearAndSelect); + } } } @@ -226,13 +228,13 @@ void BookmarkDialog::customContextMenuRequested(const QPoint &point) QAction *removeItem = menu.addAction(tr("Delete Folder")); QAction *renameItem = menu.addAction(tr("Rename Folder")); - QAction *picked_action = menu.exec(ui.treeView->mapToGlobal(point)); - if (!picked_action) + QAction *picked = menu.exec(ui.treeView->mapToGlobal(point)); + if (!picked) return; - if (picked_action == removeItem) { - bookmarkManager->removeBookmarkItem(ui.treeView, - proxyModel->mapToSource(index)); + const QModelIndex &proxyIndex = proxyModel->mapToSource(index); + if (picked == removeItem) { + bookmarkManager->removeBookmarkItem(ui.treeView, proxyIndex); ui.bookmarkFolders->clear(); ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders()); @@ -242,10 +244,9 @@ void BookmarkDialog::customContextMenuRequested(const QPoint &point) name = index.data().toString(); ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name)); } - else if (picked_action == renameItem) { - QStandardItem *item = bookmarkManager->treeBookmarkModel()-> - itemFromIndex(proxyModel->mapToSource(index)); - if (item) { + else if (picked == renameItem) { + BookmarkModel *model = bookmarkManager->treeBookmarkModel(); + if (QStandardItem *item = model->itemFromIndex(proxyIndex)) { item->setEditable(true); ui.treeView->edit(index); item->setEditable(false); @@ -253,19 +254,12 @@ void BookmarkDialog::customContextMenuRequested(const QPoint &point) } } -void BookmarkDialog::currentChanged(const QModelIndex& current, - const QModelIndex& previous) +void BookmarkDialog::currentChanged(const QModelIndex ¤t) { - Q_UNUSED(previous) - - if (!current.isValid()) { - ui.bookmarkFolders->setCurrentIndex( - ui.bookmarkFolders->findText(tr("Bookmarks"))); - return; - } - - ui.bookmarkFolders->setCurrentIndex( - ui.bookmarkFolders->findText(current.data().toString())); + QString text = tr("Bookmarks"); + if (current.isValid()) + text = current.data().toString(); + ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(text)); } bool BookmarkDialog::eventFilter(QObject *object, QEvent *e) @@ -276,7 +270,7 @@ bool BookmarkDialog::eventFilter(QObject *object, QEvent *e) QModelIndex index = ui.treeView->currentIndex(); switch (ke->key()) { case Qt::Key_F2: { - const QModelIndex& source = proxyModel->mapToSource(index); + const QModelIndex &source = proxyModel->mapToSource(index); QStandardItem *item = bookmarkManager->treeBookmarkModel()->itemFromIndex(source); if (item) { @@ -307,10 +301,11 @@ bool BookmarkDialog::eventFilter(QObject *object, QEvent *e) } +// #pragma mark -- BookmarkWidget BookmarkWidget::BookmarkWidget(BookmarkManager *manager, QWidget *parent, - bool showButtons) + bool showButtons) : QWidget(parent) , addButton(0) , removeButton(0) @@ -326,7 +321,7 @@ BookmarkWidget::~BookmarkWidget() void BookmarkWidget::removeClicked() { - const QModelIndex& index = treeView->currentIndex(); + const QModelIndex &index = treeView->currentIndex(); if (searchField->text().isEmpty()) { bookmarkManager->removeBookmarkItem(treeView, filterBookmarkModel->mapToSource(index)); @@ -360,10 +355,11 @@ void BookmarkWidget::filterChanged() expandItems(); } -void BookmarkWidget::expand(const QModelIndex& index) +void BookmarkWidget::expand(const QModelIndex &index) { - const QModelIndex& source = filterBookmarkModel->mapToSource(index); - QStandardItem *item = bookmarkManager->treeBookmarkModel()->itemFromIndex(source); + const QModelIndex &source = filterBookmarkModel->mapToSource(index); + QStandardItem *item = + bookmarkManager->treeBookmarkModel()->itemFromIndex(source); if (item) item->setData(treeView->isExpanded(index), Qt::UserRole + 11); } @@ -404,22 +400,22 @@ void BookmarkWidget::customContextMenuRequested(const QPoint &point) } } - QAction *picked_action = menu.exec(treeView->mapToGlobal(point)); - if (!picked_action) + QAction *pickedAction = menu.exec(treeView->mapToGlobal(point)); + if (!pickedAction) return; - if (picked_action == showItem) { + if (pickedAction == showItem) { emit requestShowLink(data); } - else if (picked_action == showItemNewTab) { + else if (pickedAction == showItemNewTab) { CentralWidget::instance()->setSourceInNewTab(data); } - else if (picked_action == removeItem) { + else if (pickedAction == removeItem) { bookmarkManager->removeBookmarkItem(treeView, filterBookmarkModel->mapToSource(index)); } - else if (picked_action == renameItem) { - const QModelIndex& source = filterBookmarkModel->mapToSource(index); + else if (pickedAction == renameItem) { + const QModelIndex &source = filterBookmarkModel->mapToSource(index); QStandardItem *item = bookmarkManager->treeBookmarkModel()->itemFromIndex(source); if (item) { @@ -443,7 +439,7 @@ void BookmarkWidget::setup(bool showButtons) searchField = new QLineEdit(this); vlayout->addWidget(searchField); - connect(searchField, SIGNAL(textChanged(const QString &)), this, + connect(searchField, SIGNAL(textChanged(QString)), this, SLOT(filterChanged())); treeView = new TreeView(this); @@ -490,17 +486,14 @@ void BookmarkWidget::setup(bool showButtons) treeView->viewport()->installEventFilter(this); treeView->setContextMenuPolicy(Qt::CustomContextMenu); - connect(treeView, SIGNAL(expanded(const QModelIndex&)), this, - SLOT(expand(const QModelIndex&))); - - connect(treeView, SIGNAL(collapsed(const QModelIndex&)), this, - SLOT(expand(const QModelIndex&))); - - connect(treeView, SIGNAL(activated(const QModelIndex&)), this, - SLOT(activated(const QModelIndex&))); - - connect(treeView, SIGNAL(customContextMenuRequested(const QPoint&)), - this, SLOT(customContextMenuRequested(const QPoint&))); + connect(treeView, SIGNAL(expanded(QModelIndex)), this, + SLOT(expand(QModelIndex))); + connect(treeView, SIGNAL(collapsed(QModelIndex)), this, + SLOT(expand(QModelIndex))); + connect(treeView, SIGNAL(activated(QModelIndex)), this, + SLOT(activated(QModelIndex))); + connect(treeView, SIGNAL(customContextMenuRequested(QPoint)), + this, SLOT(customContextMenuRequested(QPoint))); filterBookmarkModel->setFilterKeyColumn(0); filterBookmarkModel->setDynamicSortFilter(true); @@ -514,8 +507,8 @@ void BookmarkWidget::expandItems() QStandardItemModel *model = bookmarkManager->treeBookmarkModel(); QListlist = model->findItems(QLatin1String("*"), Qt::MatchWildcard | Qt::MatchRecursive, 0); - foreach (const QStandardItem* item, list) { - const QModelIndex& index = model->indexFromItem(item); + foreach (const QStandardItem *item, list) { + const QModelIndex &index = model->indexFromItem(item); treeView->setExpanded(filterBookmarkModel->mapFromSource(index), item->data(Qt::UserRole + 11).toBool()); } @@ -541,17 +534,17 @@ bool BookmarkWidget::eventFilter(QObject *object, QEvent *e) if (e->type() == QEvent::KeyPress) { QKeyEvent *ke = static_cast(e); if (index.isValid() && searchField->text().isEmpty()) { + const QModelIndex &src = filterBookmarkModel->mapToSource(index); if (ke->key() == Qt::Key_F2) { - QStandardItem *item = bookmarkManager->treeBookmarkModel() - ->itemFromIndex(filterBookmarkModel->mapToSource(index)); + QStandardItem *item = + bookmarkManager->treeBookmarkModel()->itemFromIndex(src); if (item) { item->setEditable(true); treeView->edit(index); item->setEditable(false); } } else if (ke->key() == Qt::Key_Delete) { - bookmarkManager->removeBookmarkItem(treeView, - filterBookmarkModel->mapToSource(index)); + bookmarkManager->removeBookmarkItem(treeView, src); } } @@ -559,7 +552,7 @@ bool BookmarkWidget::eventFilter(QObject *object, QEvent *e) default: break; case Qt::Key_Up: { case Qt::Key_Down: - treeView->subclassKeyPressEvent(ke); + treeView->subclassKeyPressEvent(ke); } break; case Qt::Key_Enter: { @@ -593,9 +586,10 @@ bool BookmarkWidget::eventFilter(QObject *object, QEvent *e) } +// #pragma mark -- BookmarkModel -BookmarkModel::BookmarkModel(int rows, int columns, QObject * parent) +BookmarkModel::BookmarkModel(int rows, int columns, QObject *parent) : QStandardItemModel(rows, columns, parent) { } @@ -619,16 +613,15 @@ Qt::ItemFlags BookmarkModel::flags(const QModelIndex &index) const } +// #pragma mark -- BookmarkManager -BookmarkManager::BookmarkManager(QHelpEngineCore* _helpEngine) +BookmarkManager::BookmarkManager(QHelpEngineCore *_helpEngine) : treeModel(new BookmarkModel(0, 1, this)) , listModel(new BookmarkModel(0, 1, this)) , helpEngine(_helpEngine) { folderIcon = QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon); - treeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Bookmark")); - listModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Bookmark")); connect(treeModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(itemChanged(QStandardItem*))); @@ -652,22 +645,10 @@ BookmarkModel* BookmarkManager::listBookmarkModel() void BookmarkManager::saveBookmarks() { - qint32 depth = 0; QByteArray bookmarks; QDataStream stream(&bookmarks, QIODevice::WriteOnly); - QStandardItem *root = treeModel->invisibleRootItem(); - - for (int i = 0; i < root->rowCount(); ++i) { - const QStandardItem *item = root->child(i); - stream << depth; // root - stream << item->data(Qt::DisplayRole).toString(); - stream << item->data(Qt::UserRole + 10).toString(); - stream << item->data(Qt::UserRole + 11).toBool(); - if (item->rowCount() > 0) { - readBookmarksRecursive(item, stream, (depth +1)); - } - } + readBookmarksRecursive(treeModel->invisibleRootItem(), stream, 0); helpEngine->setCustomValue(QLatin1String("Bookmarks"), bookmarks); } @@ -687,7 +668,7 @@ QStringList BookmarkManager::bookmarkFolders() const return folders; } -QModelIndex BookmarkManager::addNewFolder(const QModelIndex& index) +QModelIndex BookmarkManager::addNewFolder(const QModelIndex &index) { QStandardItem *item = new QStandardItem(uniqueFolderName()); item->setEditable(false); @@ -703,16 +684,17 @@ QModelIndex BookmarkManager::addNewFolder(const QModelIndex& index) return treeModel->indexFromItem(item); } -void BookmarkManager::removeBookmarkItem(QTreeView *treeView, const QModelIndex& index) +void BookmarkManager::removeBookmarkItem(QTreeView *treeView, + const QModelIndex &index) { QStandardItem *item = treeModel->itemFromIndex(index); if (item) { QString data = index.data(Qt::UserRole + 10).toString(); if (data == QLatin1String("Folder") && item->rowCount() > 0) { int value = QMessageBox::question(treeView, tr("Remove"), - tr("You are going to delete a Folder, this will also
" - "remove it's content. Are you sure to continue?"), - QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); + tr("You are going to delete a Folder, this will also
" + "remove it's content. Are you sure to continue?"), + QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); if (value == QMessageBox::Cancel) return; @@ -733,28 +715,26 @@ void BookmarkManager::removeBookmarkItem(QTreeView *treeView, const QModelIndex& } } -void BookmarkManager::showBookmarkDialog(QWidget* parent, const QString &name, - const QString &url) +void BookmarkManager::showBookmarkDialog(QWidget *parent, const QString &name, + const QString &url) { BookmarkDialog dialog(this, name, url, parent); dialog.exec(); } -void BookmarkManager::addNewBookmark(const QModelIndex& index, - const QString &name, const QString &url) +void BookmarkManager::addNewBookmark(const QModelIndex &index, + const QString &name, const QString &url) { QStandardItem *item = new QStandardItem(name); item->setEditable(false); item->setData(false, Qt::UserRole + 11); item->setData(url, Qt::UserRole + 10); - if (index.isValid()) { + if (index.isValid()) treeModel->itemFromIndex(index)->appendRow(item); - listModel->appendRow(item->clone()); - } else { + else treeModel->appendRow(item); - listModel->appendRow(item->clone()); - } + listModel->appendRow(item->clone()); } void BookmarkManager::itemChanged(QStandardItem *item) @@ -785,7 +765,8 @@ void BookmarkManager::setupBookmarkModels() QList lastDepths; QList parents; - QByteArray ba = helpEngine->customValue(QLatin1String("Bookmarks")).toByteArray(); + QByteArray ba = + helpEngine->customValue(QLatin1String("Bookmarks")).toByteArray(); QDataStream stream(ba); while (!stream.atEnd()) { stream >> depth >> name >> type >> expanded; @@ -855,8 +836,7 @@ void BookmarkManager::removeBookmarkFolderItems(QStandardItem *item) } void BookmarkManager::readBookmarksRecursive(const QStandardItem *item, - QDataStream &stream, - const qint32 depth) const + QDataStream &stream, const qint32 depth) const { for (int j = 0; j < item->rowCount(); ++j) { const QStandardItem *child = item->child(j); diff --git a/tools/assistant/tools/assistant/bookmarkmanager.h b/tools/assistant/tools/assistant/bookmarkmanager.h index 29da5f3..bf7af41 100644 --- a/tools/assistant/tools/assistant/bookmarkmanager.h +++ b/tools/assistant/tools/assistant/bookmarkmanager.h @@ -74,7 +74,7 @@ class BookmarkDialog : public QDialog Q_OBJECT public: - BookmarkDialog(BookmarkManager *manager, const QString &title, + BookmarkDialog(BookmarkManager *manager, const QString &title, const QString &url, QWidget *parent = 0); ~BookmarkDialog(); @@ -86,8 +86,8 @@ private slots: void textChanged(const QString& string); void selectBookmarkFolder(const QString &folderName); void customContextMenuRequested(const QPoint &point); - void currentChanged(const QModelIndex& current, const QModelIndex& previous); - + void currentChanged(const QModelIndex& current); + private: bool eventFilter(QObject *object, QEvent *e); @@ -177,14 +177,16 @@ public: QStringList bookmarkFolders() const; QModelIndex addNewFolder(const QModelIndex& index); void removeBookmarkItem(QTreeView *treeView, const QModelIndex& index); - void showBookmarkDialog(QWidget* parent, const QString &name, const QString &url); - void addNewBookmark(const QModelIndex& index, const QString &name, const QString &url); + void showBookmarkDialog(QWidget* parent, const QString &name, + const QString &url); + void addNewBookmark(const QModelIndex& index, const QString &name, + const QString &url); void setupBookmarkModels(); private slots: void itemChanged(QStandardItem *item); -private: +private: QString uniqueFolderName() const; void removeBookmarkFolderItems(QStandardItem *item); void readBookmarksRecursive(const QStandardItem *item, QDataStream &stream, @@ -193,7 +195,7 @@ private: private: QString oldText; QIcon folderIcon; - + BookmarkModel *treeModel; BookmarkModel *listModel; QStandardItem *renameItem; -- cgit v0.12 From 88130cb56b0b1b7332430d6045946635ca1c8c75 Mon Sep 17 00:00:00 2001 From: kh Date: Thu, 18 Jun 2009 13:15:41 +0200 Subject: Make it possible to drag bookmarks to the root item. Reviewed-by: kh --- tools/assistant/tools/assistant/bookmarkmanager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/assistant/tools/assistant/bookmarkmanager.cpp b/tools/assistant/tools/assistant/bookmarkmanager.cpp index 336c856..3bca573 100644 --- a/tools/assistant/tools/assistant/bookmarkmanager.cpp +++ b/tools/assistant/tools/assistant/bookmarkmanager.cpp @@ -606,7 +606,8 @@ Qt::DropActions BookmarkModel::supportedDropActions() const Qt::ItemFlags BookmarkModel::flags(const QModelIndex &index) const { Qt::ItemFlags defaultFlags = QStandardItemModel::flags(index); - if (index.data(Qt::UserRole + 10).toString() == QLatin1String("Folder")) + if ((!index.isValid()) // can only happen for the invisible root item + || index.data(Qt::UserRole + 10).toString() == QLatin1String("Folder")) return (Qt::ItemIsDropEnabled | defaultFlags) &~ Qt::ItemIsDragEnabled; return (Qt::ItemIsDragEnabled | defaultFlags) &~ Qt::ItemIsDropEnabled; -- cgit v0.12 From 747c7a9a060267dee9622c96bf0e2a54147dacfa Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 18 Jun 2009 13:38:10 +0200 Subject: QItemEditorFactory: made sure the ownership is taken on the QItemEditorCreator The creators were not deleted i nthe destructor of QItemEditorFactory and they could not be safely used for more than one type. Task-number: 228255 Reviewed-by: jasplin --- src/gui/itemviews/qitemeditorfactory.cpp | 16 +++++++-- .../qitemeditorfactory/tst_qitemeditorfactory.cpp | 38 ++++++++++++++++++---- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/gui/itemviews/qitemeditorfactory.cpp b/src/gui/itemviews/qitemeditorfactory.cpp index c576e40..480a472 100644 --- a/src/gui/itemviews/qitemeditorfactory.cpp +++ b/src/gui/itemviews/qitemeditorfactory.cpp @@ -158,6 +158,10 @@ QByteArray QItemEditorFactory::valuePropertyName(QVariant::Type type) const */ QItemEditorFactory::~QItemEditorFactory() { + //we make sure we delete all the QItemEditorCreatorBase + //this has to be done only once, hence the QSet + QSet set = creatorMap.values().toSet(); + qDeleteAll(set); } /*! @@ -170,8 +174,16 @@ QItemEditorFactory::~QItemEditorFactory() */ void QItemEditorFactory::registerEditor(QVariant::Type type, QItemEditorCreatorBase *creator) { - delete creatorMap.value(type, 0); - creatorMap[type] = creator; + QHash::iterator it = creatorMap.find(type); + if (it != creatorMap.end()) { + QItemEditorCreatorBase *oldCreator = it.value(); + Q_ASSERT(oldCreator); + creatorMap.erase(it); + if (!creatorMap.values().contains(oldCreator)) + delete oldCreator; // if it is no more in use we can delete it + } + + creatorMap[type] = creator; } class QDefaultItemEditorFactory : public QItemEditorFactory diff --git a/tests/auto/qitemeditorfactory/tst_qitemeditorfactory.cpp b/tests/auto/qitemeditorfactory/tst_qitemeditorfactory.cpp index 5540b38..d9a7d56 100644 --- a/tests/auto/qitemeditorfactory/tst_qitemeditorfactory.cpp +++ b/tests/auto/qitemeditorfactory/tst_qitemeditorfactory.cpp @@ -61,16 +61,40 @@ void tst_QItemEditorFactory::createEditor() void tst_QItemEditorFactory::createCustomEditor() { - QItemEditorFactory editorFactory; + //we make it inherit from QObject so that we can use QPointer + class MyEditor : public QObject, public QStandardItemEditorCreator + { + }; - QItemEditorCreatorBase *creator = new QStandardItemEditorCreator(); - editorFactory.registerEditor(QVariant::Rect, creator); + QPointer creator = new MyEditor; + QPointer creator2 = new MyEditor; - QWidget parent; + { + QItemEditorFactory editorFactory; + + editorFactory.registerEditor(QVariant::Rect, creator); + editorFactory.registerEditor(QVariant::RectF, creator); + + //creator should not be deleted as a result of calling the next line + editorFactory.registerEditor(QVariant::Rect, creator2); + QVERIFY(creator); + + //this should erase creator2 + editorFactory.registerEditor(QVariant::Rect, creator); + QVERIFY(creator2.isNull()); + + + QWidget parent; + + QWidget *w = editorFactory.createEditor(QVariant::Rect, &parent); + QCOMPARE(w->metaObject()->className(), "QDoubleSpinBox"); + QCOMPARE(w->metaObject()->userProperty().type(), QVariant::Double); + } - QWidget *w = editorFactory.createEditor(QVariant::Rect, &parent); - QCOMPARE(w->metaObject()->className(), "QDoubleSpinBox"); - QCOMPARE(w->metaObject()->userProperty().type(), QVariant::Double); + //editorFactory has been deleted, so should be creator + //because editorFActory has the ownership + QVERIFY(creator.isNull()); + QVERIFY(creator2.isNull()); delete creator; } -- cgit v0.12 From 8675a8915d09d0ca2091c606345a2d99f642949b Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Thu, 18 Jun 2009 15:33:14 +0200 Subject: QNAM HTTP code: Do not close TCP connection in all cases This makes sure the keep-alive connections stay open even if someone deletes a QNetworkReply which will then go all the way down to removeReply(QHttpNetworkReply). Should fix http://lists.trolltech.com/pipermail/qt-interest/2009-June/007777.html Reviewed-by: Peter Hartmann --- src/network/access/qhttpnetworkconnection.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index f698c71..4c08794 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -937,7 +937,8 @@ void QHttpNetworkConnectionPrivate::removeReply(QHttpNetworkReply *reply) for (int i = 0; i < channelCount; ++i) { if (channels[i].reply == reply) { channels[i].reply = 0; - closeChannel(i); + if (reply->d_func()->connectionCloseEnabled()) + closeChannel(i); QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); return; } -- cgit v0.12 From 31ed96ef2c34429d61a5d9d1c1b7fe4fc17c708b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Thu, 18 Jun 2009 16:32:06 +0200 Subject: Fixed a problem with QSvgRenderer::animationDuration(). May have returned random values for SVGs without animation tags. Task-number: 256073 Reviewed-by: Kim --- src/svg/qsvghandler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 9aa243b..d796938 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -3375,6 +3375,7 @@ void QSvgHandler::init() { m_doc = 0; m_style = 0; + m_animEnd = 0; m_defaultCoords = LT_PX; m_defaultPen = QPen(Qt::black, 1, Qt::NoPen, Qt::FlatCap, Qt::SvgMiterJoin); m_defaultPen.setMiterLimit(4); -- cgit v0.12 From 8ef1e1fc0e4b741d2f85cc8c0df42858b9306ff8 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Thu, 18 Jun 2009 17:40:21 +0200 Subject: QNetworkAccessManager: Clarify doc about deleting QNetworkReply Reviewed-by: Volker Hilsheimer --- src/network/access/qnetworkaccessmanager.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 8b44cd5..748d893 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -112,8 +112,6 @@ static void ensureInitialized() are supplied that take a request and optional data, and each return a QNetworkReply object. The returned object is used to obtain any data returned in response to the corresponding request. - the reply to is where most of the signals as well - as the downloaded data are posted. A simple download off the network could be accomplished with: \snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 0 @@ -122,7 +120,8 @@ static void ensureInitialized() takes is the QNetworkReply object containing the downloaded data as well as meta-data (headers, etc.). - \note The slot is responsible for deleting the object at that point. + \note After the request has finished, it is the responsibility of the user + to delete the QNetworkReply object at an appropriate time. A more involved example, assuming the manager is already existent, can be: -- cgit v0.12 From a60259b676743f078178185a6c587381bd957d3c Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 19 Jun 2009 14:51:52 +0200 Subject: Docs: remove reference to nonexistent file Reviewed-by: David Boddie --- tools/qdoc3/test/qt-build-docs.qdocconf | 1 - tools/qdoc3/test/qt.qdocconf | 1 - 2 files changed, 2 deletions(-) diff --git a/tools/qdoc3/test/qt-build-docs.qdocconf b/tools/qdoc3/test/qt-build-docs.qdocconf index a05786b..7a266ef 100644 --- a/tools/qdoc3/test/qt-build-docs.qdocconf +++ b/tools/qdoc3/test/qt-build-docs.qdocconf @@ -29,7 +29,6 @@ qhp.Qt.indexRoot = # See also extraimages.HTML qhp.Qt.extraFiles = classic.css \ images/qt-logo.png \ - images/trolltech-logo \ images/taskmenuextension-example.png \ images/coloreditorfactoryimage.png \ images/dynamiclayouts-example.png \ diff --git a/tools/qdoc3/test/qt.qdocconf b/tools/qdoc3/test/qt.qdocconf index 964869c..d366d1d 100644 --- a/tools/qdoc3/test/qt.qdocconf +++ b/tools/qdoc3/test/qt.qdocconf @@ -31,7 +31,6 @@ qhp.Qt.indexRoot = # See also extraimages.HTML qhp.Qt.extraFiles = classic.css \ images/qt-logo.png \ - images/trolltech-logo \ images/taskmenuextension-example.png \ images/coloreditorfactoryimage.png \ images/dynamiclayouts-example.png \ -- cgit v0.12 From 96b4fc79fd4a7b4d9cdae924ccec5643e7a49cf0 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 19 Jun 2009 17:26:02 +0200 Subject: Updated WebKit from /home/shausman/src/webkit/trunk to origin/qtwebkit-4.5 ( bd7262be70c02564d655e4f2aaf79cd8302a937f ) Changes in WebKit since the last update: ++ b/JavaScriptCore/ChangeLog 2009-02-02 Darin Adler Reviewed by Dave Hyatt. Bug 23676: Speed up uses of reserveCapacity on new vectors by adding a new reserveInitialCapacity https://bugs.webkit.org/show_bug.cgi?id=23676 * API/JSObjectRef.cpp: (JSObjectCopyPropertyNames): Use reserveInitialCapacity. * parser/Lexer.cpp: (JSC::Lexer::Lexer): Ditto. (JSC::Lexer::clear): Ditto. * wtf/Vector.h: Added reserveInitialCapacity, a more efficient version of reserveCapacity for use when the vector is brand new (still size 0 with no capacity other than the inline capacity). 2009-03-19 Geoffrey Garen Reviewed by Oliver Hunt. Fixed -- a little bit of hardening in the Collector. SunSpider reports no change. I also verified in the disassembly that we end up with a single compare to constant. * runtime/Collector.cpp: (JSC::Heap::heapAllocate): ++ b/LayoutTests/ChangeLog 2009-05-21 Geoffrey Garen Reviewed by Sam Weinig. Tests for | https://bugs.webkit.org/show_bug.cgi?id=25907 Incorrect URL returned to the DOM while the user drags a file * http/tests/local/drag-over-remote-content-expected.txt: Added. * http/tests/local/drag-over-remote-content.html: Added. * http/tests/security/drag-over-remote-content-iframe-expected.txt: Added. * http/tests/security/drag-over-remote-content-iframe.html: Added. 2009-04-14 Eric Carlson Reviewed by Alexey Proskuryakov. Fix