From 41a5f39a1c66f04f1c539079e52ecb02d0d27895 Mon Sep 17 00:00:00 2001 From: xiaokai <2485423036@qq.com> Date: Sat, 10 Jun 2023 08:00:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/UWE_projectCode/#mainwindow.cpp# | 954 +++++++++++++++++++++++++ src/UWE_projectCode/.#mainwindow.cpp | 0 src/UWE_projectCode/finaltest.pro | 49 ++ src/UWE_projectCode/finaltest.pro.user | 326 +++++++++ src/UWE_projectCode/finddialog.cpp | 53 ++ src/UWE_projectCode/finddialog.h | 11 + src/UWE_projectCode/mytreeview.cpp | 236 ++++++ src/UWE_projectCode/mytreeview.h | 47 ++ 8 files changed, 1676 insertions(+) create mode 100644 src/UWE_projectCode/#mainwindow.cpp# create mode 100644 src/UWE_projectCode/.#mainwindow.cpp create mode 100644 src/UWE_projectCode/finaltest.pro create mode 100644 src/UWE_projectCode/finaltest.pro.user create mode 100644 src/UWE_projectCode/finddialog.cpp create mode 100644 src/UWE_projectCode/finddialog.h create mode 100644 src/UWE_projectCode/mytreeview.cpp create mode 100644 src/UWE_projectCode/mytreeview.h diff --git a/src/UWE_projectCode/#mainwindow.cpp# b/src/UWE_projectCode/#mainwindow.cpp# new file mode 100644 index 0000000..776a645 --- /dev/null +++ b/src/UWE_projectCode/#mainwindow.cpp# @@ -0,0 +1,954 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +// 是否启用QMainWindow自带的菜单 +//#define USE_DEFAULT_MENU_BAR +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + this->variate_map = new Variate_Map; + // 建立项目与主界面的联系 + this->work_project = new Work_Project; + this->work_project->father = this; + + // syn界面布局设置 + qmainwindow_syn = new QMainWindow(); + QWidget *widget_syn = new QWidget(); + + QHBoxLayout *layout_syn = new QHBoxLayout(widget_syn); + layout_syn->addWidget(ui->widget); + widget_syn->setLayout(layout_syn); + qmainwindow_syn->setCentralWidget(widget_syn); + qmainwindow_syn->addDockWidget(Qt::TopDockWidgetArea, ui->dockWidget_src_syn); + +// qmainwindow_syn->addDockWidget(Qt::BottomDockWidgetArea, ui->dockWidget_cmd_syn); + +// QVBoxLayout *layout = new QVBoxLayout(widget_syn); +// layout->addWidget(ui->widget, 0, Qt::AlignLeft); +// QVBoxLayout *layout = new QVBoxLayout; +// layout->addWidget(ui->widget); +// QHBoxLayout *hLayout = new QHBoxLayout; +// hLayout->addWidget(ui->widget); +// QWidget *centralWidget = new QWidget; +// centralWidget->setLayout(hLayout); +// qmainwindow_syn->setCentralWidget(ui->widget); +// layout1->addWidget(button); +// ui->widget->setLayout(layout1); +// ui->widget->setGeometry(0, 0, 150, 600); + + ui->tabWidget_flow->addTab(qmainwindow_syn, "Syn"); + ui->tabWidget_flow->removeTab(0); + + // pt界面布局设置 + qmainwindow_pt = new QMainWindow(); + qmainwindow_pt->setCentralWidget(new QWidget()); + qmainwindow_pt->addDockWidget(Qt::TopDockWidgetArea, ui->dockWidget_src_pt); + qmainwindow_pt->addDockWidget(Qt::BottomDockWidgetArea, ui->dockWidget_cmd_pt); + + ui->tabWidget_flow->removeTab(0); + ui->tabWidget_flow->addTab(qmainwindow_pt, "PT"); + + + // 在右侧浮动窗口中添 report窗口 +// dockWidget_report_syn = new QDockWidget(tr("report"), this); +// dockWidget_report_syn->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetClosable); +// dockWidget_report_syn->setVisible(true); +// addDockWidget(Qt::RightDockWidgetArea, dockWidget_report_syn); +// qmainwindow_syn->tabifyDockWidget(ui->dockWidget_src_syn, dockWidget_report_syn); +// ui->dockWidget_src_syn->raise(); + + // 在左侧浮动窗口中添 module窗口 + tabifyDockWidget(ui->dockWidget_file, ui->dockWidget_module); + ui->dockWidget_file->raise(); + + //指定菜单 +#ifdef USE_DEFAULT_MENU_BAR + //添 菜单 (此处添 为的为QMainWindow自带的菜单) + pMenuBar = this->menuBar(); +#else + //添 自定义菜单 + pMenuBar = new QMenuBar(this); +#endif + + //定义菜单项 + //(&n)代表快捷方式,当窗口获得焦点时按alt+n即可打开“测试”菜单项 + pMenu1 = new QMenu("文件(&n)",this); + pMenu2 = new QMenu("执行",this); + pMenu3 = new QMenu("工具",this); + + //定义子菜单 + //(&s)为子菜单快捷键,当打开该菜单项后,按下‘s’键即可响应 + pAction_newproject = new QAction("新建项目(&s)",this); + //新建一个带图 的菜单项,图 使用资源文件中的资源 + pAction_openproject = new QAction(QIcon(":/new/prefix1/resource/soccer_ball.ico"),"打开项目",this); + pAction_save = new QAction("保存",this); + pAction_syn = new QAction("run syn(&y)",this); + pAction_parameter_config = new QAction("参数配置",this); + pActionTest5 = new QAction("测试5(&M)",this); + pActionTest6 = new QAction("测试6",this); + + //将菜单项添 到子菜单 + pMenu1->addAction(pAction_newproject); + pMenu1->addAction(pAction_openproject); + //在菜单项之间添 分割线 + pMenu1->addSeparator(); + pMenu1->addAction(pAction_save); + + pMenu2->addAction(pAction_parameter_config); + pMenu2->addAction(pAction_syn); + + + pMenu3->addAction(pActionTest5); + pMenu3->addAction(pActionTest6); + + //将子菜单添 到菜单 + pMenuBar->addMenu(pMenu1); + pMenuBar->addMenu(pMenu2); + pMenuBar->addMenu(pMenu3); + + // 终端窗口 + ui->pushButton_run_cmd_syn->setFocus(); + ui->pushButton_run_cmd_syn->setShortcut(Qt::Key_Return); + + m_process_bash = new QProcess; + m_process_bash->start("bash"); + m_process_bash->waitForStarted(); + m_process_bash->write("cd / \n"); + + + // 设置module列表 + this->model_module = new QStandardItemModel; + model_module->setHorizontalHeaderLabels(QStringList()<<"module name"<<"state"); + this->ui->treeView_module->setModel(model_module); + this->ui->treeView_module->setColumnWidth(0, 200); + this->ui->treeView_module->setColumnWidth(1, 50); + + QMenu *menu_module = new QMenu(this); + QAction *pAction_newmodule = new QAction("new module", this); + QAction *pAction_delmodule = new QAction("delete module", this); + menu_module->addAction(pAction_newmodule); + menu_module->addAction(pAction_delmodule); + ui->treeView_module->setContextMenuPolicy(Qt::CustomContextMenu); + + // 建立信号槽连接,处理module 形列表右键菜单事件 + connect(ui->treeView_module, &QTreeView::customContextMenuRequested, this, [=](const QPoint &pos) { + // 显示右键菜单 + menu_module->popup(ui->treeView_module->viewport()->mapToGlobal(pos)); + }); + // new mdoule槽连接 + connect(pAction_newmodule, &QAction::triggered, this, &MainWindow::New_module); + + +#ifndef USE_DEFAULT_MENU_BAR + //当不使用QMainWindow自带的菜单 时,必须要 上此行 + setMenuBar(pMenuBar); +#endif + + //添 菜单响应函数 + connect(pAction_newproject, &QAction::triggered, this->work_project, &Work_Project::New_Project_1); + connect(pAction_openproject,&QAction::triggered,this,&MainWindow::OpenProject); + connect(pAction_parameter_config, &QAction::triggered, this, &MainWindow::Parameter_Config); + + connect(m_process_bash, &QProcess::readyReadStandardOutput, this, &MainWindow::readBashStandardOutputInfo); + connect(m_process_bash, &QProcess::readyReadStandardError, this, &MainWindow::readBashStandardErrorInfo); +} + +// 打开项目响应函数 +void MainWindow::OpenProject() +{ + this->work_project->uwe_project_path = QFileDialog::getExistingDirectory(this, "打开项目", "/home/UWE/zj"); + chdir(work_project->uwe_project_path.toStdString().data()); + work_project->Get_Work_config(); + + //设置 形文件列表 + this->model_file = new QFileSystemModel; + this->model_file->setRootPath(this->work_project->uwe_project_path); + this->ui->treeView_file->setModel(this->model_file); + this->ui->treeView_file->setRootIndex(this->model_file->index(this->work_project->uwe_project_path)); + this->ui->treeView_file->setHeaderHidden(true); + this->ui->treeView_file->setColumnHidden(1, true); + this->ui->treeView_file->setColumnHidden(2, true); + this->ui->treeView_file->setColumnHidden(3, true); + + connect(this->ui->treeView_file, &QTreeView::clicked, this, &MainWindow::TreeClicked); + + //终端进入工作项目 + string cmd_cd = "cd " + work_project->uwe_project_path.toStdString() + "\n pwd \n"; + this->m_process_bash->write(cmd_cd.data()); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +string get_current_date(); +// 参数配置响应函数 +void MainWindow::Parameter_Config() +{ + this->variate_map->add_variate("TCLPATH", "."); + this->variate_map->add_variate("DCWORK", "./dc.work"); + this->variate_map->add_variate("current_date", get_current_date()); + //this->variate_map->Generate_Config_File(); + + this->ui->textEdit_cmd_syn->append("Parameter config completed!\n"); +} + +// 新建项目1响应函数 +void Work_Project::New_Project_1() +{ + QDialog *qdialog = new QDialog; + qdialog->setWindowTitle("新建项目"); + qdialog->setFixedSize(800, 450); + + QHBoxLayout *layout = new QHBoxLayout(qdialog); + QListWidget *listWidget = new QListWidget; + listWidget->setMinimumWidth(150); + listWidget->setFont(QFont("宋体",14)); + listWidget->addItem("Project1"); + listWidget->addItem(""); + QWidget *widget1 = new QWidget, *widget2 = new QWidget; + widget1->setMaximumHeight(350); widget2->setMaximumHeight(350); + QLabel *lab1 = new QLabel("创建项目流程主要包括导入项目路径、导入代 \n路径、选择顶层模块", widget1); + lab1->setFont(QFont("宋体", 15)); + lab1->setWordWrap(true); + lab1->adjustSize(); + lab1->setMinimumSize(500, 100); + QLabel *lab2 = new QLabel("", widget2); + QStackedLayout *stackedLayout = new QStackedLayout; + stackedLayout->addWidget(widget1); + stackedLayout->addWidget(widget2); + + layout->addWidget(listWidget, 2); + layout->addLayout(stackedLayout, 3); + qdialog->setLayout(layout); + + QPushButton *button_next = new QPushButton("下一步", qdialog); + button_next->move(568, 400); + QPushButton *button_cancel = new QPushButton("取消", qdialog); + button_cancel->move(675, 400); + + QObject::connect(listWidget, &QListWidget::currentRowChanged, stackedLayout, &QStackedLayout::setCurrentIndex); + QObject::connect(button_next, &QPushButton::clicked, qdialog, &QDialog::close); + QObject::connect(button_next, &QPushButton::clicked, this, &Work_Project::New_Project_2); + QObject::connect(button_cancel, &QPushButton::clicked, qdialog, &QDialog::close); + + qdialog->exec(); +} + + +// 新建项目2响应函数(新建项目2对话框) +void Work_Project::New_Project_2() +{ + QDialog *qdialog = new QDialog; + qdialog->setWindowTitle("新建项目"); + qdialog->setFixedSize(800,450); + + //添 表 布局 + QFormLayout* layout = new QFormLayout(); + layout->setRowWrapPolicy(QFormLayout::DontWrapRows); + edit_uwe_project_path = new QLineEdit(); + edit_uwe_project_name = new QLineEdit(); + layout->addRow("项目路径:", edit_uwe_project_path); + layout->addRow("新建项目名称:", edit_uwe_project_name); + + // 选择路径按钮 + QPushButton *button_work_project_path = new QPushButton(edit_uwe_project_path); + button_work_project_path->setText("......"); + button_work_project_path->setCursor(Qt::ArrowCursor); + QWidgetAction* action = new QWidgetAction(edit_uwe_project_path); + action->setDefaultWidget(button_work_project_path); + edit_uwe_project_path->addAction(action, QLineEdit::TrailingPosition); + + // 将布局添 到对话框 + qdialog->setLayout(layout); + + // 操作按键 + QPushButton *button_next = new QPushButton("下一步", qdialog); + button_next->move(568, 400); + QPushButton *button_back = new QPushButton("上一步", qdialog); + button_back->move(675, 400); + + // 按键响应信号槽函数 + connect(button_work_project_path, &QPushButton::clicked, [=](){ + this->uwe_project_path = QFileDialog::getExistingDirectory(0, "选择目录", "/home/UWE/zj"); + edit_uwe_project_path->setText(uwe_project_path); + }); + connect(button_next, &QPushButton::clicked, qdialog, &QDialog::close); + connect(button_next, &QPushButton::clicked, this, &Work_Project::New_setup_lib_path); + QObject::connect(button_back, &QPushButton::clicked, qdialog, &QDialog::close); + QObject::connect(button_back, &QPushButton::clicked, this, &Work_Project::New_Project_1); + + // 显示对话框 + qdialog->exec(); +} + +// lib_path setup设置界面 +void Work_Project::New_setup_lib_path() +{ + // 保存UWE项目信息 + uwe_project_name = edit_uwe_project_name->text(); + uwe_project_path = edit_uwe_project_path->text(); + + // 新建对话框 + QDialog *qdialog = new QDialog; + qdialog->setWindowTitle("库路径配置"); + qdialog->setFixedSize(800,400); + + // 新建my_lib_path列表 + QListWidget *qlistwidget_lib_path = new QListWidget(qdialog); + qlistwidget_lib_path->resize(600, 350); + // 如果list_lib_path不为空(即上一步退回) + if (!list_lib_path.isEmpty()){ + foreach(QString lib_path, list_lib_path) + qlistwidget_lib_path->addItem(lib_path); + } + + // 添 添 路径, 除路径,下一步,上一步按键 + QPushButton *button_addpath = new QPushButton("添 路径", qdialog); + button_addpath->move(650, 100); + QPushButton *button_delpath = new QPushButton(" 除路径", qdialog); + button_delpath->move(650, 160); + QPushButton *button_next = new QPushButton("下一步", qdialog); + button_next->move(670, 270); + QPushButton *button_previous = new QPushButton("上一步", qdialog); + button_previous->move(670, 310); + + // add path按键响应 + connect(button_addpath, &QPushButton::clicked, [=](){ + QString lib_path = QFileDialog::getExistingDirectory(0, "选择库路径", "/home/UWE/zj", QFileDialog::ShowDirsOnly); + if (!list_lib_path.contains(lib_path)){ + qlistwidget_lib_path->addItem(lib_path); + list_lib_path.append(lib_path); + } + }); + // del path按键响应 + connect(button_delpath, &QPushButton::clicked, [=](){ + QListWidgetItem* selectedItem = qlistwidget_lib_path->currentItem(); + if (selectedItem != nullptr) { + QString lib_path = selectedItem->text(); + list_lib_path.removeOne(lib_path); + qlistwidget_lib_path->takeItem(qlistwidget_lib_path->row(selectedItem)); + delete selectedItem; + } + }); + // next step按键响应 + connect(button_next, &QPushButton::clicked, qdialog, &QDialog::close); + connect(button_next, &QPushButton::clicked, this, &Work_Project::New_setup_target_library); + // previous step按键响应 + connect(button_previous, &QPushButton::clicked, qdialog, &QDialog::close); + connect(button_previous, &QPushButton::clicked, this, &Work_Project::New_Project_2); + + // 显示对话框 + qdialog->exec(); +} + +// 从lib_path中提取lib 函数 +void Work_Project::Extract_lib() +{ + // lib_path不为空 + if (!list_lib_path.isEmpty()){ + // 遍历所有lib_path,提取其中的lib + foreach (QString lib_path, list_lib_path){ + QDir dir(lib_path); + QFileInfoList list = dir.entryInfoList(); + + for (int i = 0; i < list.size(); ++i) { + QFileInfo fileInfo = list.at(i); + if (fileInfo.isFile()) { + QString fileName = fileInfo.fileName(); + if ((list_lib.indexOf(fileName) == -1) && (fileName.endsWith(".db", Qt::CaseInsensitive) || fileName.endsWith(".lib", Qt::CaseInsensitive))) + list_lib.append(fileName); + QString filePath = fileInfo.filePath(); + // 处理子目录 + } else if (fileInfo.isDir() && fileInfo.fileName() != "." && fileInfo.fileName() != "..") { + QDir subDir(fileInfo.filePath()); + subDir.setFilter(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks); + QFileInfoList subList = subDir.entryInfoList(); + for (int j = 0; j < subList.size(); ++j) { + QFileInfo subFileInfo = subList.at(j); + QString fileName = subFileInfo.fileName(); + if ((list_lib.indexOf(fileName) == -1) && (fileName.endsWith(".db", Qt::CaseInsensitive) || fileName.endsWith(".lib", Qt::CaseInsensitive))) + list_lib.append(fileName); + } + } + } + } + } +} + +// 展示lib 函数 +QTableView* Work_Project::Show_lib(QList& list_lib, QStandardItemModel *model) +{ + QTableView *tableView = new QTableView(); + int size = list_lib.size(); + int remainder = size % 4; + for (int i = 0; i < size-remainder; i=i+4) { + QList rowItems; + rowItems.append(new QStandardItem(list_lib[i])); + rowItems.append(new QStandardItem(list_lib[i+1])); + rowItems.append(new QStandardItem(list_lib[i+2])); + rowItems.append(new QStandardItem(list_lib[i+3])); + model->appendRow(rowItems); + } + QList rowItems; + for (int i = size-remainder; i < size; i++) + rowItems.append(new QStandardItem(list_lib[i])); + model->appendRow(rowItems); + + tableView->setModel(model); + tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); + tableView->resizeColumnsToContents(); + tableView->resizeRowsToContents(); + tableView->setWordWrap(true); + + return tableView; +} + +// target_library选择界面 +void Work_Project::New_setup_target_library() +{ + // 提取lib + Extract_lib(); + + // 展示lib + QStandardItemModel *model = new QStandardItemModel(); + QTableView *tableView = Show_lib(list_lib, model); + + // 对话框及按键 + QDialog *dialog = new QDialog(); + dialog->setWindowTitle("target_library选择"); + dialog->resize(1400, 800); + QVBoxLayout *layout = new QVBoxLayout(); + layout->addWidget(tableView); + QHBoxLayout *buttonLayout = new QHBoxLayout(); + QPushButton *button_next = new QPushButton("确定"); + QPushButton *button_previous = new QPushButton("上一步"); + buttonLayout->addWidget(button_next); + buttonLayout->addWidget(button_previous); + layout->addLayout(buttonLayout); + dialog->setLayout(layout); + + // 响应函数 + connect(button_next, &QPushButton::clicked, dialog, &QDialog::accept); + connect(button_previous, &QPushButton::clicked, dialog, &QDialog::close); + connect(button_previous, &QPushButton::clicked, this, &Work_Project::New_setup_lib_path); + + if (dialog->exec() == QDialog::Accepted) { + QItemSelectionModel *selectionModel = tableView->selectionModel(); + QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); + + // iterate over the selected indexes and add their rows to the set + for (const QModelIndex &index : selectedIndexes) { + QString lib = model->data(model->index(index.row(), index.column())).toString(); + list_target_lib_selected.append(lib); + } + // 进入下一界面 + New_setup_link_library(); + } +} + +// link_library选择界面 +void Work_Project::New_setup_link_library() +{ + // 展示lib + QStandardItemModel *model = new QStandardItemModel(); + QTableView *tableView = Show_lib(list_lib, model); + + // 对话框及按键 + QDialog *dialog = new QDialog(); + dialog->setWindowTitle("link_library选择"); + dialog->resize(1400, 800); + QVBoxLayout *layout = new QVBoxLayout(); + layout->addWidget(tableView); + QHBoxLayout *buttonLayout = new QHBoxLayout(); + QPushButton *button_next = new QPushButton("确定"); + QPushButton *button_previous = new QPushButton("上一步"); + buttonLayout->addWidget(button_next); + buttonLayout->addWidget(button_previous); + layout->addLayout(buttonLayout); + dialog->setLayout(layout); + + // 响应函数 + connect(button_next, &QPushButton::clicked, dialog, &QDialog::accept); + connect(button_previous, &QPushButton::clicked, dialog, &QDialog::close); + connect(button_previous, &QPushButton::clicked, this, &Work_Project::New_setup_target_library); + + if (dialog->exec() == QDialog::Accepted) { + QItemSelectionModel *selectionModel = tableView->selectionModel(); + QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); + + // iterate over the selected indexes and add their rows to the set + for (const QModelIndex &index : selectedIndexes) { + QString lib = model->data(model->index(index.row(), index.column())).toString(); + list_link_lib_selected.append(lib); + } + // 进入下一界面 + Src_Project_Environment_set(); + } +} + + +// 芯片环境设置响应函数 +void Work_Project::Src_Project_Environment_set() +{ + QDialog *qdialog = new QDialog; + qdialog->setWindowTitle("芯片项目环境设置"); + qdialog->setFixedSize(800, 450); + + //输入框及其按钮 + QFormLayout *layout = new QFormLayout; + layout->setRowWrapPolicy(QFormLayout::DontWrapRows); + edit_src_project_path = new QLineEdit; + edit_src_path = new QLineEdit; + layout->addRow("芯片项目路径:", edit_src_project_path); + layout->addRow("代 路径", edit_src_path); + + QPushButton *button_src_project_path = new QPushButton(edit_src_project_path); + QPushButton *button_src_path = new QPushButton(edit_src_path); + button_src_project_path->setText("..."); button_src_path->setText("..."); + button_src_project_path->setCursor(Qt::ArrowCursor); button_src_path->setCursor(Qt::ArrowCursor); + QWidgetAction *action_Project_path = new QWidgetAction(edit_src_project_path), *action_src_path = new QWidgetAction(edit_src_path); + action_Project_path->setDefaultWidget(button_src_project_path); action_src_path->setDefaultWidget(button_src_path); + edit_src_project_path->addAction(action_Project_path, QLineEdit::TrailingPosition); edit_src_path->addAction(action_src_path, QLineEdit::TrailingPosition); + qdialog->setLayout(layout); + + //单独按钮 + QPushButton *button_determine = new QPushButton("确定", qdialog), *button_back = new QPushButton("上一步", qdialog); + button_determine->move(568, 400); button_back->move(675, 400); + + //按钮对应槽函数 + connect(button_src_project_path, &QPushButton::clicked, [=](){ + this->src_project_path = QFileDialog::getExistingDirectory(0, "选择目录", "/home/UWE/zj"); + edit_src_project_path->setText(src_project_path); + }); + connect(button_src_path, &QPushButton::clicked, [=](){ + src_path = QFileDialog::getExistingDirectory(0, "选择目录", "/home/UWE/zj"); + edit_src_path->setText(src_path); + }); + connect(button_determine, &QPushButton::clicked, qdialog, &QDialog::close); + connect(button_determine, &QPushButton::clicked, this, &Work_Project::Src_Project_Environment_set_Determine); + connect(button_back, &QPushButton::clicked, qdialog, &QDialog::close); + connect(button_back, &QPushButton::clicked, this, &Work_Project::New_setup_link_library); + + qdialog->exec(); +} + + +// 芯片项目环境配置确定响应函数 +void Work_Project::Src_Project_Environment_set_Determine() +{ + src_project_path = edit_src_project_path->text(); + src_path = edit_src_path->text(); +// module_name = edit_module_name->text(); + + // 生成工作项目对应文件夹 + string str_work_project_path = uwe_project_path.toStdString(), str_work_project_name = uwe_project_name.toStdString(); + chdir(str_work_project_path.data()); + mkdir(str_work_project_name.data(), 0755); + str_work_project_path += '/' + str_work_project_name; + chdir(str_work_project_path.data()); + uwe_project_path = QString::fromStdString(str_work_project_path); + qDebug() << uwe_project_path; + + // 保存配置信息 + Generate_UWE_Work_config(); + + // 设置 形文件列表 + this->father->model_file = new QFileSystemModel; + this->father->model_file->setRootPath(uwe_project_path); + this->father->ui->treeView_file->setModel(this->father->model_file); + this->father->ui->treeView_file->setRootIndex(this->father->model_file->index(uwe_project_path)); + this->father->ui->treeView_file->setHeaderHidden(true); + this->father->ui->treeView_file->setColumnHidden(1, true); + this->father->ui->treeView_file->setColumnHidden(2, true); + this->father->ui->treeView_file->setColumnHidden(3, true); + + connect(this->father->ui->treeView_file, &QTreeView::clicked, this->father, &MainWindow::TreeClicked); + + // 终端进入项目文件夹,链接src代 文件夹 + string ln_cmd = " ln -s " + this->src_path.toStdString() + ' ' + "./src"; ln_cmd += "\nln -s /home/UWE/zj/tmp/Scripts ./Scripts"; + string cmd_1 = "cd "+str_work_project_path+'\n' + "pwd\n" + ln_cmd+'\n'; + this->father->m_process_bash->write(cmd_1.data()); + + // 生成执行所需tcl文件 + ofstream out1("ProjectPathSetting.tcl", ios::out); + out1 << "set PROJECTPATH " << this->src_project_path.toStdString() << "\n" << "puts ${PROJECTPATH}"; + out1.close(); + + // make Prepare的一系列操作 + string cmd_2 = "echo 'ProjectPathSetting.tcl is generated successfully!\n./src soft link is created.'\n"; + string cmd_cp = "cp -r /home/UWE/zj/tmp/Template/* ./ \ntouch tmp.log \necho 'copy files in Template here.' \ncp -r /home/UWE/zj/tmp/Makefile ./ \n" + "cp -r /home/UWE/zj/test_1/syn_main.tcl ./ \n"; + string cmd_flist = "filelistpath=`find ./src/ -maxdepth 1 -name '*flist*' -type f` \nfilelistname=${filelistpath#*src/} \necho '`include \"./\"' > ./dc.work/filelist.v \n"; + string cmd_incdir = "incdirlistpath=`find ./src/ -maxdepth 1 -name '*incdir*' -type f` \nincdirlistname=${incdirlistpath#*src/} \necho -f ./src/$incdirlistname \ > ./nc.work/sim_filelist.f \n"; + string cmd_nc = "echo '-f ./src/'$filelistname'' \ >> ./nc.work/sim_filelist.f \necho \" \" >> ./nc.work/sim_filelist.f \necho //Add simulation files bellow >> ./nc.work/sim_filelist.f \n"; + string cmd_mv = "mv ./spyglass.work/demo.prj ./spyglass.work/"; cmd_mv += this->module_name.toStdString(); cmd_mv += ".prj \n"; + cmd_mv += "mv ./spyglass.work/waiver/demo.awl ./spyglass.work/waiver/"+this->module_name.toStdString()+".awl\n"; + cmd_2 += cmd_cp + cmd_flist + cmd_incdir + cmd_nc + cmd_mv; + //cout << cmd_2; + this->father->m_process_bash->write(cmd_2.data()); + + // 生成synopsys_dc.setup文件 + Generate_Setup_File(); +} + +// 生成工作项目配置文件 +void Work_Project::Generate_UWE_Work_config() +{ + ofstream out("UWE_Project_config", ios::out); + out << "uwe_project_path = " << uwe_project_path.toStdString() << endl; + out << "uwe_project_name = " << uwe_project_name.toStdString() << endl; + out << "src_project_path = " << src_project_path.toStdString() << endl; + out << "src_path = " << src_path.toStdString() << endl; + out.close(); +} + +// 生成setup文件 +void Work_Project::Generate_Setup_File() +{ + // 配置setup默认值 + edit_designer = new QLineEdit(); edit_designer->setText("{c64 group}"); + edit_company = new QLineEdit(); edit_company->setText("{nudt c64}"); + edit_synthetic_library = new QLineEdit(); edit_synthetic_library->setText("{dw_foundation.sldb}"); + edit_target_library = new QLineEdit(); + edit_link_library = new QLineEdit(); + edit_symbol_library=new QLineEdit(); edit_symbol_library->setText("{dw_foundation.sldb}"); + edit_cache_write=new QLineEdit(); edit_cache_write->setText("./cache"); + edit_cache_read=new QLineEdit(); edit_cache_read->setText("$cache_write"); + edit_my_lib_path=new QLineEdit(); + edit_search_path=new QLineEdit(); edit_search_path->setText("$search_path $my_lib_path "); + edit_suppress_message=new QLineEdit(); edit_suppress_message->setText("{UID-401}"); + edit_define_design_lib=new QLineEdit(); edit_define_design_lib->setText("-path ./analyzed"); + edit_view_script_submenu_items=new QLineEdit(); edit_view_script_submenu_items->setText("{\"Clean Sweep" "remove_design -design\"}"); + + // 生成synopsys_dc.setup文件 + ofstream out_setup("synopsys_dc.setup", ios::out); + out_setup << "set designer " << this->edit_designer->text().toStdString() << '\n'; + out_setup << "set company " << this->edit_company->text().toStdString() << '\n'; + + out_setup << "set synthetic_library " << this->edit_synthetic_library->text().toStdString() << '\n'; + out_setup << "set target_library {"; + for (int i = 0; i < list_target_lib_selected.size(); i++){ + out_setup << list_target_lib_selected.at(i).toStdString() << ' '; + } out_setup << '}' << endl; + + out_setup << "set link_library {"; + for (int i = 0; i < list_link_lib_selected.size(); i++){ + out_setup << list_link_lib_selected.at(i).toStdString() << ' '; + } out_setup << '}' << endl; + + out_setup << "set symbol_library " << this->edit_symbol_library->text().toStdString() << '\n'; + out_setup << "set cache_write " << this->edit_cache_write->text().toStdString() << '\n'; + out_setup << "set cache_read $cache_write\n"; + + out_setup << "set my_lib_path \" ../ \\n ./ \\n"; + for (int i = 0; i < list_lib_path.size()-1; i++){ + out_setup << list_lib_path.at(i).toStdString() << " \\\t"; + } out_setup << list_lib_path.at(list_lib_path.size()-1).toStdString() << " \"" << endl; + + out_setup << "set search_path " << this->edit_search_path->text().toStdString() << '\n'; + out_setup << "suppress_message " << this->edit_suppress_message->text().toStdString() << '\n'; + out_setup << "define_design_lib DEFAULT -path " << this->edit_define_design_lib->text().toStdString() << '\n'; + out_setup << "set view_script_submenu_items " << this->edit_view_script_submenu_items->text().toStdString() << '\n'; + out_setup.close(); +} + +// 据配置文件获取工作项目配置 +void Work_Project::Get_Work_config() +{ + ifstream in("UWE_Project_config", ios::in); + string str; + in >> str >> str >> str; + in >> str >> str >> str; uwe_project_name = QString::fromStdString(str); + in >> str >> str >> str; src_project_path = QString::fromStdString(str); + in >> str >> str >> str; src_path = QString::fromStdString(str); + in >> str >> str >> str; module_name = QString::fromStdString(str); + in.close(); +} + +// 获取当前系统时间 +string get_current_date() +{ + time_t timeReal; + time(&timeReal); + timeReal = timeReal + 8*3600; + tm* t = gmtime(&timeReal); + string str = to_string(t->tm_year+1900) + '_' + to_string(t->tm_mon+1)+to_string(t->tm_mday) + '_' + to_string(t->tm_hour)+to_string(t->tm_min); + return str; +} + +// 点击 形文件列表展示文本内容 +void MainWindow::TreeClicked(const QModelIndex &index) +{ + ui->dockWidget_src_syn->show(); + QString context, file_name = model_file->fileName(index); + QString path = model_file->filePath(index); + QFile file(path); + file.open(QFile::ReadOnly | QFile::Text); + while (!file.atEnd()) { + QByteArray line = file.readLine(); + QString str(line); + context.append(str); + } + + if (!context.isEmpty()){ + QTextEdit *textEdit_src = new QTextEdit; + textEdit_src->setText(context); + textEdit_src->setFont(QFont("Consolas", 12)); + + ui->tabWidget_src_syn->addTab(textEdit_src, file_name); + ui->tabWidget_src_syn->setCurrentWidget(textEdit_src); + } + ui->dockWidget_src_syn->raise(); +} + +// 终端输出内容响应函数 +void MainWindow::readBashStandardOutputInfo() +{ + QByteArray cmdout = m_process_bash->readAllStandardOutput(); + + // 综合完成响应函数 + if (cmdout.indexOf("Thank you...") != -1){ + qDebug() << "syn sucessfully!" << endl; + QStandardItem *item = model_module->item(row_current_module_treeview, 1); + item->setIcon(style()->standardIcon(QStyle::SP_DialogApplyButton)); + } + + if (!cmdout.isEmpty()){ + ui->textEdit_cmd_syn->append(QString::fromLocal8Bit(cmdout)); + } + QScrollBar *scroll = ui->textEdit_cmd_syn->verticalScrollBar(); + scroll->setSliderPosition(scroll->maximum()); +} + + +// 终端输出错误信息响应函数 +void MainWindow::readBashStandardErrorInfo() +{ + QByteArray cmdout = m_process_bash->readAllStandardError(); + if (!cmdout.isEmpty()){ + ui->textEdit_cmd_syn->append(QString::fromLocal8Bit(cmdout)); + } + QScrollBar *scroll = ui->textEdit_cmd_syn->verticalScrollBar(); + scroll->setSliderPosition(scroll->maximum()); +} + +// 字符串变量替换 +void MainWindow::String_Replace(string &str, string variate_key) +{ + string variate_value = this->variate_map->get_value(variate_key); + int variate_size = variate_key.size(); + while (str.find(variate_key) != string::npos) + str = str.replace(str.find(variate_key), variate_size, variate_value); +} + +// 生成配置文件 +void Variate_Map::Generate_Parameter_File() +{ + ofstream out("parameter.tcl", ios::out); + for (auto i : mapper) + out << "set " << i.first << ' ' << i.second << endl; + out.close(); +} + +// 保存参数配置 +void MainWindow::on_buttonBox_Save_accepted() +{ + string FLOW_value = (ui->radioButton_FLOW_TRUE->isChecked()) ? "TRUE" : "FALSE"; + variate_map->add_variate("FLOW", FLOW_value); + string LOADDDC_value = (ui->radioButton_LOADDDC_TRUE->isChecked()) ? "TRUE" : "FALSE"; + variate_map->add_variate("LOADDDC", LOADDDC_value); + string CHECKCODE_value = (ui->radioButton_CHECKCODE_TRUE->isChecked()) ? "TRUE" : "FALSE"; + variate_map->add_variate("CHECKCODE", CHECKCODE_value); + string DEBUGSDC_value = (ui->radioButton_DEBUGSDC_TRUE->isChecked()) ? "TRUE" : "FALSE"; + variate_map->add_variate("DEBUGSDC", DEBUGSDC_value); + + variate_map->Generate_Parameter_File(); + ui->textEdit_cmd_syn->append("parameter.tcl has been generated sucessfully!\n"); +} + +// 运行综合按钮响应函数 +void MainWindow::on_pushButton_runsyn_clicked() +{ + Parameter_Config(); + + string syn_cmd = "dc_shell-t -f TCLPATH/syn_main.tcl | tee dc.log DCWORK/Logs/dc_current_date.log \nmake c_R0 \n"; + this->String_Replace(syn_cmd, "TCLPATH"); + this->String_Replace(syn_cmd, "DCWORK"); + this->String_Replace(syn_cmd, "current_date"); + cout << syn_cmd << endl; + this->ui->textEdit_cmd_syn->append("run syn \n"); + this->m_process_bash->write(syn_cmd.data()); +} + +// 代 窗口关闭响应函数 +void MainWindow::on_tabWidget_src_tabCloseRequested(int index) +{ + ui->tabWidget_src_syn->removeTab(index); +} + +// R0_check result按钮响应函数 +void MainWindow::on_pushButton_result_clicked() +{ + ktextEdit = new KTextEdit(dockWidget_report_syn); + //获取result内容 + QString result_path = QDir::currentPath() + "/R0_check.result"; + QFile file(result_path); + QString context; + file.open(QFile::ReadOnly | QFile::Text); + while (!file.atEnd()) { + QByteArray line = file.readLine(); + QString str(line); + context.append(str); + } + ktextEdit->SetText(context); + //设置文本游 到文本头 + QTextCursor cursor = ktextEdit->textCursor(); + cursor.movePosition(QTextCursor::Start); + ktextEdit->setTextCursor(cursor); + + dockWidget_report_syn->setWidget(ktextEdit); + + dockWidget_report_syn->raise(); +} + +//终端运行按钮响应函数 +void MainWindow::on_pushButton_run_cmd_clicked() +{ + QString strCmd = ui->lineEdit_syn->text(); + ui->textEdit_cmd_syn->append("Linux:~$ " + strCmd); + m_process_bash->write(ui->lineEdit_syn->text().toLocal8Bit() + '\n'); + ui->lineEdit_syn->clear(); +} + +// New nodule响应函数 +void MainWindow::New_module() +{ + QDialog *qdialog = new QDialog; + qdialog->setWindowTitle("module name"); + qdialog->setFixedSize(500, 50); + + //输入框及其按钮 + QFormLayout *layout = new QFormLayout; + layout->setRowWrapPolicy(QFormLayout::DontWrapRows); + QLineEdit *edit_module_name = new QLineEdit; + layout->addRow("module name:", edit_module_name); + + qdialog->setLayout(layout); + + //单独按钮 + QPushButton *button_determine = new QPushButton("确定", qdialog); + button_determine->move(300, 100); + + //按钮对应槽函数 + connect(button_determine, &QPushButton::clicked, qdialog, &QDialog::close); + connect(button_determine, &QPushButton::clicked, this, [=]{ + QList items; + items.append(new QStandardItem(edit_module_name->text())); +// childItem->setIcon(style()->standardIcon(QStyle::SP_DialogApplyButton)); + QStandardItem *Item_state = new QStandardItem(); + Item_state->setIcon(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion)); + items.append(Item_state); + model_module->appendRow(items); + row_current_module_treeview++; + + this->work_project->module_name = edit_module_name->text(); + ofstream out2("setModuleName.tcl", ios::out); + out2 << "set Design " << edit_module_name->text().toStdString() << "\n" << "puts ${Design}"; + out2.close(); + }); + + qdialog->exec(); +} + +// code_check响应函数 +void MainWindow::on_pushButton_code_check_clicked() +{ + string cmd_code_check_date = "c_date=`date +%Y_%m%d_%H%M` \n"; + string cmd_code_check_filelist = "echo 'Checking filelist.v ...' > code_check.result \n" + "filelistpath=`find ./src/ -name '*flist*' -type f` \n" + "echo filelistpath: $filelistpath \n" + "for file in $filelistpath; \n" + "do filelistname+=${file#*src/}' ' \n done \n" + "echo filelistname: $filelistname \n" + "if [ -z \"$filelistname\" ]; \n then echo \"Error: Filelist is not exist or the name is not matching '*_filelist' format. exit.\" " + "echo \"Error: Filelist is not exist or the name is not matching '*_filelist' format. exit.\" >> code_check.result exit \n fi \n" + "SIMEMU=`grep -n \"_SIMULATION_\|_EMULATION_\" $filelistpath` \n" + "if [ -z \"$SIMEMU\" ]; \n then echo \"Info: There are no _SIMULATION_ or _EMULATION_ definition in file $filelistname .\" \n fi \n"; + string cmd_code_check_src = "echo " " >> code_check.result \n" + "echo \"Checking 'timescale' in *.v files ... (Warning)\" >> code_check.result \n" + "find ./src/ -name \"*.v\" | xargs grep -n 'timescale' >> code_check.result \n" + "echo " " >> code_check.result \n" + "echo \"Checking Chinese words in *.v files .. (Warning).\" >> code_check.result \n" + "find ./src/ -name \"*.v\" | xargs grep -nP '[\p{Han}]' >> code_check.result \n" + "echo " " >> code_check.result \n" + "echo \"Checking Synophsis key words in *.v files ... (Info)\" >> code_check.result \n" + "find ./src/ -name \"*.v\" | xargs grep -n 'full_case' >> code_check.result \n" + "find ./src/ -name \"*.v\" | xargs grep -n 'parallel_case' >> code_check.result \n" + "find ./src/ -name \"*.v\" | xargs grep -n 'translate on' >> code_check.result \n" + "find ./src/ -name \"*.v\" | xargs grep -n 'translate off' >> code_check.result \n"; + string cmd_code_check_author = "echo " " >> code_check.result \n" + "echo \"Checking author notes in *.v files .. (Warning).\" >> code_check.result \n" + "for file in `find ./src/ -regex \".*\.vh\|.*\.v\|.*\.h\"` \n" + "do authorname=`grep -n \"author\|Author\|AUTHOR\|Generated by\|created\" $file` \n" + "if [ -z \"$authorname\" ]; \n " + "then echo \"Warning: Author notes is not exist or the name is not matching 'author|Author|AUTHOR|Generated by|created' format in file $file\" \n" + "echo \"Warning: Author notes is not exist or the name is not matching 'author|Author|AUTHOR|Generated by|created' format in file $file\" >> code_check.result \n" + "fi \n done \n"; + string cmd_code_check_xrun_log = "echo \" \" >> code_check.result \n" + "echo \"Checking NC log in xrun.log ... \" >> code_check.result \n" + "find . -maxdepth 1 -name \"xrun.log\" | xargs grep \"*E\" >> code_check.result \n" + "find . -maxdepth 1 -name \"xrun.log\" | xargs grep \"*W,RECOME\" >> code_check.result \n" + "find . -maxdepth 1 -name \"xrun.log\" | xargs grep \"*W,CUVWSP\" >> code_check.result \n" + "find . -maxdepth 1 -name \"xrun.log\" | xargs grep \"*W,CUVWSI\" >> code_check.result \n" + "find . -maxdepth 1 -name \"xrun.log\" | xargs grep \"*W,CUVMPW\" >> code_check.result \n"; + string cmd_code_check_dc_log = "echo \" \" >> code_check.result \n" + "echo \"Checking DC dc.log ...\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"Error:\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"Latch \" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"Timing loop\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"FFGEN\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"have the default net type\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"unresolved\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"unmapped\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"(LINT-5)\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"sensiti\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"MV-038\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"MV-039\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"MV-513\" >> code_check.result \n" + "find . -maxdepth 1 -name \"dc.log\" | xargs grep \"MV-514\" >> code_check.result \n"; + string cmd_code_check_copy = "cp code_check.result Logs/code_check_${c_date}.result \n"; + string cmd_code_check = cmd_code_check_date + cmd_code_check_filelist + cmd_code_check_src + cmd_code_check_author + cmd_code_check_xrun_log + cmd_code_check_dc_log + cmd_code_check_copy; + + this->ui->textEdit_cmd_syn->append("Beginning check code \n"); + + this->m_process_bash->write(cmd_code_check.data()); +} diff --git a/src/UWE_projectCode/.#mainwindow.cpp b/src/UWE_projectCode/.#mainwindow.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/UWE_projectCode/finaltest.pro b/src/UWE_projectCode/finaltest.pro new file mode 100644 index 0000000..d86d22f --- /dev/null +++ b/src/UWE_projectCode/finaltest.pro @@ -0,0 +1,49 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2022-09-13T16:59:02 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = test +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +CONFIG += c++11 + +SOURCES += \ + highlighter.cpp \ + ktextedit.cpp \ + main.cpp \ + mainwindow.cpp \ + mytreeview.cpp + + + +HEADERS += \ + highlighter.h \ + mainwindow.h \ + mytreeview.h + + + +FORMS += \ + mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/src/UWE_projectCode/finaltest.pro.user b/src/UWE_projectCode/finaltest.pro.user new file mode 100644 index 0000000..a8ba0c5 --- /dev/null +++ b/src/UWE_projectCode/finaltest.pro.user @@ -0,0 +1,326 @@ + + + + + + EnvironmentId + {a65e2026-5075-402d-8461-16bc6af287b9} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + GBK + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.12.2 GCC 64bit + Desktop Qt 5.12.2 GCC 64bit + qt.qt5.5122.gcc_64_kit + 0 + 0 + 0 + + /home/UWE/zj/Qt/Project/build-test-ZJ-Desktop_Qt_5_12_2_GCC_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/UWE/zj/Qt/Project/build-test-ZJ-Desktop_Qt_5_12_2_GCC_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/UWE/zj/Qt/Project/build-test-ZJ-Desktop_Qt_5_12_2_GCC_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + test-ZJ + + Qt4ProjectManager.Qt4RunConfiguration:/home/UWE/zj/Qt/Project/UWE/test-ZJ.pro + test-ZJ.pro + + 3768 + false + true + true + false + false + true + + /home/UWE/zj/Qt/Project/build-test-ZJ-Desktop_Qt_5_12_2_GCC_64bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 20 + + + Version + 20 + + diff --git a/src/UWE_projectCode/finddialog.cpp b/src/UWE_projectCode/finddialog.cpp new file mode 100644 index 0000000..9f96ed4 --- /dev/null +++ b/src/UWE_projectCode/finddialog.cpp @@ -0,0 +1,53 @@ +#ifndef _FINDDIALOG_H_ +#define _FINDDIALOG_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class FindDialog : public QDialog +{ + Q_OBJECT + +protected: + QGroupBox m_radioGrpBx; + + QGridLayout m_layout; + QHBoxLayout m_hbLayout; + + QLabel m_findLbl; + QLineEdit m_findEdit; + QPushButton m_findBtn; + QPushButton m_closeBtn; + QCheckBox m_matchChkBx; + QRadioButton m_forwardBtn; + QRadioButton m_backwardBtn; + + QPointer m_pText; // FindDialog ¾ÛºÏʹÓà QPlainTextEdit + QSharedPointer m_pFindDlg; + QTextCharFormat m_format; + void initControl(); + void connectSlot(); + +protected slots: + void onFindClicked(); + void onCloseClicked(); +public: + explicit FindDialog(QWidget* parent = 0, QPlainTextEdit* pText = 0); + void setPlainTextEdit(QPlainTextEdit* pText); + void highlightText(QPlainTextEdit* pText); + QPlainTextEdit* getPlainTextEdit(); + bool event(QEvent* evt); +}; + + + +#endif // _FINDDIALOG_H_ diff --git a/src/UWE_projectCode/finddialog.h b/src/UWE_projectCode/finddialog.h new file mode 100644 index 0000000..be72cf2 --- /dev/null +++ b/src/UWE_projectCode/finddialog.h @@ -0,0 +1,11 @@ +#ifndef FINDDIALOG_H +#define FINDDIALOG_H + + +class finddialog +{ +public: + finddialog(); +}; + +#endif // FINDDIALOG_H \ No newline at end of file diff --git a/src/UWE_projectCode/mytreeview.cpp b/src/UWE_projectCode/mytreeview.cpp new file mode 100644 index 0000000..7b4b0fe --- /dev/null +++ b/src/UWE_projectCode/mytreeview.cpp @@ -0,0 +1,236 @@ +#include "mytreeview.h" +#include "ui_mainwindow.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ui_mainwindow.h" + +MyTreeView::MyTreeView(QWidget *parent) + : QTreeView(parent) +{ + // 初始化 + this->model_module = new QStandardItemModel; + cnt_module = 0; + list_actionof_modules = new QList(); + map_name_2_item = new std::map(); + model_module->setHorizontalHeaderLabels(QStringList()<<"module name"<<"state"); + setModel(model_module); + setColumnWidth(0, 200); + setColumnWidth(1, 50); + setContextMenuPolicy(Qt::CustomContextMenu); + setSelectionMode(QAbstractItemView::SingleSelection); + + // actions + action_new_module1 = new QAction("new module", this); + action_new_module2 = new QAction("new module", this); + action_del_module = new QAction("del module", this); + + // menu_module_blank + menu_module_blank = new QMenu(this); + menu_module_blank->addAction(action_new_module1); + // menu_module_withmodule + menu_module_withmodule = new QMenu(this); + menu_module_withmodule->addAction(action_new_module2); + menu_module_move = menu_module_withmodule->addMenu(tr("move to")); menu_module_move->addAction(new QAction("顶层")); + menu_module_withmodule->addAction(action_del_module); + + // 空白处菜单new module信号槽 + connect(action_new_module1, &QAction::triggered, this, [=]() { + New_Module(nullptr); + }); + // 有module处菜单new module信号槽 + connect(action_new_module2, &QAction::triggered, this, [this](){ + New_Module(selecteditem); + }); + // 有module处菜单move to信号槽 + connect(menu_module_move, &QMenu::triggered, this, &MyTreeView::on_MoveMenu_Triggered); + // del module信号槽 + connect(action_del_module, &QAction::triggered, this, [this](){ + Del_Module(selecteditem); + }); +} + +// 鼠标点击treeview响应函数 +void MyTreeView::mousePressEvent(QMouseEvent *event) +{ + QPoint p = event->pos(); + QModelIndex index = indexAt(p); + QStandardItemModel *model; + if (event->buttons() & Qt::RightButton){ // 鼠标右键点击 + if (!index.isValid()){ // 点击空白处 + menu_module_blank->popup(viewport()->mapToGlobal(p)); + } + else { // 点击有module处 + menu_module_withmodule->popup(viewport()->mapToGlobal(p)); + model = qobject_cast(this->model()); + selecteditem = model->itemFromIndex(index); + } + } + if(!index.isValid()) + { + clearSelection(); //实现点空白处取消选择 +// if (father->ui->treeView_module->selectionModel()) +// father->ui->treeView_module->selectionModel()->clear(); +// emit sigPressEmpty(); +// return; + } + + QTreeView::mousePressEvent(event); +} + +// new module响应槽函数 +void MyTreeView::New_Module(QStandardItem* selecteditem) +{ + QDialog *qdialog = new QDialog; + qdialog->setWindowTitle("module name"); + qdialog->setFixedSize(500, 50); + + QFormLayout *layout = new QFormLayout; + layout->setRowWrapPolicy(QFormLayout::DontWrapRows); + QLineEdit *edit_module_name = new QLineEdit; + layout->addRow("module name:", edit_module_name); + + qdialog->setLayout(layout); + + QPushButton *button_determine = new QPushButton("确定", qdialog); + button_determine->move(300, 100); + + connect(button_determine, &QPushButton::clicked, qdialog, &QDialog::close); + connect(button_determine, &QPushButton::clicked, this, [=]{ + QString module_name = edit_module_name->text(); + QStandardItem *item_new = new QStandardItem(module_name); + QStandardItem *Item_state = new QStandardItem(); + Item_state->setIcon(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion)); + + // 直接创建new module + if (selecteditem == nullptr){ + QList items; + items.append(item_new); + items.append(Item_state); + model_module->appendRow(items); + } + // 创建子module + else{ + int row = selecteditem->rowCount(); + selecteditem->setChild(row, 0, item_new); + selecteditem->setChild(row, 1, Item_state); + } + + // 添加module信息 + map_name_2_item->insert(std::pair(module_name, item_new)); + QAction *action_tmp = new QAction(module_name, this); list_actionof_modules->append(action_tmp); + cnt_module++; + + // 更新MoveMenu菜单信息 + menu_module_move->addAction(action_tmp); + }); + + qdialog->exec(); +} + +// +QStandardItem* MyTreeView::Name_get_Item(QString name_module) +{ + std::map::iterator it = map_name_2_item->find(name_module); + if (it != map_name_2_item->end()) // 找到 + return it->second; + else // 没找到 + std::cout << "map中不存在该元素\n"; + return nullptr; +} + +// move_to菜单列表点击action响应函数 (目前还存在的bug,父项移到子项下寄) +void MyTreeView::on_MoveMenu_Triggered(QAction* action) +{ + if (action){ + QString father_item_name = action->text(); + QString selected_item_name = selecteditem->text(); + if (father_item_name == "顶层"){ // 如果移动到顶层 + if (selecteditem->parent() == nullptr) // 选中item没有父项 + return; + else{ //选中item有原父项 + QStandardItem *old_father_item = selecteditem->parent(); + QString old_father_item_name = old_father_item->text(); + // 移动(重新添加) + model_module->appendRow(old_father_item->takeRow(selecteditem->row())); + } + } + else{ // 不是移动到顶层 + // 获取父项item + QStandardItem *fatherItem = Name_get_Item(father_item_name); + if (father_item_name == selected_item_name) + return; + else{ + if (selecteditem->parent() == nullptr){ // 选中item没有父项 + // 移动(重新添加) + fatherItem->appendRow(model_module->takeRow(selecteditem->row())); + } + else{ //选中item有原父项 + QStandardItem *old_father_item = selecteditem->parent(); + QString old_father_item_name = old_father_item->text(); + if (old_father_item_name == father_item_name) // 新旧父项相同 + return; + // 移动(重新添加) + fatherItem->appendRow(old_father_item->takeRow(selecteditem->row())); + } + } + } + } +} + +// +void MyTreeView::Add_Module(QString module_name, QStandardItem* father) +{ + // 图标item + QStandardItem *Item_state = new QStandardItem(); + Item_state->setIcon(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion)); + + if (father){ + father->setChild(father->rowCount(), 0, new QStandardItem(module_name)); + father->setChild(father->rowCount(), 1, Item_state); + } + else { + QList item_row; + item_row.append(new QStandardItem(module_name)); + item_row.append(Item_state); + model_module->appendRow(item_row); + } +} + +// del module响应函数 +void MyTreeView::Del_Module(QStandardItem* selecteditem) +{ + // 在model中删除 + QStandardItem* parentItem = selecteditem->parent(); + if (parentItem){ + parentItem->removeRow(selecteditem->row()); + } + else{ + model_module->removeRow(selecteditem->row()); + } + + // 获取当前model所有module name,将不在其中的action对象删除 + QList list_del_module; + for (int i = 0; i < model_module->rowCount(); ++i) { + QStandardItem* item = model_module->item(i, 0); + if (item) { + QString text = item->text(); + list_del_module.append(text); + } + } + foreach(QAction* action, menu_module_move->actions()){ + if (!list_del_module.contains(action->text()) && action->text() != "顶层") { + menu_module_move->removeAction(action); + action->deleteLater(); // 删除该QAction对象并释放内存 + } + } +} + diff --git a/src/UWE_projectCode/mytreeview.h b/src/UWE_projectCode/mytreeview.h new file mode 100644 index 0000000..0957d9f --- /dev/null +++ b/src/UWE_projectCode/mytreeview.h @@ -0,0 +1,47 @@ +#ifndef MYTREEVIEW_H +#define MYTREEVIEW_H + +#include +#include +#include "mainwindow.h" +#include +#include + + +//改造QTreeView,实现点击空白处时取消选择 + +class MyTreeView : public QTreeView +{ + Q_OBJECT +public: + MainWindow* father = nullptr; + QStandardItemModel* model_module; // module数据模型 + QMenu *menu_module_blank, *menu_module_withmodule; // 右键菜单选项 + QAction *action_new_module1, *action_new_module2, *action_del_module, *action_move_module; // 动作 + + // 数据结构 + std::map *map_name_2_item; // module名和item对应表 + QStandardItem *selecteditem = nullptr; // 当前鼠标选中的item对象 + QList *list_actionof_modules; // module对应action列表 + int cnt_module; // module计数 + QMenu *menu_module_move; // move to菜单 + // + + MyTreeView(QWidget *parent = Q_NULLPTR); + QStandardItem* Name_get_Item(QString); + void Add_Module(QString, QStandardItem*); + +public slots: + void New_Module(QStandardItem*); + void Del_Module(QStandardItem*); + void on_MoveMenu_Triggered(QAction*); // menu按键响应槽函数 + + +signals: + void sigPressEmpty(); + +protected: + void mousePressEvent ( QMouseEvent * event ) ; +}; + +#endif