Keyword
. In order for us to determine the type of the keyword, we introduce a new entity: enum KeywordStyle { DefaultKeywordStyle, DoxygenKeywordStyle };
style
field and a new QString searchingText() const;
method QString searchingText() const;
. This method returns the string by which the keyword is searched, here is its implementation: QString Keyword::searchingText() const { if (style == DefaultKeywordStyle) return name + QLatin1Char(':'); else { Q_ASSERT(style == DoxygenKeywordStyle && "keywordStyle is not properly configured"); return QLatin1Char('@') + name.toLower(); } }
equals
method an appropriate comparison of the style
fields.name
field with a new method, searchingText
. This needs to be done in the LineParser
class in three methods:findKeywordEntryCandidates
- this method is used to generate a list of keyword positions that are in the comment line. Using searchingText
, the specified keyword is searched.keywordEntriesFromCandidates
- this method creates a list of {KEYWORD, TEXT} pairs. Here, searchingText
used to determine the length of a keyword.todoItemsFromKeywordEntries
- this method generates a list of records that we see in the To-Do window. Here, the searchingText
method is used to form a string that will be displayed to the user.Settings
class. In this class, we will loadsave
setDefault
methods setDefault
.load
method recovers information about keywords from the configuration. Since the configuration may be in the old format, by default we must set the keyword type to DefaultKeywordStyle
. Actually, the refinement of this method is rather trivial, only two lines were added: const QString styleKey = QLatin1String("style"); //... keyword.style = static_cast<KeywordStyle>(settings->value(styleKey, DefaultKeywordStyle).toInt());
save
method was updated in the same way: const QString styleKey = QLatin1String("style"); //... settings->setValue(styleKey, keyword.style);
void Settings::setDefault() { scanningScope = ScanningScopeCurrentFile; keywords.clear(); setDefaultKeywordStyle(); setDoxygenKeywordStyle(); } void Settings::setDefaultKeywordStyle() { Keyword keyword; keyword.name = QLatin1String("TODO"); keyword.iconResource = QLatin1String(Constants::ICON_WARNING); keyword.color = QColor(QLatin1String(Constants::COLOR_TODO_BG)); keyword.style = DefaultKeywordStyle; keywords.append(keyword); //... } void Settings::setDoxygenKeywordStyle() { Keyword keyword; keyword.name = QLatin1String("todo"); keyword.iconResource = QLatin1String(Constants::ICON_WARNING); keyword.color = QColor(QLatin1String(Constants::COLOR_TODO_BG)); keyword.style = DoxygenKeywordStyle; keywords.append(keyword); //... }
KeywordDialog
work with the new field style
and the new check box. In the class constructor, add the code to enable / disable the checkbox: if (keyword.style == DoxygenKeywordStyle) ui->doxygenStyleCheckBox->setCheckState(Qt::Checked); else ui->doxygenStyleCheckBox->setCheckState(Qt::Unchecked);
Keyword
generation method of ui
also add the corresponding code: result.style = (ui->doxygenStyleCheckBox->checkState() == Qt::Checked) ? DoxygenKeywordStyle : DefaultKeywordStyle;
OptionsDialog
class, since the objects of the Keyword
class are converted into objects of the QListWidgetItem
class. To this end, I highlighted such transformations into separate methods: void OptionsDialog::itemFromKeyword(const Keyword &keyword, QListWidgetItem *item) { item->setIcon(QIcon(keyword.iconResource)); item->setText(keyword.name); item->setData(Constants::IconResourceRole, keyword.iconResource); item->setData(Constants::KeywordStyleRole, keyword.style); item->setBackgroundColor(keyword.color); } Keyword OptionsDialog::keywordFromItem(const QListWidgetItem *item) { Keyword keyword; keyword.name = item->text(); keyword.iconResource = item->data(Constants::IconResourceRole).toString(); keyword.color = item->backgroundColor(); keyword.style = static_cast<KeywordStyle>(item->data(Constants::KeywordStyleRole).toInt()); return keyword; }
And in the code I replaced all the transformations with calls to these methods.All commands in the documentation start with a backslash (\) or an at-sign (@)
Source: https://habr.com/ru/post/138814/
All Articles