- enhancement: auto sort TODO items

This commit is contained in:
Roy Qu 2022-10-26 11:10:56 +08:00
parent da2a7549f1
commit fde8a868fa
4 changed files with 23 additions and 8 deletions

View File

@ -32,6 +32,7 @@ Red Panda C++ Version 2.0
- change: Don't generate localized filename when new header/add file in the project view - change: Don't generate localized filename when new header/add file in the project view
- fix: Restore project's original compiler set if user choose 'No' in the confirm project compiler set change dialog. - fix: Restore project's original compiler set if user choose 'No' in the confirm project compiler set change dialog.
- fix: Encoding info in the status bar not correctly updated when save a new file - fix: Encoding info in the status bar not correctly updated when save a new file
- enhancement: auto sort TODO items
Red Panda C++ Version 1.5 Red Panda C++ Version 1.5

View File

@ -4565,7 +4565,6 @@ void MainWindow::onTodoFound(const QString& filename, int lineNo, int ch, const
void MainWindow::onTodoParseFinished() void MainWindow::onTodoParseFinished()
{ {
} }
void MainWindow::prepareProjectForCompile() void MainWindow::prepareProjectForCompile()
@ -6284,6 +6283,7 @@ void MainWindow::on_actionNew_Project_triggered()
} }
mProject->saveAll(); mProject->saveAll();
updateProjectView(); updateProjectView();
mTodoParser->parseFiles(mProject->unitFiles());
scanActiveProject(true); scanActiveProject(true);
Editor* editor = mEditorList->getEditor(); Editor* editor = mEditorList->getEditor();
updateClassBrowserForEditor(editor); updateClassBrowserForEditor(editor);

View File

@ -143,6 +143,7 @@ void TodoThread::doParseFile(const QString &filename, QSynedit::PHighlighter hig
pos+highlighter->getTokenPos(), pos+highlighter->getTokenPos(),
lines[i].trimmed() lines[i].trimmed()
); );
break;
} }
} }
highlighter->next(); highlighter->next();
@ -168,13 +169,29 @@ TodoModel::TodoModel(QObject *parent) : QAbstractListModel(parent)
void TodoModel::addItem(const QString &filename, int lineNo, int ch, const QString &line) void TodoModel::addItem(const QString &filename, int lineNo, int ch, const QString &line)
{ {
QList<PTodoItem> &items=getItems(mIsForProject); QList<PTodoItem> &items=getItems(mIsForProject);
beginInsertRows(QModelIndex(),items.count(),items.count()); int pos=-1;
for (int i=0;i<items.count();i++) {
int comp=QString::compare(filename,items[i]->filename);
if (comp<0) {
pos=i;
break;
} else if (comp==0) {
if (lineNo<items[i]->lineNo) {
pos=i;
break;
}
}
}
if (pos<0) {
pos=items.count();
}
beginInsertRows(QModelIndex(),pos,pos);
PTodoItem item = std::make_shared<TodoItem>(); PTodoItem item = std::make_shared<TodoItem>();
item->filename = filename; item->filename = filename;
item->lineNo = lineNo; item->lineNo = lineNo;
item->ch = ch; item->ch = ch;
item->line = line; item->line = line;
items.append(item); items.insert(pos,item);
endInsertRows(); endInsertRows();
} }
@ -259,8 +276,6 @@ QVariant TodoModel::data(const QModelIndex &index, int role) const
case 1: case 1:
return item->lineNo; return item->lineNo;
case 2: case 2:
return item->ch;
case 3:
return item->line; return item->line;
} }
} }
@ -276,8 +291,6 @@ QVariant TodoModel::headerData(int section, Qt::Orientation orientation, int rol
case 1: case 1:
return tr("Line"); return tr("Line");
case 2: case 2:
return tr("Column");
case 3:
return tr("Content"); return tr("Content");
} }
} }
@ -286,5 +299,5 @@ QVariant TodoModel::headerData(int section, Qt::Orientation orientation, int rol
int TodoModel::columnCount(const QModelIndex &) const int TodoModel::columnCount(const QModelIndex &) const
{ {
return 4; return 3;
} }

View File

@ -59,6 +59,7 @@ public:
int columnCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override;
bool isForProject() const; bool isForProject() const;
void setIsForProject(bool newIsForProject); void setIsForProject(bool newIsForProject);
}; };
class TodoThread: public QThread class TodoThread: public QThread