Warning, file /office/calligra/libs/text/KoSectionModel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #ifndef KOSECTIONMODEL_H 0002 #define KOSECTIONMODEL_H 0003 0004 #include <QTextDocument> 0005 #include <QAbstractItemModel> 0006 #include <QVector> 0007 #include <QSet> 0008 0009 #include <KoSection.h> 0010 #include <KoSectionEnd.h> 0011 0012 /** 0013 * Used to handle all the sections in the document 0014 * 0015 * Now there actually two levels of section handling: 0016 * 1) Formatting Level: on this level we should be sure, that 0017 * pointers to KoSection and KoSectionEnd in the KoParagraphStyles 0018 * properties SectionEndings and SectionStartings are consistent. 0019 * Handling on this level is provided on the level of text editing 0020 * commands: DeleteCommand, NewSectionCommand 0021 * We can't move it to another place, because we should know the 0022 * semantics of operation to handle it right way. 0023 * 2) Model(Tree) Level: on this level we should update KoSectionModel 0024 * right way, so it in any moment represents the actual tree 0025 * of sections. Tree is built easily: 0026 * One section is son of another, if it is directly nested in it. 0027 * As text editing commands have access to change Formatting Level, 0028 * they are declared as friend classes of KoSectionModel to be able 0029 * affect Model structure without changing something on Formatting 0030 * Level. Also affected by RenameSectionCommand. 0031 * 0032 * Also we need to look at the consistency of some section properties: 0033 * 0034 * 1) Bounds. Those now are handled with QTextCursors that are placed 0035 * on start and end of the section. In default state start cursor 0036 * isn't moving if text inserted in its position, and end cursor 0037 * moves. But in the case of initial document loading, it is necessary 0038 * to make some end cursors stop moving, so we have: 0039 * KoTextLoader -> calling -> KoSection::setKeepEndBound() 0040 * KoTextLoader -> calling -> KoSectionModel::allowMovingEndBound() 0041 * ^-- this needed to restore default behaviour after load 0042 * 0043 * 2) Level. Level means the depth of the section in tree. Root 0044 * sections has 0 (zero) level. Now if you look at the possible 0045 * text editing command affecting sections you may notice that 0046 * level of section doesn't change in any case. Initial level 0047 * is set in KoSection constructor as parent's level plus one. 0048 * TODO: write about drag-n-drop here, when its implemented 0049 * 0050 * 3) Name. Each KoSection has a name that must be unique. We have 0051 * two groups of KoSections in each moment of time: the first group 0052 * consists of the sections that are present in document now, 0053 * the second group consists of the sections that were deleted, but 0054 * we still need them as they may be restored with "undo". 0055 * This groups are stored in m_registeredSections and m_sectionNames. 0056 * 0057 * Sections are created through this newSection() and newSectionEnd() 0058 * functions. 0059 * 0060 * This object is created for QTextDocument on the first query of it. 0061 */ 0062 class KOTEXT_EXPORT KoSectionModel : public QAbstractItemModel 0063 { 0064 Q_OBJECT 0065 public: 0066 static const int PointerRole = Qt::UserRole; 0067 0068 explicit KoSectionModel(QTextDocument *doc); 0069 ~KoSectionModel() override; 0070 0071 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0072 QModelIndex parent(const QModelIndex &child) const override; 0073 0074 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0075 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0076 0077 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0078 0079 /// Creates KoSection in position of @p cursor with some allowed name 0080 KoSection *createSection(const QTextCursor &cursor, KoSection *parent); 0081 0082 /// Creates KoSection in position of @p cursor with specified @p name 0083 KoSection *createSection(const QTextCursor &cursor, KoSection *parent, const QString &name); 0084 0085 /// Creates KoSectionEnd in pair for a @p section 0086 KoSectionEnd *createSectionEnd(KoSection *section); 0087 0088 /** Tries to set @p section name to @p name 0089 * @return @c false if there is a section with such name 0090 * and new name isn't accepted and @c true otherwise. 0091 */ 0092 bool setName(KoSection *section, const QString &name); 0093 0094 /** 0095 * Returns pointer to the deepest KoSection that covers @p pos 0096 * or NULL if there is no such section 0097 */ 0098 KoSection *sectionAtPosition(int pos) const; 0099 0100 /// Returns name for the new section. 0101 QString possibleNewName(); 0102 0103 /// Returns if this name is possible. 0104 bool isValidNewName(const QString &name) const; 0105 0106 /// Setting all sections end bound cursor to move with text inserting. 0107 void allowMovingEndBound(); 0108 0109 /// Finds index of @p child inside his parent. 0110 int findRowOfChild(KoSection *child) const; 0111 0112 private: 0113 Q_DISABLE_COPY(KoSectionModel) 0114 0115 friend class DeleteCommand; 0116 friend class NewSectionCommand; 0117 0118 /** 0119 * Inserts @p section to it's parent (should be 0120 * stored in @p section already) in position childIdx. 0121 * Affects only Model Level(@see KoSectionModel). 0122 */ 0123 void insertToModel(KoSection* section, int childIdx); 0124 /** 0125 * Deletes @p section from it's parent (should be 0126 * stored in @p section already). 0127 * Affects only Model Level 0128 * @see KoSectionModel 0129 */ 0130 void deleteFromModel(KoSection *section); 0131 0132 QTextDocument *m_doc; 0133 QSet<KoSection *> m_registeredSections; ///< stores pointer to sections that sometime was registered 0134 QHash<QString, KoSection *> m_sectionNames; ///< stores name -> pointer reference, for sections that are visible in document now 0135 QHash<KoSection *, QPersistentModelIndex> m_modelIndex; 0136 0137 QVector<KoSection *> m_rootSections; 0138 0139 }; 0140 0141 Q_DECLARE_METATYPE(KoSectionModel *) 0142 0143 #endif //KOSECTIONMODEL_H