handwritingengine.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef HANDWRITINGENGINE_H
  2. #define HANDWRITINGENGINE_H
  3. #include <QObject>
  4. #include <QUrl>
  5. #include <QByteArray>
  6. #include <QtProtobufTypes>
  7. #include "matrix.h"
  8. #include <memory>
  9. namespace handwriting {
  10. class HandwritingClient;
  11. }
  12. class HandwritingEngine final : public QObject
  13. {
  14. Q_OBJECT
  15. Q_PROPERTY(int result READ result WRITE setResult NOTIFY resultChanged)
  16. Q_PROPERTY(handwriting::Matrix *matrix READ matrix CONSTANT)
  17. public:
  18. explicit HandwritingEngine(QObject *parent = nullptr);
  19. virtual ~HandwritingEngine() = default;
  20. Q_INVOKABLE void recognize();
  21. Q_INVOKABLE void setNeuralNetworkData(const QString &networkDataPath);
  22. Q_INVOKABLE void updateValue(int index, double value);
  23. int result() const
  24. {
  25. return m_result;
  26. }
  27. handwriting::Matrix *matrix()
  28. {
  29. return &m_matrix;
  30. }
  31. public slots:
  32. void setResult(int result)
  33. {
  34. if (m_result == result)
  35. return;
  36. m_result = result;
  37. emit resultChanged(m_result);
  38. }
  39. signals:
  40. void resultChanged(int result);
  41. private:
  42. std::shared_ptr<handwriting::HandwritingClient> m_client;
  43. int m_result;
  44. QtProtobuf::DoubleList m_data;
  45. handwriting::Matrix m_matrix;
  46. };
  47. #endif // HANDWRITINGENGINE_H