ProjectManager接口改进
This commit is contained in:
parent
4efa62dd52
commit
fc0a6e2dac
|
@ -14,6 +14,83 @@ namespace Project {
|
|||
*/
|
||||
class ProjectException : public Config::ParseException {};
|
||||
|
||||
class FilesOperate {
|
||||
public:
|
||||
virtual ~FilesOperate() = default;
|
||||
|
||||
/**
|
||||
* @brief 建立新的包路径
|
||||
* @param path_defs 包路径定义
|
||||
* @return
|
||||
*/
|
||||
virtual QModelIndex newPackage(const QList<QString> &path_defs) = 0;
|
||||
/**
|
||||
* @brief 转换QModexIndex为逻辑路径
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
virtual QStringList packagePath(const QModelIndex &path) const = 0;
|
||||
/**
|
||||
* @brief 在指定包路径下建立创建文本文件记录
|
||||
* @param package_appoint 指定包节点路径
|
||||
* @throw ProjectException
|
||||
*/
|
||||
virtual QModelIndex appendFile(const QModelIndex &package_appoint, const QString &name, const QString &path_on_disk) = 0;
|
||||
/**
|
||||
* @brief 重命名该节点名称
|
||||
* @param node
|
||||
* @param name
|
||||
*/
|
||||
virtual void rename(const QModelIndex &node, const QString &name) = 0;
|
||||
|
||||
/**
|
||||
* @brief 移动到新的分类中
|
||||
* @param node_frompath 移动的源文件节点路径
|
||||
* @param target_group 移动目标包路径
|
||||
* @return
|
||||
*/
|
||||
virtual void moveTo(const QModelIndex &node_frompath, const QModelIndex &target_group, int index = -1) = 0;
|
||||
|
||||
/**
|
||||
* @brief 删除指定的文件或者包组织节点
|
||||
* @param node_path 节点路径,包路径或文件路径
|
||||
* @throw ProjectException
|
||||
*/
|
||||
virtual void deleteT(const QModelIndex &node_path) = 0;
|
||||
};
|
||||
|
||||
class FilesQuery {
|
||||
public:
|
||||
virtual ~FilesQuery() = default;
|
||||
|
||||
/**
|
||||
* @brief 汇总该节点下管理的磁盘文件信息
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
virtual QList<QModelIndex> filesGather(const QModelIndex &node) const = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取所有指定后缀名的文件
|
||||
* @param suffix 后缀名类型
|
||||
* @return 文件集合
|
||||
*/
|
||||
virtual QList<std::tuple<QString, QFileInfo>> filesWithEnds(const QString &suffix) const = 0;
|
||||
/**
|
||||
* @brief 查询节点文件信息,文件节点返回文件的info,包节点返回文简介的info
|
||||
* @param path 树节点路径
|
||||
* @return QFileInfo 文件或文件夹的info实例
|
||||
*/
|
||||
virtual QFileInfo queryInfo(const QModelIndex &path) = 0;
|
||||
|
||||
/**
|
||||
* @brief 通过文件反查获取ModelIndex
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
virtual QModelIndex queryIndex(const QFileInfo &file) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 项目管理
|
||||
* 项目名称
|
||||
|
@ -39,11 +116,9 @@ namespace Project {
|
|||
*/
|
||||
virtual Config::Configration *configraions() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取项目文件所在文件夹
|
||||
* @return
|
||||
*/
|
||||
virtual QDir projectDir() const = 0;
|
||||
virtual FilesOperate *operateAccess() const = 0;
|
||||
|
||||
virtual FilesQuery *queryAccess() const = 0;
|
||||
|
||||
// 项目操作=========================================================
|
||||
/**
|
||||
|
@ -52,14 +127,6 @@ namespace Project {
|
|||
*/
|
||||
virtual QString suffix() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取项目文件的实际路径
|
||||
* @param project_dir
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
virtual QString fmtedProjectPath(const QString &project_dir, const QString &name) const = 0;
|
||||
|
||||
/**
|
||||
* @brief 载入项目组织文件
|
||||
* @param project_file 项目文件路径
|
||||
|
@ -72,21 +139,12 @@ namespace Project {
|
|||
* @param name 项目文件名
|
||||
* @throw ProjectException*, ParseException*
|
||||
*/
|
||||
virtual void newProject(const QString &project_dir, const QString &name) = 0;
|
||||
virtual void newProject(const QString &path_holder, const QString &name) = 0;
|
||||
|
||||
/**
|
||||
* @brief 关闭当前项目
|
||||
*/
|
||||
virtual void closeProject() = 0;
|
||||
/**
|
||||
* @brief 项目出于打开状态
|
||||
* @return
|
||||
*/
|
||||
virtual bool isOpen() const noexcept = 0;
|
||||
/**
|
||||
* @brief 修改状态,需要被保存
|
||||
* @return
|
||||
*/
|
||||
virtual bool isModified() const noexcept = 0;
|
||||
|
||||
/**
|
||||
* @brief save 保存当前项目
|
||||
|
@ -98,81 +156,32 @@ namespace Project {
|
|||
* @brief 获取项目名称
|
||||
* @return
|
||||
*/
|
||||
virtual QString projectName() const = 0;
|
||||
virtual QString name() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 重置项目名称
|
||||
* @param name
|
||||
*/
|
||||
virtual void resetProjectName(const QString& name) = 0;
|
||||
|
||||
// 项目内容管理=======================================================
|
||||
/**
|
||||
* @brief 建立新的包路径
|
||||
* @param path_defs 包路径定义
|
||||
* @return
|
||||
*/
|
||||
virtual QModelIndex newPackage(const QList<QString> &path_defs) = 0;
|
||||
/**
|
||||
* @brief 转换QModexIndex为逻辑路径
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
virtual QStringList packagePath(const QModelIndex &path) const = 0;
|
||||
/**
|
||||
* @brief 在指定包路径下建立创建文本文件记录
|
||||
* @param package_appoint 指定包节点路径
|
||||
* @throw ProjectException
|
||||
*/
|
||||
virtual QModelIndex signFile(const QModelIndex &package_appoint, const QString &name, const QString &path_on_disk) = 0;
|
||||
/**
|
||||
* @brief 重命名该节点名称
|
||||
* @param node
|
||||
* @param name
|
||||
*/
|
||||
virtual void rename(const QModelIndex &node, const QString &name) = 0;
|
||||
/**
|
||||
* @brief 汇总该节点下管理的磁盘文件信息
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
virtual QList<QModelIndex> filesGather(const QModelIndex &node) const = 0;
|
||||
/**
|
||||
* @brief 移动到新的分类中
|
||||
* @param node_frompath 移动的源文件节点路径
|
||||
* @param target_group 移动目标包路径
|
||||
* @return
|
||||
*/
|
||||
virtual void moveTo(const QModelIndex &node_frompath, const QModelIndex &target_group, int index=-1) = 0;
|
||||
/**
|
||||
* @brief 删除指定的文件或者包组织节点
|
||||
* @param node_path 节点路径,包路径或文件路径
|
||||
* @throw ProjectException
|
||||
*/
|
||||
virtual void deleteTarget(const QModelIndex &node_path) = 0;
|
||||
virtual void resetName(const QString &name) = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取所有指定后缀名的文件
|
||||
* @param suffix 后缀名类型
|
||||
* @return 文件集合
|
||||
*/
|
||||
virtual QList<std::tuple<QString, QFileInfo>> filesWithEnds(const QString &suffix) const = 0;
|
||||
/**
|
||||
* @brief 查询节点文件信息,文件节点返回文件的info,包节点返回文简介的info
|
||||
* @param path 树节点路径
|
||||
* @return QFileInfo 文件或文件夹的info实例
|
||||
*/
|
||||
virtual QFileInfo queryInfo(const QModelIndex &path) = 0;
|
||||
|
||||
/**
|
||||
* @brief 通过文件反查获取ModelIndex
|
||||
* @param file
|
||||
* @brief 获取项目文件所在文件夹
|
||||
* @return
|
||||
*/
|
||||
virtual QModelIndex queryIndex(const QFileInfo &file) = 0;
|
||||
virtual QDir directory() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 项目出于打开状态
|
||||
* @return
|
||||
*/
|
||||
virtual bool isOpenning() const noexcept = 0;
|
||||
|
||||
/**
|
||||
* @brief 修改状态,需要被保存
|
||||
* @return
|
||||
*/
|
||||
virtual bool isModified() const noexcept = 0;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace Project
|
||||
|
||||
#endif // LIBPROJECTMANAGER_H
|
||||
|
|
|
@ -60,10 +60,7 @@ QString XMLProjectManager::suffix() const
|
|||
return "nsf";
|
||||
}
|
||||
|
||||
bool XMLProjectManager::isOpen() const noexcept
|
||||
{
|
||||
return open_status;
|
||||
}
|
||||
bool XMLProjectManager::isOpenning() const noexcept { return open_status; }
|
||||
|
||||
bool XMLProjectManager::isModified() const noexcept
|
||||
{
|
||||
|
@ -115,10 +112,9 @@ void XMLProjectManager::openProject(const QString &project_file)
|
|||
pnode->setIcon(QIcon(":/icons/toplevel.png"));
|
||||
}
|
||||
|
||||
void XMLProjectManager::newProject(const QString &project_dir, const QString &name)
|
||||
{
|
||||
void XMLProjectManager::newProject(const QString &path_holder, const QString &name) {
|
||||
// 确定目标项目文件
|
||||
filepath_store = fmtedProjectPath(project_dir, name);
|
||||
filepath_store = path_holder;
|
||||
|
||||
QFileInfo info(filepath_store);
|
||||
if(info.exists())
|
||||
|
@ -129,7 +125,7 @@ void XMLProjectManager::newProject(const QString &project_dir, const QString &na
|
|||
project_node->setFile(".project_config.xml");
|
||||
project_structure->appendRow(project_node);
|
||||
|
||||
QDir root(project_dir);
|
||||
QDir root = info.absoluteDir();
|
||||
project_config->loadFile(root.filePath(project_node->file()));
|
||||
|
||||
// 写出到磁盘
|
||||
|
@ -138,14 +134,6 @@ void XMLProjectManager::newProject(const QString &project_dir, const QString &na
|
|||
project_node->setIcon(QIcon(":/icons/toplevel.png"));
|
||||
}
|
||||
|
||||
QString XMLProjectManager::fmtedProjectPath(const QString &project_dir, const QString &name) const
|
||||
{
|
||||
QDir root(project_dir);
|
||||
auto project_file = root.filePath(name + ".nsf");
|
||||
|
||||
return project_file;
|
||||
}
|
||||
|
||||
void XMLProjectManager::closeProject()
|
||||
{
|
||||
open_status = false;
|
||||
|
@ -175,26 +163,24 @@ void XMLProjectManager::save()
|
|||
txout.flush();
|
||||
}
|
||||
|
||||
QString XMLProjectManager::projectName() const
|
||||
{
|
||||
return project_structure->item(0)->text();
|
||||
}
|
||||
QString XMLProjectManager::name() const { return project_structure->item(0)->text(); }
|
||||
|
||||
void XMLProjectManager::resetProjectName(const QString &name)
|
||||
{
|
||||
this->project_structure->item(0)->setText(name);
|
||||
}
|
||||
void XMLProjectManager::resetName(const QString &name) { this->project_structure->item(0)->setText(name); }
|
||||
|
||||
Configration *XMLProjectManager::configraions() const
|
||||
{
|
||||
return this->project_config;
|
||||
}
|
||||
|
||||
QDir XMLProjectManager::projectDir() const
|
||||
QDir XMLProjectManager::directory() const
|
||||
{
|
||||
return QFileInfo(filepath_store).absoluteDir();
|
||||
}
|
||||
|
||||
FilesOperate *XMLProjectManager::operateAccess() const { return const_cast<XMLProjectManager *>(this); }
|
||||
|
||||
FilesQuery *XMLProjectManager::queryAccess() const { return const_cast<XMLProjectManager *>(this); }
|
||||
|
||||
void XMLProjectManager::structure_parser(QDomElement struct_elm, ProjectNode *pnode)
|
||||
{
|
||||
auto children = struct_elm.childNodes();
|
||||
|
@ -239,8 +225,7 @@ void XMLProjectManager::structure_severlize(ProjectNode *pnode, QDomElement &elm
|
|||
}
|
||||
}
|
||||
|
||||
QModelIndex XMLProjectManager::signFile(const QModelIndex &package_path, const QString &name, const QString &path_on_disk)
|
||||
{
|
||||
QModelIndex XMLProjectManager::appendFile(const QModelIndex &package_path, const QString &name, const QString &path_on_disk) {
|
||||
if(!package_path.isValid())
|
||||
throw new Impl_ProjectException("参数错误", "指定的package_path无效");
|
||||
|
||||
|
@ -298,8 +283,7 @@ QList<QModelIndex> XMLProjectManager::filesGather(const QModelIndex &node) const
|
|||
return rets;
|
||||
}
|
||||
|
||||
void XMLProjectManager::deleteTarget(const QModelIndex &node_path)
|
||||
{
|
||||
void XMLProjectManager::deleteT(const QModelIndex &node_path) {
|
||||
if(!node_path.isValid())
|
||||
throw new Impl_ProjectException("参数错误", "指定的节点路径无效");
|
||||
|
||||
|
|
|
@ -30,10 +30,10 @@ namespace Project {
|
|||
QString filename;
|
||||
};
|
||||
|
||||
|
||||
class LIBPROJECTMANAGER_EXPORT XMLProjectManager
|
||||
: public QObject, public Project::ProjectManager
|
||||
{
|
||||
class LIBPROJECTMANAGER_EXPORT XMLProjectManager : public QObject,
|
||||
public Project::ProjectManager,
|
||||
public Project::FilesOperate,
|
||||
public Project::FilesQuery {
|
||||
public:
|
||||
XMLProjectManager(QObject *parent = nullptr);
|
||||
virtual ~XMLProjectManager();
|
||||
|
@ -43,27 +43,30 @@ namespace Project {
|
|||
public:
|
||||
virtual QStandardItemModel* model() const override;
|
||||
virtual Config::Configration *configraions() const override;
|
||||
virtual QDir projectDir() const override;
|
||||
virtual QDir directory() const override;
|
||||
|
||||
virtual FilesOperate *operateAccess() const override;
|
||||
|
||||
virtual FilesQuery *queryAccess() const override;
|
||||
|
||||
virtual QString suffix() const override;
|
||||
virtual QString fmtedProjectPath(const QString &project_dir, const QString &name) const override;
|
||||
virtual bool isOpen() const noexcept override;
|
||||
virtual bool isOpenning() const noexcept override;
|
||||
virtual bool isModified() const noexcept override;
|
||||
virtual void openProject(const QString &project_file) override;
|
||||
virtual void newProject(const QString &project_dir, const QString &name) override;
|
||||
virtual void newProject(const QString &path_holder, const QString &name) override;
|
||||
virtual void closeProject() override;
|
||||
virtual void save() override;
|
||||
virtual QString projectName() const override;
|
||||
virtual void resetProjectName(const QString& name) override;
|
||||
virtual QString name() const override;
|
||||
virtual void resetName(const QString &name) override;
|
||||
|
||||
virtual QModelIndex newPackage(const QList<QString> &path) override;
|
||||
virtual QStringList packagePath(const QModelIndex &path) const override;
|
||||
|
||||
virtual QModelIndex signFile(const QModelIndex &package_path, const QString &name, const QString &path_on_disk) override;
|
||||
virtual QModelIndex appendFile(const QModelIndex &package_path, const QString &name, const QString &path_on_disk) override;
|
||||
virtual void rename(const QModelIndex &node, const QString &name) override;
|
||||
virtual QList<QModelIndex> filesGather(const QModelIndex &node) const override;
|
||||
virtual void moveTo(const QModelIndex &node_frompath, const QModelIndex &target_group, int index) override;
|
||||
virtual void deleteTarget(const QModelIndex &node_path) override;
|
||||
virtual void deleteT(const QModelIndex &node_path) override;
|
||||
|
||||
virtual QList<std::tuple<QString, QFileInfo>> filesWithEnds(const QString &suffix) const override;
|
||||
|
||||
|
@ -88,6 +91,5 @@ namespace Project {
|
|||
|
||||
virtual QModelIndex query_index(const QFileInfo &file, const QModelIndex &base);
|
||||
};
|
||||
|
||||
}
|
||||
#endif // XMLPROJECTMANAGER_H
|
||||
|
|
Loading…
Reference in New Issue