class browser icons

This commit is contained in:
royqh1979@gmail.com 2021-09-26 12:19:46 +08:00
parent 3a6097c40f
commit 36fa23634d
26 changed files with 155 additions and 42 deletions

View File

@ -1,4 +1,5 @@
Version 0.2 Version 0.2
- enhancement: class browser syntax colors and icons
- enhancement: function tips - enhancement: function tips
- enhancement: project support - enhancement: project support
- enhancement: paint color editor use system palette's disabled group color - enhancement: paint color editor use system palette's disabled group color

View File

@ -460,7 +460,7 @@ void Editor::focusOutEvent(QFocusEvent *event)
this, this,
&SynEdit::invalidate); &SynEdit::invalidate);
} }
pMainWindow->updateClassBrowserForEditor(nullptr); //pMainWindow->updateClassBrowserForEditor(nullptr);
pMainWindow->updateEditorActions(); pMainWindow->updateEditorActions();
pMainWindow->updateStatusbarForLineCol(); pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo(); pMainWindow->updateForStatusbarModeInfo();

View File

@ -467,5 +467,24 @@
<file>images/associations/obj.ico</file> <file>images/associations/obj.ico</file>
<file>images/associations/rc.ico</file> <file>images/associations/rc.ico</file>
<file>images/associations/template.ico</file> <file>images/associations/template.ico</file>
<file>images/classparser/class.ico</file>
<file>images/classparser/define.ico</file>
<file>images/classparser/enum.ico</file>
<file>images/classparser/global.ico</file>
<file>images/classparser/global_method.ico</file>
<file>images/classparser/method_inherited.ico</file>
<file>images/classparser/method_inherited_protected.ico</file>
<file>images/classparser/method_private.ico</file>
<file>images/classparser/method_protected.ico</file>
<file>images/classparser/method_public.ico</file>
<file>images/classparser/namespace.ico</file>
<file>images/classparser/static_method.ico</file>
<file>images/classparser/static_var.ico</file>
<file>images/classparser/type.ico</file>
<file>images/classparser/var_inherited.ico</file>
<file>images/classparser/var_inherited_protected.ico</file>
<file>images/classparser/var_private.ico</file>
<file>images/classparser/var_protected.ico</file>
<file>images/classparser/var_public.ico</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1628,6 +1628,19 @@ void MainWindow::buildContextMenus()
mProject->removeFolder(folderNode); mProject->removeFolder(folderNode);
mProject->saveOptions(); mProject->saveOptions();
}); });
//context menu signal for class browser
ui->classBrowser->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->classBrowser,&QWidget::customContextMenuRequested,
this, &MainWindow::onClassBrowserContextMenu);
mClassBrowser_Sort_By_Type = createActionFor(
tr("Sort By Type"),
ui->classBrowser);
mClassBrowser_Sort_By_Type->setIcon(QIcon(":/icons/images/newlook24/077-sort-type.png"));
QAction * mClassBrowser_Sort_By_Name;
QAction * mClassBrowser_Show_Inheritance;
QAction * mClassBrowser_goto_declaration;
QAction * mClassBrowser_goto_definition;
} }
void MainWindow::maximizeEditor() void MainWindow::maximizeEditor()
@ -3433,3 +3446,9 @@ const std::shared_ptr<QHash<StatementKind, QColor> > &MainWindow::statementColor
return mStatementColors; return mStatementColors;
} }
void MainWindow::on_classBrowser_doubleClicked(const QModelIndex &index)
{
}

View File

@ -339,6 +339,8 @@ private slots:
void on_actionProject_Open_In_Terminal_triggered(); void on_actionProject_Open_In_Terminal_triggered();
void on_classBrowser_doubleClicked(const QModelIndex &index);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;
@ -409,6 +411,12 @@ private:
QAction * mProject_Rename_Folder; QAction * mProject_Rename_Folder;
QAction * mProject_Remove_Folder; QAction * mProject_Remove_Folder;
//actions for class browser
QAction * mClassBrowser_Sort_By_Type;
QAction * mClassBrowser_Sort_By_Name;
QAction * mClassBrowser_Show_Inheritance;
QAction * mClassBrowser_goto_declaration;
QAction * mClassBrowser_goto_definition;
// QWidget interface // QWidget interface
protected: protected:

View File

@ -10,7 +10,7 @@ ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent)
mRoot = new ClassBrowserNode(); mRoot = new ClassBrowserNode();
mRoot->parent = nullptr; mRoot->parent = nullptr;
mRoot->statement = PStatement(); mRoot->statement = PStatement();
mRoot->childrenFetched = true; // mRoot->childrenFetched = true;
mUpdating = false; mUpdating = false;
mUpdateCount = 0; mUpdateCount = 0;
mShowInheritedMembers = false; mShowInheritedMembers = false;
@ -54,14 +54,14 @@ bool ClassBrowserModel::hasChildren(const QModelIndex &parent) const
{ {
ClassBrowserNode *parentNode; ClassBrowserNode *parentNode;
if (!parent.isValid()) { // top level if (!parent.isValid()) { // top level
return mRoot->children.count(); return mRoot->children.count()>0;
} else { } else {
parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer()); parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer());
if (parentNode->childrenFetched) // if (parentNode->childrenFetched)
return parentNode->children.count(); return parentNode->children.count()>0;
if (parentNode->statement) // if (parentNode->statement)
return !parentNode->statement->children.isEmpty(); // return !parentNode->statement->children.isEmpty();
return false; // return false;
} }
} }
@ -81,37 +81,37 @@ int ClassBrowserModel::columnCount(const QModelIndex&) const
return 1; return 1;
} }
void ClassBrowserModel::fetchMore(const QModelIndex &parent) //void ClassBrowserModel::fetchMore(const QModelIndex &parent)
{ //{
if (!parent.isValid()) { // top level // if (!parent.isValid()) { // top level
return; // return;
} // }
ClassBrowserNode *parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer()); // ClassBrowserNode *parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer());
if (!parentNode->childrenFetched) { // if (!parentNode->childrenFetched) {
parentNode->childrenFetched = true; // parentNode->childrenFetched = true;
if (parentNode->statement && !parentNode->statement->children.isEmpty()) { // if (parentNode->statement && !parentNode->statement->children.isEmpty()) {
filterChildren(parentNode, parentNode->statement->children); // filterChildren(parentNode, parentNode->statement->children);
beginInsertRows(parent,0,parentNode->children.count()); // beginInsertRows(parent,0,parentNode->children.count());
endInsertRows(); // endInsertRows();
} // }
} // }
} //}
bool ClassBrowserModel::canFetchMore(const QModelIndex &parent) const //bool ClassBrowserModel::canFetchMore(const QModelIndex &parent) const
{ //{
if (!parent.isValid()) { // top level // if (!parent.isValid()) { // top level
return false; // return false;
} // }
ClassBrowserNode *parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer()); // ClassBrowserNode *parentNode = static_cast<ClassBrowserNode *>(parent.internalPointer());
if (!parentNode->childrenFetched) { // if (!parentNode->childrenFetched) {
if (parentNode->statement && !parentNode->statement->children.isEmpty()) // if (parentNode->statement && !parentNode->statement->children.isEmpty())
return true; // return true;
else // else
parentNode->childrenFetched = true; // parentNode->childrenFetched = true;
} // }
return false; // return false;
} //}
QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
{ {
@ -123,7 +123,7 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
if (node->statement) { if (node->statement) {
return node->statement->command; return node->statement->command + node->statement->args;
} }
} else if (role == Qt::ForegroundRole) { } else if (role == Qt::ForegroundRole) {
if (node->statement) { if (node->statement) {
@ -136,6 +136,70 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
} }
return mColors->value(kind,pMainWindow->palette().color(QPalette::Text)); return mColors->value(kind,pMainWindow->palette().color(QPalette::Text));
} }
} else if (role == Qt::DecorationRole) {
if (node->statement) {
PStatement statement = (node->statement);
StatementKind kind;
if (mParser) {
kind = mParser->getKindOfStatement(statement);
} else {
kind = statement->kind;
}
switch (kind) {
case StatementKind::skTypedef:
return QIcon(":/icons/images/classparser/type.ico");
case StatementKind::skClass:
case StatementKind::skEnumClassType:
case StatementKind::skEnumType:
return QIcon(":/icons/images/classparser/class.ico");
case StatementKind::skNamespace:
case StatementKind::skNamespaceAlias:
return QIcon(":/icons/images/classparser/namespace.ico");
case StatementKind::skPreprocessor:
return QIcon(":/icons/images/classparser/define.ico");
case StatementKind::skEnum:
return QIcon(":/icons/images/classparser/enum.ico");
case StatementKind::skFunction:
case StatementKind::skConstructor:
case StatementKind::skDestructor:
if (statement->scope == StatementScope::ssGlobal)
return QIcon(":/icons/images/classparser/global_method.ico");
if (statement->isInherited) {
if (statement->classScope == StatementClassScope::scsProtected) {
return QIcon(":/icons/images/classparser/method_inherited_protected.ico");
} else if (statement->classScope == StatementClassScope::scsPublic) {
return QIcon(":/icons/images/classparser/method_inherited.ico");
}
} else {
if (statement->classScope == StatementClassScope::scsProtected) {
return QIcon(":/icons/images/classparser/method_protected.ico");
} else if (statement->classScope == StatementClassScope::scsPublic) {
return QIcon(":/icons/images/classparser/method_public.ico");
} else {
return QIcon(":/icons/images/classparser/method_private.ico");
}
}
case StatementKind::skVariable:
if (statement->scope == StatementScope::ssGlobal)
return QIcon(":/icons/images/classparser/global.ico");
if (statement->isInherited) {
if (statement->classScope == StatementClassScope::scsProtected) {
return QIcon(":/icons/images/classparser/var_inherited_protected.ico");
} else if (statement->classScope == StatementClassScope::scsPublic) {
return QIcon(":/icons/images/classparser/var_inherited.ico");
}
} else {
if (statement->classScope == StatementClassScope::scsProtected) {
return QIcon(":/icons/images/classparser/var_protected.ico");
} else if (statement->classScope == StatementClassScope::scsPublic) {
return QIcon(":/icons/images/classparser/var_public.ico");
} else {
return QIcon(":/icons/images/classparser/var_private.ico");
}
}
}
}
} }
return QVariant(); return QVariant();
} }
@ -215,9 +279,10 @@ void ClassBrowserModel::addChild(ClassBrowserNode *node, PStatement statement)
PClassBrowserNode newNode = std::make_shared<ClassBrowserNode>(); PClassBrowserNode newNode = std::make_shared<ClassBrowserNode>();
newNode->parent = node; newNode->parent = node;
newNode->statement = statement; newNode->statement = statement;
newNode->childrenFetched = false; // newNode->childrenFetched = false;
node->children.append(newNode.get()); node->children.append(newNode.get());
mNodes.append(newNode); mNodes.append(newNode);
filterChildren(newNode.get(), statement->children);
} }
void ClassBrowserModel::addMembers(const QSet<QString> &includedFiles) void ClassBrowserModel::addMembers(const QSet<QString> &includedFiles)

View File

@ -8,7 +8,7 @@ struct ClassBrowserNode {
ClassBrowserNode* parent; ClassBrowserNode* parent;
PStatement statement; PStatement statement;
QVector<ClassBrowserNode *> children; QVector<ClassBrowserNode *> children;
bool childrenFetched; // bool childrenFetched;
}; };
using PClassBrowserNode = std::shared_ptr<ClassBrowserNode>; using PClassBrowserNode = std::shared_ptr<ClassBrowserNode>;
@ -26,8 +26,8 @@ public:
bool hasChildren(const QModelIndex &parent) const override; bool hasChildren(const QModelIndex &parent) const override;
int rowCount(const QModelIndex &parent) const override; int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override;
void fetchMore(const QModelIndex &parent) override; // void fetchMore(const QModelIndex &parent) override;
bool canFetchMore(const QModelIndex &parent) const override; // bool canFetchMore(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
const PCppParser &parser() const; const PCppParser &parser() const;
void setParser(const PCppParser &newCppParser); void setParser(const PCppParser &newCppParser);
@ -59,6 +59,7 @@ private:
QString mCurrentFile; QString mCurrentFile;
bool mShowInheritedMembers; bool mShowInheritedMembers;
std::shared_ptr<QHash<StatementKind, QColor>> mColors; std::shared_ptr<QHash<StatementKind, QColor>> mColors;
}; };
#endif // CLASSBROWSER_H #endif // CLASSBROWSER_H