使用route类型定义节点路径,libProjectManager添加实用方法,projectPresent样板代码
This commit is contained in:
parent
a3ea94d58c
commit
0b764bf30a
|
@ -0,0 +1,68 @@
|
|||
#include "projectpresent.h"
|
||||
#include "command_list.h"
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QMenu>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
using namespace Components;
|
||||
using namespace CommandList;
|
||||
|
||||
ProjectPresent::ProjectPresent(Core::AppCore *core, QWidget *parent)
|
||||
: QWidget(parent), source(core), view_present(new QTreeView(this))
|
||||
{
|
||||
auto layout = new QVBoxLayout(this);
|
||||
|
||||
layout->addWidget(view_present);
|
||||
auto mgr = core->disp_core->get<DocumentsManager>(NAME(DocumentsManager));
|
||||
view_present->setModel(mgr->projectManager()->model());
|
||||
|
||||
connect(view_present, &QTreeView::customContextMenuRequested,
|
||||
this, &ProjectPresent::menu_popup);
|
||||
connect(view_present, &QTreeView::doubleClicked,
|
||||
this, &ProjectPresent::open_target);
|
||||
}
|
||||
|
||||
QString ProjectPresent::name() const
|
||||
{
|
||||
return NAME(ProjectPresent);
|
||||
}
|
||||
|
||||
void ProjectPresent::menu_popup(const QPoint &p)
|
||||
{
|
||||
QMenu m;
|
||||
m.addAction("新建路径", [this](){
|
||||
auto path_string = QInputDialog::getText(this, "输入路径定义/packa/packb/packc", "路径定义:");
|
||||
if(path_string.isEmpty())
|
||||
return;
|
||||
|
||||
source->disp_core->postCommand(NewPackage(path_string));
|
||||
});
|
||||
|
||||
auto index = this->view_present->currentIndex();
|
||||
if(index.isValid()){
|
||||
auto mgr = source->disp_core->get<DocumentsManager>(NAME(DocumentsManager));
|
||||
auto menu = m.addMenu("新建文件");
|
||||
auto views = mgr->fileTypes();
|
||||
for(auto &it : views){
|
||||
menu->addAction(it, [this, &it, &index, mgr](){
|
||||
auto name = QInputDialog::getText(this, "输入文件名称", "文件名称");
|
||||
auto path = mgr->converter(index);
|
||||
source->disp_core->postCommand(NewFile(path, name, it));
|
||||
});
|
||||
}
|
||||
|
||||
m.addSeparator();
|
||||
m.addAction("移除节点");
|
||||
}
|
||||
|
||||
|
||||
m.exec(mapToGlobal(p));
|
||||
}
|
||||
|
||||
void ProjectPresent::open_target(const QModelIndex &t)
|
||||
{
|
||||
auto mgr = source->disp_core->get<DocumentsManager>(NAME(DocumentsManager));
|
||||
auto path = mgr->converter(t);
|
||||
source->disp_core->postCommand(OpenFile(path));
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef PROJECTPRESENT_H
|
||||
#define PROJECTPRESENT_H
|
||||
|
||||
#include "manager_docs.h"
|
||||
|
||||
#include <QTreeView>
|
||||
#include <QWidget>
|
||||
#include <commandsdispatcher.h>
|
||||
#include <libProjectManager.h>
|
||||
|
||||
namespace Components {
|
||||
/**
|
||||
* @brief 项目视图
|
||||
*/
|
||||
class ProjectPresent : public QWidget, public Schedule::AccessibleObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ProjectPresent(Core::AppCore *core,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
|
||||
// AccessibleObject interface
|
||||
public:
|
||||
virtual QString name() const override;
|
||||
|
||||
private:
|
||||
Core::AppCore *const source;
|
||||
QTreeView *const view_present;
|
||||
|
||||
void menu_popup(const QPoint &p);
|
||||
void open_target(const QModelIndex &t);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // PROJECTPRESENT_H
|
|
@ -0,0 +1,41 @@
|
|||
#include "route.h"
|
||||
|
||||
using namespace Core;
|
||||
|
||||
Route::Route()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Route::Route(const Route &other)
|
||||
: links_store(other.links_store) {}
|
||||
|
||||
QStringList Route::links() const
|
||||
{
|
||||
return links_store;
|
||||
}
|
||||
|
||||
Route Route::operator |(const QString &node) const
|
||||
{
|
||||
Route exlink(*this);
|
||||
exlink.links_store.append(node);
|
||||
return exlink;
|
||||
}
|
||||
|
||||
bool Route::operator==(const Route &other) const
|
||||
{
|
||||
if(links_store.size() == other.links_store.size()){
|
||||
for(auto idx=0; idx<links_store.size(); ++idx)
|
||||
if(links_store.at(idx) != other.links_store.at(idx))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Route Route::collect(const QList<QString> &list)
|
||||
{
|
||||
Route v;
|
||||
v.links_store.append(list);
|
||||
return v;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef ROUTE_H
|
||||
#define ROUTE_H
|
||||
|
||||
#include <qstringlist.h>
|
||||
|
||||
|
||||
namespace Core {
|
||||
class Route
|
||||
{
|
||||
public:
|
||||
Route();
|
||||
Route(const Route& other);
|
||||
|
||||
QStringList links() const;
|
||||
Route operator|(const QString &node) const;
|
||||
bool operator==(const Route &other) const;
|
||||
|
||||
static Route collect(const QList<QString> &list);
|
||||
|
||||
private:
|
||||
QStringList links_store;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // ROUTE_H
|
|
@ -163,6 +163,13 @@ namespace Project {
|
|||
*/
|
||||
virtual QFileInfo queryInfo(const QModelIndex &path) = 0;
|
||||
|
||||
/**
|
||||
* @brief 通过文件反查获取ModelIndex
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
virtual QModelIndex queryIndex(const QFileInfo &file) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -357,6 +357,16 @@ QFileInfo XMLProjectManager::queryInfo(const QModelIndex &path)
|
|||
return QFileInfo(QFileInfo(filepath_store).dir().filePath(item->file()));
|
||||
}
|
||||
|
||||
QModelIndex XMLProjectManager::queryIndex(const QFileInfo &file)
|
||||
{
|
||||
auto xinfo = query_index(file, project_structure->item(0)->index());
|
||||
|
||||
if(xinfo.isValid())
|
||||
return xinfo;
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
ProjectNode *XMLProjectManager::node_follows(ProjectNode *pnode, const QList<QString> &path_remains)
|
||||
{
|
||||
if(path_remains.size()==0)
|
||||
|
@ -419,6 +429,30 @@ QModelIndex XMLProjectManager::groups_rebuild(ProjectNode *pnode, const QList<QS
|
|||
return item->index();
|
||||
}
|
||||
|
||||
QModelIndex XMLProjectManager::query_index(const QFileInfo &file, const QModelIndex &base)
|
||||
{
|
||||
if(!base.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
auto item = static_cast<ProjectNode*>(project_structure->itemFromIndex(base));
|
||||
if(item->nodeType() == NodeType::FILE) {
|
||||
auto dir = QFileInfo(filepath_store).absoluteDir();
|
||||
auto target_info = QFileInfo(dir.filePath(item->file()));
|
||||
if(target_info == file)
|
||||
return item->index();
|
||||
}
|
||||
else {
|
||||
for(auto idx=0; idx<item->rowCount(); ++idx)
|
||||
{
|
||||
auto idx_m = query_index(file, item->child(idx)->index());
|
||||
if(idx_m.isValid())
|
||||
return idx_m;
|
||||
}
|
||||
}
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
|
||||
void XMLProjectManager::moveTo(const QModelIndex &item_path, const QModelIndex &target_group, int index)
|
||||
{
|
||||
|
|
|
@ -68,6 +68,7 @@ namespace Project {
|
|||
virtual QList<std::tuple<QString, QFileInfo>> filesWithEnds(const QString &suffix) const override;
|
||||
|
||||
virtual QFileInfo queryInfo(const QModelIndex &path) override;
|
||||
virtual QModelIndex queryIndex(const QFileInfo &file) override;
|
||||
|
||||
private:
|
||||
Config::Configration *const project_config;
|
||||
|
@ -83,6 +84,9 @@ namespace Project {
|
|||
QList<std::tuple<QString, QFileInfo>> nodes_search(ProjectNode *pnode, const QString &suffix) const;
|
||||
|
||||
QModelIndex groups_rebuild(ProjectNode *pnode, const QList<QString> &path_remains);
|
||||
|
||||
|
||||
virtual QModelIndex query_index(const QFileInfo &file, const QModelIndex &base);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue