RedPanda-CPP/RedPandaIDE/project.h

260 lines
7.1 KiB
C
Raw Normal View History

2021-09-05 23:45:05 +08:00
#ifndef PROJECT_H
#define PROJECT_H
2021-09-11 09:21:44 +08:00
#include <QAbstractItemModel>
2021-09-05 23:45:05 +08:00
#include <QObject>
2021-09-06 08:45:53 +08:00
#include <QSettings>
2021-09-05 23:45:05 +08:00
#include <memory>
#include "SimpleIni.h"
2021-09-05 23:45:05 +08:00
using SimpleIni = CSimpleIniA;
2021-09-05 23:45:05 +08:00
enum class ProjectType {
2021-09-09 23:20:00 +08:00
GUI=0,
Console=1,
StaticLib=2,
DynamicLib=3
2021-09-05 23:45:05 +08:00
};
class Project;
class Editor;
2021-09-06 08:45:53 +08:00
class CppParser;
2021-09-07 00:32:16 +08:00
struct FolderNode;
using PFolderNode = std::shared_ptr<FolderNode>;
struct FolderNode {
QString text;
2021-09-10 10:27:01 +08:00
std::weak_ptr<FolderNode> parent;
2021-09-07 00:32:16 +08:00
int unitIndex;
QList<PFolderNode> children;
2021-09-10 21:37:52 +08:00
int level;
2021-09-07 00:32:16 +08:00
};
2021-09-05 23:45:05 +08:00
class ProjectUnit {
public:
2021-09-07 00:32:16 +08:00
explicit ProjectUnit(Project* parent);
Project* parent() const;
void setParent(Project* newParent);
2021-09-05 23:45:05 +08:00
Editor *editor() const;
void setEditor(Editor *newEditor);
const QString &fileName() const;
void setFileName(const QString &newFileName);
bool isNew() const;
void setNew(bool newNew);
const QString &folder() const;
void setFolder(const QString &newFolder);
bool compile() const;
void setCompile(bool newCompile);
bool compileCpp() const;
void setCompileCpp(bool newCompileCpp);
bool overrideBuildCmd() const;
void setOverrideBuildCmd(bool newOverrideBuildCmd);
const QString &buildCmd() const;
void setBuildCmd(const QString &newBuildCmd);
bool link() const;
void setLink(bool newLink);
int priority() const;
void setPriority(int newPriority);
const QByteArray &encoding() const;
void setEncoding(const QByteArray &newEncoding);
2021-09-06 12:58:29 +08:00
bool modified() const;
2021-09-05 23:45:05 +08:00
void setModified(bool value);
bool save();
2021-09-07 10:28:40 +08:00
PFolderNode &node();
void setNode(const PFolderNode &newNode);
2021-09-05 23:45:05 +08:00
private:
2021-09-07 00:32:16 +08:00
Project* mParent;
2021-09-05 23:45:05 +08:00
Editor* mEditor;
QString mFileName;
bool mNew;
QString mFolder;
bool mCompile;
bool mCompileCpp;
bool mOverrideBuildCmd;
QString mBuildCmd;
bool mLink;
int mPriority;
QByteArray mEncoding;
2021-09-07 00:32:16 +08:00
PFolderNode mNode;
2021-09-05 23:45:05 +08:00
};
2021-09-06 08:45:53 +08:00
using PProjectUnit = std::shared_ptr<ProjectUnit>;
2021-09-06 01:47:07 +08:00
struct ProjectVersionInfo{
explicit ProjectVersionInfo();
2021-09-06 01:47:07 +08:00
int major;
int minor;
int release;
int build;
int languageID;
int charsetID;
QString companyName;
QString fileVersion;
QString fileDescription;
QString internalName;
QString legalCopyright;
QString legalTrademarks;
QString originalFilename;
QString productName;
QString productVersion;
bool autoIncBuildNr;
bool syncProduct;
};
struct ProjectOptions{
ProjectType type;
int version;
2021-09-10 10:27:01 +08:00
QStringList objFiles;
2021-09-06 01:47:07 +08:00
QString compilerCmd;
QString cppCompilerCmd;
QString linkerCmd;
QStringList includes;
QStringList libs;
QString privateResource;
QStringList resourceIncludes;
QStringList makeIncludes;
bool useGPP;
QString icon;
QString exeOutput;
QString objectOutput;
QString logOutput;
bool logOutputEnabled;
bool useCustomMakefile;
QString customMakefile;
bool usePrecompiledHeader;
2021-09-10 10:27:01 +08:00
QString precompiledHeader;
2021-09-06 01:47:07 +08:00
bool overrideOutput;
QString overridenOutput;
QString hostApplication;
bool includeVersionInfo;
bool supportXPThemes;
int compilerSet;
2021-09-13 10:48:44 +08:00
QByteArray compilerOptions;
2021-09-07 14:04:48 +08:00
ProjectVersionInfo versionInfo;
2021-09-06 01:47:07 +08:00
QString cmdLineArgs;
2021-09-07 14:04:48 +08:00
bool staticLink;
bool addCharset;
2021-09-10 15:03:47 +08:00
QString encoding;
2021-09-06 01:47:07 +08:00
};
2021-09-11 09:21:44 +08:00
class ProjectModel : public QAbstractItemModel {
Q_OBJECT
public:
explicit ProjectModel(Project* project, QObject* parent=nullptr);
void beginUpdate();
void endUpdate();
private:
Project* mProject;
int mUpdateCount;
// QAbstractItemModel interface
public:
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
};
2021-09-05 23:45:05 +08:00
class Project : public QObject
{
Q_OBJECT
public:
2021-09-07 16:49:35 +08:00
explicit Project(const QString& filename, const QString& name,QObject *parent = nullptr);
2021-09-11 18:42:49 +08:00
~Project();
2021-09-09 11:47:04 +08:00
QString directory() const;
QString executable() const;
2021-09-06 08:45:53 +08:00
QString makeFileName();
2021-09-09 11:47:04 +08:00
bool modified() const;
2021-09-07 00:32:16 +08:00
void setFileName(const QString& value);
void setModified(bool value);
2021-09-07 10:28:40 +08:00
void addFolder(const QString& s);
2021-09-07 00:32:16 +08:00
PProjectUnit addUnit(const QString& inFileName,
PFolderNode parentNode,
bool rebuild);
2021-09-12 22:45:00 +08:00
void buildPrivateResource(bool forceSave=false);
void checkProjectFileForUpdate(SimpleIni& ini);
2021-09-07 16:49:35 +08:00
void closeUnit(int index);
void createFolderNodes();
void doAutoOpen();
2021-09-09 00:15:12 +08:00
bool fileAlreadyExists(const QString& s);
PFolderNode folderNodeFromName(const QString& name);
2021-09-13 10:48:44 +08:00
char getCompilerOption(const QString& optionString);
2021-09-09 11:47:04 +08:00
QString getFolderPath(PFolderNode node);
int getUnitFromString(const QString& s);
2021-09-09 18:36:54 +08:00
void incrementBuildNumber();
2021-09-12 00:17:15 +08:00
int indexInUnits(const QString& fileName) const;
int indexInUnits(const Editor* editor) const;
2021-09-09 18:36:54 +08:00
QString listUnitStr(const QChar& separator);
void loadLayout(); // load all [UnitX]
void loadOptions(SimpleIni& ini);
2021-09-10 15:03:47 +08:00
void loadUnitLayout(Editor *e, int index); // load single [UnitX] cursor positions
2021-09-10 12:37:02 +08:00
PFolderNode makeNewFileNode(const QString& s, bool isFolder, PFolderNode newParent);
PFolderNode makeProjectNode();
2021-09-10 21:37:52 +08:00
int newUnit(PFolderNode parentNode,
2021-09-07 10:28:40 +08:00
const QString customFileName);
Editor* openUnit(int index);
2021-09-10 15:03:47 +08:00
void rebuildNodes();
bool removeEditor(int index, bool doClose);
2021-09-10 21:37:52 +08:00
bool removeFolder(PFolderNode node);
2021-09-11 18:42:49 +08:00
void resetParserProjectFiles();
2021-09-10 21:37:52 +08:00
void saveAll(); // save [Project] and all [UnitX]
void saveLayout(); // save all [UnitX]
2021-09-10 23:41:38 +08:00
void saveOptions();
2021-09-07 10:28:40 +08:00
void saveUnitAs(int i, const QString& sFileName); // save single [UnitX]
void saveUnitLayout(Editor* e, int index); // save single [UnitX] cursor positions
bool saveUnits();
2021-09-13 10:48:44 +08:00
void setCompilerOption(const QString& optionString, char value);
2021-09-11 09:21:44 +08:00
void sortUnitsByPriority();
void sortUnitsByAlpha();
2021-09-10 23:41:38 +08:00
void updateFolders();
2021-09-11 09:21:44 +08:00
void updateNodeIndexes();
2021-09-09 00:15:12 +08:00
2021-09-11 09:21:44 +08:00
//void showOptions();
2021-09-07 10:28:40 +08:00
// bool assignTemplate(const QString& aFileName, const PTemplate& aTemplate);
2021-09-10 23:41:38 +08:00
//void saveToLog();
2021-09-07 16:49:35 +08:00
std::shared_ptr<CppParser> cppParser();
2021-09-09 00:15:12 +08:00
const QString &filename() const;
2021-09-10 12:37:02 +08:00
const QString &name() const;
void setName(const QString &newName);
const PFolderNode &node() const;
void setNode(const PFolderNode &newNode);
2021-09-14 17:33:47 +08:00
ProjectOptions &options();
2021-09-10 15:03:47 +08:00
2021-09-11 18:42:49 +08:00
ProjectModel* model() ;
2021-09-11 11:42:20 +08:00
const QList<PProjectUnit> &units() const;
2021-09-05 23:45:05 +08:00
signals:
2021-09-07 10:28:40 +08:00
void nodesChanged();
void modifyChanged(bool value);
2021-09-07 00:32:16 +08:00
private:
void open();
2021-09-10 21:37:52 +08:00
void removeFolderRecurse(PFolderNode node);
2021-09-11 09:21:44 +08:00
void updateFolderNode(PFolderNode node);
2021-09-06 08:45:53 +08:00
private:
QList<PProjectUnit> mUnits;
ProjectOptions mOptions;
QString mFilename;
QString mName;
bool mModified;
QStringList mFolders;
std::shared_ptr<CppParser> mParser;
2021-09-07 16:49:35 +08:00
QList<PFolderNode> mFolderNodes;
2021-09-07 00:32:16 +08:00
PFolderNode mNode;
2021-09-11 09:21:44 +08:00
ProjectModel mModel;
2021-09-05 23:45:05 +08:00
};
QByteArray toByteArray(const QString& s);
QString fromByteArray(const QByteArray& s);
2021-09-05 23:45:05 +08:00
#endif // PROJECT_H