[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kparts
From: Dawit Alemayehu <adawit () kde ! org>
Date: 2010-10-27 17:55:42
Message-ID: 20101027175542.66A03AC897 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1190451 by adawit:
- Added an enum for specifying query method to SelectorInterface class.
- Added a second argument to querySelector and querySelectorAll function for passing \
the desired query method.
- Added a new member function, supportedQueryMethods, to the SelectorInterface class.
- Added two new member functions, isNull and hasAttribute, to the Element class.
- Added the appropriate macro label for exporting the SelectorInterface class.
M +19 -1 htmlextension.cpp
M +68 -11 htmlextension.h
--- trunk/KDE/kdelibs/kparts/htmlextension.cpp #1190450:1190451
@@ -18,9 +18,12 @@
*/
#include "htmlextension.h"
-#include <kglobal.h>
+
#include "part.h"
+#include <kglobal.h>
+
+
using namespace KParts;
KParts::HtmlExtension::HtmlExtension(KParts::ReadOnlyPart* parent)
@@ -37,6 +40,11 @@
return KGlobal::findDirectChild<KParts::HtmlExtension *>(obj);
}
+SelectorInterface::QueryMethods SelectorInterface::supportedQueryMethods() const
+{
+ return EntireContent;
+}
+
class SelectorInterface::ElementPrivate : public QSharedData
{
public:
@@ -58,6 +66,11 @@
{
}
+bool SelectorInterface::Element::isNull() const
+{
+ return d->tag.isNull();
+}
+
void SelectorInterface::Element::setTagName(const QString& tag)
{
d->tag = tag;
@@ -82,3 +95,8 @@
{
return d->attributes.value(name, defaultValue);
}
+
+bool SelectorInterface::Element::hasAttribute(const QString& name) const
+{
+ return d->attributes.contains(name);
+}
--- trunk/KDE/kdelibs/kparts/htmlextension.h #1190450:1190451
@@ -20,16 +20,19 @@
#ifndef KPARTS_HTMLEXTENSION_H
#define KPARTS_HTMLEXTENSION_H
-#include <QSharedDataPointer>
+#include <QtCore/QSharedDataPointer>
#include <QtCore/QObject>
-#include <kurl.h>
+
#include <kparts/kparts_export.h>
+class KUrl;
+
namespace KParts
{
class ReadOnlyPart;
class HtmlExtensionPrivate;
+class SelectorInterfacePrivate;
/**
* @short an extension for KParts to provide HTML-related features
@@ -69,25 +72,64 @@
* const QList<SelectorInterface::Element> elements = \
selectorInterface->querySelectorAll("head > \
link[rel=\"alternate\"]");
* </code>
*/
-class SelectorInterface
+class KPARTS_EXPORT SelectorInterface
{
public:
class ElementPrivate;
class Element;
+ /**
+ * Query methods.
+ */
+ enum QueryMethod {
+ EntireContent = 0x01, /*!< Query the entire content. */
+ SelectedContent = 0x02 /*!< Query only the user selected content, if \
any. */ + };
+ Q_DECLARE_FLAGS(QueryMethods, QueryMethod)
+
+ /**
+ * Destructor
+ */
virtual ~SelectorInterface() {}
+
/**
- * Returns the first (in document order) element in this fragment
- * matching the given CSS selector @p query.
+ * Returns the supported query methods.
+ *
+ * By default only quering the entire content is supported.
+ *
+ * @see QueryMethod
*/
- virtual Element querySelector(const QString& query) const = 0;
+ virtual QueryMethods supportedQueryMethods() const;
+
/**
+ * Returns the first (in document order) element in this fragment matching
+ * the given CSS selector @p query and querying method @p method.
+ *
+ * Note that since the returned item is static snapshot, i.e. not live, it
+ * will not be updated when the document changes.
+ *
+ * If the quering method specified by @p method is not supported or cannot be
+ * handled, then a null element is returned.
+ *
+ * @see supportedQueryMethods
+ * @see QueryMethod
+ */
+ virtual Element querySelector(const QString& query, QueryMethod method) const = \
0; +
+ /**
* Returns all (in document order) elements in this fragment matching the
- * given CSS selector @p query. Note that the returned list is
- * static and not live, and will not be updated when the document
- * changes
+ * given CSS selector @p query and querying method @p method.
+ *
+ * Note that since the returned list is static snapshot, i.e. not live, it
+ * will not be updated when the document changes.
+ *
+ * If the quering method specified by @p method is not supported or cannot be
+ * handled, then an empty list is returned.
+ *
+ * @see supportedQueryMethods
+ * @see QueryMethod
*/
- virtual QList<Element> querySelectorAll(const QString& query) const = 0;
+ virtual QList<Element> querySelectorAll(const QString& query, QueryMethod \
method) const = 0;
class KPARTS_EXPORT Element {
public:
@@ -95,23 +137,32 @@
* Constructor
*/
Element();
+
/**
* Copy constructor
*/
Element(const Element& other);
+
/**
* Destructor
*/
~Element();
/**
+ * Returns true if the element is null ; otherwise returns false.
+ */
+ bool isNull() const;
+
+ /**
* Sets the tag name of this element.
*/
void setTagName(const QString& tag);
+
/**
* Returns the tag name of this element.
*/
QString tagName() const;
+
/**
* Adds an attribute with the given name and value.
* If an attribute with the same name exists, its value is replaced by \
value. @@ -128,6 +179,11 @@
*/
QString attribute(const QString& name, const QString& defaultValue = \
QString()) const;
+ /**
+ * Returns true if the attribute with the given @p name exists.
+ */
+ bool hasAttribute(const QString& name) const;
+
// No namespace support yet, could be added with attributeNS, setAttributeNS
/**
@@ -151,7 +207,6 @@
private:
QSharedDataPointer<ElementPrivate> d;
};
-
};
} // namespace KParts
@@ -161,6 +216,8 @@
lhs.swap( rhs );
}
+Q_DECLARE_OPERATORS_FOR_FLAGS(KParts::SelectorInterface::QueryMethods)
+
Q_DECLARE_TYPEINFO(KParts::SelectorInterface::Element, Q_MOVABLE_TYPE);
Q_DECLARE_INTERFACE(KParts::SelectorInterface,
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic