summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-01-22 11:29:08 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-01-22 11:30:10 (GMT)
commit81db7d1ca46b7b0d922a1107d93f49b2cebb6bfb (patch)
treef2f703ecf1eec16e5576bc18124eb5e604ee7eb3 /Swift/QtUI/MUCSearch
parent72f6e3fc436b5e4f7988ffa19359bb6cff644590 (diff)
downloadswift-81db7d1ca46b7b0d922a1107d93f49b2cebb6bfb.zip
swift-81db7d1ca46b7b0d922a1107d93f49b2cebb6bfb.tar.bz2
Work around Qt crash bug when destroying the selection list in MUC search.
Diffstat (limited to 'Swift/QtUI/MUCSearch')
-rw-r--r--Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp38
-rw-r--r--Swift/QtUI/MUCSearch/QtMUCSearchWindow.h2
2 files changed, 28 insertions, 12 deletions
diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
index 3c16efb..2130993 100644
--- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
+++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
@@ -150,16 +150,12 @@ void QtMUCSearchWindow::setSearchInProgress(bool searching) {
}
void QtMUCSearchWindow::accept() {
- QModelIndexList selection = ui_.results_->selectionModel()->selectedIndexes();
- if (selection.isEmpty()) {
- onFinished(boost::optional<JID>());
+ MUCSearchRoomItem* room = getSelectedRoom();
+ if (room) {
+ onFinished(JID(Q2PSTRING(room->getNode()), Q2PSTRING(room->getParent()->getHost())));
}
else {
- QModelIndex selectedItem = selection[0];
- MUCSearchRoomItem* item = dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(selectedItem.internalPointer()));
- if (item) {
- onFinished(JID(Q2PSTRING(item->getNode()), Q2PSTRING(item->getParent()->getHost())));
- }
+ onFinished(boost::optional<JID>());
}
QDialog::accept();
}
@@ -170,13 +166,31 @@ void QtMUCSearchWindow::reject() {
}
void QtMUCSearchWindow::handleSelectionChanged(const QItemSelection& selection, const QItemSelection&) {
- if (selection.indexes().size() > 0) {
- ui_.okButton->setEnabled(dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(selection.indexes()[0].internalPointer())));
+ ui_.okButton->setEnabled(getSelectedRoom());
+}
+
+MUCSearchRoomItem* QtMUCSearchWindow::getSelectedRoom() const {
+ QItemSelection ranges = ui_.results_->selectionModel()->selection();
+ // Not using selectedIndexes(), because this seems to cause a crash in Qt (4.7.0) in the
+ // QModelIndexList destructor.
+ // This is a workaround posted in http://www.qtcentre.org/threads/16933 (although this case
+ // was resolved by linking against the debug libs, ours isn't, and we're not alone)
+ QModelIndexList lstIndex;
+ for (int i = 0; i < ranges.count(); ++i) {
+ QModelIndex parent = ranges.at(i).parent();
+ int right = ranges.at(i).model()->columnCount(parent) - 1;
+ if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) {
+ for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) {
+ lstIndex.append(ranges.at(i).model()->index(r, 0, parent));
+ }
+ }
+ }
+ if (lstIndex.empty()) {
+ return NULL;
}
else {
- ui_.okButton->setEnabled(false);
+ return dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(lstIndex.first().internalPointer()));
}
}
-
}
diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h
index c7661c2..05ab9a5 100644
--- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h
+++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h
@@ -13,6 +13,7 @@
namespace Swift {
class MUCSearchModel;
class MUCSearchDelegate;
+ class MUCSearchRoomItem;
class QtMUCSearchWindow : public QDialog, public MUCSearchWindow {
Q_OBJECT
@@ -38,6 +39,7 @@ namespace Swift {
void handleActivated(const QModelIndex& index);
void updateThrobberPosition();
void handleSelectionChanged (const QItemSelection&, const QItemSelection&);
+ MUCSearchRoomItem* getSelectedRoom() const;
private:
Ui::QtMUCSearchWindow ui_;