Skip to content

Instantly share code, notes, and snippets.

@torarnv
Created April 30, 2009 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torarnv/104309 to your computer and use it in GitHub Desktop.
Save torarnv/104309 to your computer and use it in GitHub Desktop.
commit bc9fc46f05064f605a356af974caa06cb6ed7219
Author: Tor Arne Vestbø <tor.arne.vestbo@nokia.com>
Date: Wed Apr 29 12:18:21 2009 +0200
Add isEmpty() method to QWebElementCollection
diff --git a/WebKit/qt/Api/qwebelement.cpp b/WebKit/qt/Api/qwebelement.cpp
index e916076..361a2a4 100644
--- a/WebKit/qt/Api/qwebelement.cpp
+++ b/WebKit/qt/Api/qwebelement.cpp
@@ -1407,6 +1407,17 @@ void QWebElementCollection::append(const QWebElement &element)
}
/*!
+ Returns true if the collection does not contain any elements; false otherwise.
+*/
+bool QWebElementCollection::isEmpty() const
+{
+ if (!d)
+ return true;
+
+ return d->m_result->length() == 0;
+}
+
+/*!
Returns the number of elements in the collection.
*/
int QWebElementCollection::count() const
diff --git a/WebKit/qt/Api/qwebelement.h b/WebKit/qt/Api/qwebelement.h
index 844334e..7c5c45a 100644
--- a/WebKit/qt/Api/qwebelement.h
+++ b/WebKit/qt/Api/qwebelement.h
@@ -162,6 +162,7 @@ public:
void append(const QWebElementCollection &collection);
void append(const QWebElement &element);
+ bool isEmpty() const;
int count() const;
QWebElement at(int i) const;
diff --git a/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp b/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp
index c10faa5..2eea25d 100644
--- a/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp
+++ b/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp
@@ -144,6 +144,11 @@ void tst_QWebElement::simpleCollection()
QCOMPARE(list.count(), 2);
QCOMPARE(list.at(0).toPlainText(), QString("first para"));
QCOMPARE(list.at(1).toPlainText(), QString("second para"));
+
+ QWebElementCollection empty;
+ QVERIFY(empty.isEmpty());
+ empty.append(paras);
+ QVERIFY(!empty.isEmpty());
}
void tst_QWebElement::attributes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment