ScoreboardHandler.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <QtXml/QXmlDefaultHandler>
  2. #include <QDebug>
  3. #ifndef SCOREBOARDHANDLER_H
  4. #define SCOREBOARDHANDLER_H
  5. class Handler : public QXmlDefaultHandler {
  6. public:
  7. Handler() {
  8. data = new QList< QHash<QString,QString> >;
  9. }
  10. QList< QHash<QString,QString> > getData() {
  11. return *data;
  12. }
  13. bool startDocument() {
  14. inScoreboard = false;
  15. return true;
  16. }
  17. bool endElement( const QString&, const QString&, const QString &name ) {
  18. if( name == "scoreboard" ) inScoreboard = false;
  19. return true;
  20. }
  21. bool startElement( const QString&, const QString&, const QString &name, const QXmlAttributes &attrs ) {
  22. QHash<QString,QString> thisData;
  23. if( inScoreboard && name=="player" ) {
  24. for( int i=0; i<attrs.count(); i++ ) {
  25. thisData[attrs.localName(i)] = attrs.value(i);
  26. }
  27. data->append(thisData);
  28. } else if( name == "scoreboard" ) {
  29. inScoreboard = true;
  30. }
  31. return true;
  32. }
  33. private:
  34. bool inScoreboard;
  35. QList< QHash<QString,QString> > *data;
  36. };
  37. #endif // SCOREBOARDHANDLER_H