#pragma once #include "textpresents.h" namespace wstext_model { typedef QList CharStream; class CharSetU16 { public: static CharStream combineToU(const QString &buffer); static QString splitToC(const CharStream &buffer); static bool contains(uint32_t code); static uint size(); }; /** * @brief 聚合体类型 */ enum class AssembleType { INLINE_ELEMENT, FRAGMENT, DOCUMENT, }; /** * @brief 内存实例接口 */ class Element : public std::enable_shared_from_this { public: explicit Element(AssembleType t); explicit Element(const Element & other); AssembleType baseType() const; qulonglong hashCode() const; virtual std::shared_ptr clone() const; virtual qulonglong pos() const; private: AssembleType type_store; }; class WsChar : public Element { private: uint32_t code_store; public: explicit WsChar(uint32_t code); virtual ~WsChar() = default; uint32_t code() const; static QList> convertFrom(const QString &text); }; class WsPart : public Element { public: /** * 获取指定元素的所有权. * * \param text * \param offset */ std::shared_ptr insertChars(const QList> &text, uint32_t offset = -1); QList> getChars(uint32_t offset, uint32_t count) const; std::shared_ptr delChars(uint32_t offset, uint32_t count); std::shared_ptr mergeFrom(const QList> &mbrs); }; class LIBWSTEXTEDIT_EXPORT WsBlock { private: QList element_store; public: uint32_t blockIndex() const; void addElements(const QList &text, uint32_t offset = UINT32_MAX); QList getElements(uint32_t offset, uint32_t count) const; void delElements(uint32_t offset, uint32_t count); QString toText() const; }; class LIBWSTEXTEDIT_EXPORT WsDocument : public QObject { Q_OBJECT private: std::shared_ptr document_format; QList> block_store; public: void bindFormat(std::shared_ptr f); std::shared_ptr getFormat() const; void addBlocks(const QList> &blks, uint32_t offset = UINT32_MAX); uint32_t blockCount() const; QList> getBlocks(uint32_t offset, uint32_t count = 1) const; void delBlocks(uint32_t offset, uint32_t count = 1); QString toPlainText() const; void setPlainText(const QString &text); }; }