104 lines
2.5 KiB
C++
104 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include "textpresents.h"
|
|
|
|
namespace wstext_model {
|
|
typedef QList<uint32_t> 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<Element> {
|
|
public:
|
|
explicit Element(AssembleType t);
|
|
explicit Element(const Element & other);
|
|
|
|
AssembleType baseType() const;
|
|
qulonglong hashCode() const;
|
|
|
|
virtual std::shared_ptr<const Element> 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<std::shared_ptr<const WsChar>> convertFrom(const QString &text);
|
|
};
|
|
|
|
|
|
class WsPart : public Element {
|
|
public:
|
|
/**
|
|
* 获取指定元素的所有权.
|
|
*
|
|
* \param text
|
|
* \param offset
|
|
*/
|
|
std::shared_ptr<const WsPart> insertChars(const QList<std::shared_ptr<const WsChar>> &text, uint32_t offset = -1);
|
|
QList<std::shared_ptr<const WsChar>> getChars(uint32_t offset, uint32_t count) const;
|
|
std::shared_ptr<const WsPart> delChars(uint32_t offset, uint32_t count);
|
|
|
|
std::shared_ptr<const WsPart> mergeFrom(const QList<std::shared_ptr<const Element>> &mbrs);
|
|
};
|
|
|
|
class LIBWSTEXTEDIT_EXPORT WsBlock {
|
|
private:
|
|
QList<Element*> element_store;
|
|
|
|
public:
|
|
uint32_t blockIndex() const;
|
|
void addElements(const QList<Element*> &text, uint32_t offset = UINT32_MAX);
|
|
QList<Element*> 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<wstext_present::DocFormat> document_format;
|
|
QList<std::shared_ptr<WsBlock>> block_store;
|
|
|
|
public:
|
|
void bindFormat(std::shared_ptr<wstext_present::DocFormat> f);
|
|
std::shared_ptr<wstext_present::DocFormat> getFormat() const;
|
|
|
|
void addBlocks(const QList<std::shared_ptr<WsBlock>> &blks, uint32_t offset = UINT32_MAX);
|
|
uint32_t blockCount() const;
|
|
QList<std::shared_ptr<WsBlock>> 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);
|
|
|
|
};
|
|
}
|