2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-10-03 17:18:43 +08:00
|
|
|
#ifndef TODOPARSER_H
|
|
|
|
#define TODOPARSER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QAbstractListModel>
|
2022-10-22 23:29:12 +08:00
|
|
|
#include "HighlighterManager.h"
|
|
|
|
#include "qsynedit/Constants.h"
|
2021-10-03 17:18:43 +08:00
|
|
|
|
|
|
|
struct TodoItem {
|
|
|
|
QString filename;
|
|
|
|
int lineNo;
|
|
|
|
int ch;
|
|
|
|
QString line;
|
|
|
|
};
|
|
|
|
|
|
|
|
using PTodoItem = std::shared_ptr<TodoItem>;
|
|
|
|
|
|
|
|
class TodoModel : public QAbstractListModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TodoModel(QObject* parent=nullptr);
|
|
|
|
void addItem(const QString& filename, int lineNo,
|
|
|
|
int ch, const QString& line);
|
2022-10-22 23:29:12 +08:00
|
|
|
void removeTodosForFile(const QString& filename);
|
2021-10-03 17:18:43 +08:00
|
|
|
void clear();
|
2022-10-23 00:39:24 +08:00
|
|
|
void clear(bool forProject);
|
2021-10-03 17:18:43 +08:00
|
|
|
PTodoItem getItem(const QModelIndex& index);
|
2022-10-22 23:29:12 +08:00
|
|
|
private:
|
|
|
|
QList<PTodoItem> &getItems(bool forProject);
|
|
|
|
const QList<PTodoItem> &getConstItems(bool forProject) const;
|
2021-10-03 17:18:43 +08:00
|
|
|
private:
|
|
|
|
QList<PTodoItem> mItems;
|
2022-10-22 23:29:12 +08:00
|
|
|
QList<PTodoItem> mProjectItems;
|
|
|
|
bool mIsForProject;
|
2021-10-03 17:18:43 +08:00
|
|
|
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
|
|
|
int columnCount(const QModelIndex &parent) const override;
|
2022-10-22 23:29:12 +08:00
|
|
|
bool isForProject() const;
|
|
|
|
void setIsForProject(bool newIsForProject);
|
2021-10-03 17:18:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class TodoThread: public QThread
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TodoThread(const QString& filename, QObject* parent = nullptr);
|
2022-10-22 23:29:12 +08:00
|
|
|
explicit TodoThread(const QStringList& files, QObject* parent = nullptr);
|
2021-10-03 17:18:43 +08:00
|
|
|
signals:
|
2022-10-22 23:29:12 +08:00
|
|
|
void parseStarted();
|
|
|
|
void parsingFile(const QString& fileName);
|
2021-10-03 17:18:43 +08:00
|
|
|
void todoFound(const QString& filename, int lineNo, int ch, const QString& line);
|
|
|
|
void parseFinished();
|
2022-10-22 23:29:12 +08:00
|
|
|
private:
|
|
|
|
void parseFile();
|
|
|
|
void parseFiles();
|
|
|
|
void doParseFile(const QString& filename, QSynedit::PHighlighter highlighter);
|
2021-10-03 17:18:43 +08:00
|
|
|
private:
|
|
|
|
QString mFilename;
|
2022-10-22 23:29:12 +08:00
|
|
|
QStringList mFiles;
|
|
|
|
bool mParseFiles;
|
2021-10-03 17:18:43 +08:00
|
|
|
|
|
|
|
// QThread interface
|
|
|
|
protected:
|
|
|
|
void run() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
using PTodoThread = std::shared_ptr<TodoThread>;
|
|
|
|
|
|
|
|
class TodoParser : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TodoParser(QObject *parent = nullptr);
|
2022-10-22 23:29:12 +08:00
|
|
|
void parseFile(const QString& filename,bool isForProject);
|
|
|
|
void parseFiles(const QStringList& files);
|
2021-10-03 17:18:43 +08:00
|
|
|
bool parsing() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
TodoThread* mThread;
|
2022-01-04 16:50:54 +08:00
|
|
|
QMutex mMutex;
|
2021-10-03 17:18:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
using PTodoParser = std::shared_ptr<TodoParser>;
|
|
|
|
|
|
|
|
#endif // TODOPARSER_H
|