7
7
#include " value_conversion_util.h"
8
8
#include " webdriver_session.h"
9
9
#include " webdriver_view_factory.h"
10
- #include " webdriver_util.h"
11
10
#include " common_util.h"
12
11
#include " q_key_converter.h"
13
12
#include " extension_qt/widget_element_handle.h"
26
25
27
26
namespace webdriver {
28
27
29
- #if 1
30
- #define REMOVE_INTERNAL_SUFIXES (qstr ) \
31
- qstr.remove(QRegExp(QLatin1String(" _QMLTYPE_\\ d+" ))); \
32
- qstr.remove(QRegExp(QLatin1String(" _QML_\\ d+" ))); \
33
- if (qstr.startsWith(QLatin1String(" QDeclarative" ))) qstr = qstr.mid(12 );
34
- #else
35
- #define REMOVE_INTERNAL_SUFIXES(qstr)
36
- #endif
37
-
38
28
const ViewType QQmlViewCmdExecutorCreator::QML_VIEW_TYPE = 0x13f6 ;
39
29
40
30
QQmlViewCmdExecutorCreator::QQmlViewCmdExecutorCreator ()
@@ -118,16 +108,12 @@ void QQmlViewCmdExecutor::GetSource(std::string* source, Error** error) {
118
108
return ;
119
109
}
120
110
121
- XMLElementMap elementsMap;
122
111
QByteArray byteArray;
123
112
QBuffer buff (&byteArray);
124
113
buff.open (QIODevice::ReadWrite);
125
114
126
- createUIXML (parentItem, &buff, elementsMap, error);
127
-
128
- if (*error)
129
- return ;
130
-
115
+ QQmlXmlSerializer serializer (&buff);
116
+ serializer.createXml (parentItem);
131
117
*source = byteArray.data ();
132
118
}
133
119
@@ -589,7 +575,7 @@ void QQmlViewCmdExecutor::GetElementTagName(const ElementId& element, std::strin
589
575
return ;
590
576
591
577
QString className (pItem->metaObject ()->className ());
592
- REMOVE_INTERNAL_SUFIXES (className);
578
+ QQmlViewUtil::removeInternalSuffixes (className);
593
579
594
580
*tag_name = className.toStdString ();
595
581
}
@@ -787,9 +773,16 @@ void QQmlViewCmdExecutor::ExecuteScript(const std::string& script, const base::L
787
773
*value = static_cast <Value*>(ret_value.release ());
788
774
}
789
775
776
+ void QQmlViewCmdExecutor::VisualizerSource (std::string* source, Error** error)
777
+ {
778
+ GetSource (source, error);
779
+ session_->logger ().Log (kInfoLogLevel , " VisualizerSource:" );
780
+ session_->logger ().Log (kInfoLogLevel , *source);
781
+ }
782
+
790
783
bool QQmlViewCmdExecutor::FilterElement (const QDeclarativeItem* item, const std::string& locator, const std::string& query) {
791
784
QString className (item->metaObject ()->className ());
792
- REMOVE_INTERNAL_SUFIXES (className);
785
+ QQmlViewUtil::removeInternalSuffixes (className);
793
786
794
787
if (locator == LocatorType::kClassName ) {
795
788
if (query == className.toStdString ())
@@ -814,12 +807,10 @@ bool QQmlViewCmdExecutor::FilterElement(const QDeclarativeItem* item, const std:
814
807
void QQmlViewCmdExecutor::FindElementsByXpath (QDeclarativeItem* parent, const std::string &query, std::vector<ElementId>* elements, Error **error) {
815
808
QByteArray byteArray;
816
809
QBuffer buff (&byteArray);
817
-
818
810
buff.open (QIODevice::ReadWrite);
819
- XMLElementMap elementsMap;
820
- createUIXML (parent, &buff, elementsMap, error);
821
- if (*error)
822
- return ;
811
+
812
+ QQmlXmlSerializer serializer (&buff);
813
+ serializer.createXml (parent);
823
814
824
815
buff.seek (0 );
825
816
@@ -846,6 +837,7 @@ void QQmlViewCmdExecutor::FindElementsByXpath(QDeclarativeItem* parent, const st
846
837
QString elemId (node.node ().attribute (" elementId" ).value ());
847
838
848
839
if (!elemId.isEmpty ()) {
840
+ const QQmlXmlSerializer::XMLElementMap& elementsMap = serializer.getElementsMap ();
849
841
if (elementsMap.contains (elemId)) {
850
842
ElementId elm;
851
843
session_->AddElement (view_id_, new QElementHandle (elementsMap[elemId]), &elm);
@@ -877,48 +869,4 @@ void QQmlViewCmdExecutor::FindElementsByXpath(QDeclarativeItem* parent, const st
877
869
buff.close ();
878
870
}
879
871
880
- void QQmlViewCmdExecutor::createUIXML (QDeclarativeItem *parent, QIODevice* buff, XMLElementMap& elementsMap, Error** error) {
881
-
882
- QXmlStreamWriter* writer = new QXmlStreamWriter ();
883
-
884
- writer->setDevice (buff);
885
- writer->setAutoFormatting (true );
886
- writer->writeStartDocument ();
887
-
888
- addItemToXML (parent, elementsMap, writer);
889
-
890
- writer->writeEndDocument ();
891
-
892
- delete writer;
893
- }
894
-
895
- void QQmlViewCmdExecutor::addItemToXML (QDeclarativeItem* parent, XMLElementMap& elementsMap, QXmlStreamWriter* writer) {
896
- if (NULL == parent) {
897
- session_->logger ().Log (kWarningLogLevel , " parent item is NULL." );
898
- return ;
899
- }
900
-
901
- QString className (parent->metaObject ()->className ());
902
- REMOVE_INTERNAL_SUFIXES (className);
903
-
904
- writer->writeStartElement (className);
905
-
906
- if (!parent->objectName ().isEmpty ())
907
- writer->writeAttribute (" id" , parent->objectName ());
908
-
909
- QString elementKey = GenerateRandomID ().c_str ();
910
- elementsMap.insert (elementKey, QPointer<QDeclarativeItem>(parent));
911
- writer->writeAttribute (" elementId" , elementKey);
912
-
913
- QList<QObject*> childs = parent->children ();
914
- foreach (QObject *child, childs) {
915
- QDeclarativeItem* childItem = qobject_cast<QDeclarativeItem*>(child);
916
- if (childItem)
917
- addItemToXML (childItem, elementsMap, writer);
918
- }
919
-
920
- writer->writeEndElement ();
921
- }
922
-
923
-
924
872
} // namespace webdriver
0 commit comments