|
@@ -70,21 +70,21 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
layout6->addWidget(my2);
|
|
|
ui->frame_4->setLayout(layout6);
|
|
|
connect(my2, &MyListWidget::operationCompleted, this, &MainWindow::handleOperationCompleted);
|
|
|
- connect(my2, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_listWidget_customContextMenuRequested(QPoint)));
|
|
|
+ connect(my2, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_listWidget_2_customContextMenuRequested(QPoint)));
|
|
|
my3=new MyListWidget();
|
|
|
my3->setObjectName("listWidget_3");
|
|
|
QVBoxLayout *layout7 = new QVBoxLayout();
|
|
|
layout7->addWidget(my3);
|
|
|
ui->frame_5->setLayout(layout7);
|
|
|
connect(my3, &MyListWidget::operationCompleted, this, &MainWindow::handleOperationCompleted);
|
|
|
- connect(my3, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_listWidget_customContextMenuRequested(QPoint)));
|
|
|
+ connect(my3, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_listWidget_3_customContextMenuRequested(QPoint)));
|
|
|
my4=new MyListWidget();
|
|
|
my4->setObjectName("listWidget_4");
|
|
|
QVBoxLayout *layout8 = new QVBoxLayout();
|
|
|
layout8->addWidget(my4);
|
|
|
ui->frame_6->setLayout(layout8);
|
|
|
connect(my4, &MyListWidget::operationCompleted, this, &MainWindow::handleOperationCompleted);
|
|
|
- connect(my4, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_listWidget_customContextMenuRequested(QPoint)));
|
|
|
+ connect(my4, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_listWidget_4_customContextMenuRequested(QPoint)));
|
|
|
|
|
|
QString folder = "/users/lal/documents/RedInterstitialData/HotUpdate2";
|
|
|
root_pro_path=folder;
|
|
@@ -106,15 +106,21 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
// 从JSON对象中提取数据
|
|
|
QJA = QJO.value("children").toArray();
|
|
|
|
|
|
+
|
|
|
+ ////////////////////////////////////////////////
|
|
|
ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
- connect(ui->treeView, &QTreeView::customContextMenuRequested, this, &MainWindow::slotTreeMenu);
|
|
|
+ connect(ui->treeView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotTreeMenu(QPoint)));
|
|
|
+
|
|
|
+
|
|
|
//初始化treeview 和 combobox
|
|
|
QTreeView *treeView=ui->treeView;
|
|
|
+
|
|
|
QStandardItemModel* model=new QStandardItemModel(treeView);
|
|
|
model->setHorizontalHeaderLabels(QStringList()<<QStringLiteral("名称"));
|
|
|
treeView->setModel(model);
|
|
|
|
|
|
initTreeView(model->invisibleRootItem(),QJA);
|
|
|
+
|
|
|
qDebug()<<"QJA"<<QJA;
|
|
|
|
|
|
//初始化右边
|
|
@@ -315,6 +321,8 @@ void MainWindow::initTreeView(QStandardItem* parentItem,const QJsonArray& jsonAr
|
|
|
initTreeView(item, childrenArray);
|
|
|
}
|
|
|
}
|
|
|
+ ui->treeView->clearSelection();
|
|
|
+ ui->treeView->setCurrentIndex(QModelIndex());
|
|
|
|
|
|
}
|
|
|
|
|
@@ -350,63 +358,27 @@ void MainWindow::inittreeview(QJsonValueRef ref)
|
|
|
ui->treeView->setModel(model);
|
|
|
}
|
|
|
|
|
|
-void MainWindow::on_pushButton_4_clicked()
|
|
|
-{
|
|
|
- QList<QStandardItem*> items1;
|
|
|
- QStandardItemModel *model1 = static_cast<QStandardItemModel*>(ui->treeView->model());
|
|
|
- QStandardItem* item2 = new QStandardItem(QStringLiteral("新建测试"));
|
|
|
- items1.append(item2);
|
|
|
- model1->appendRow(items1);
|
|
|
-
|
|
|
|
|
|
|
|
|
-}
|
|
|
-
|
|
|
void MainWindow::slotTreeMenu(const QPoint &pos)
|
|
|
{
|
|
|
- QString qss = "QMenu{color:#E8E8E8;background:#4D4D4D;margin:2px;}\
|
|
|
- QMenu::item{padding:3px 20px 3px 20px;}\
|
|
|
- QMenu::indicator{width:13px;height:13px;}\
|
|
|
- QMenu::item:selected{color:#E8E8E8;border:0px solid #575757;background:#1E90FF;}\
|
|
|
- QMenu::separator{height:1px;background:#757575;}";
|
|
|
-
|
|
|
- QMenu menu;
|
|
|
- menu.setStyleSheet(qss); //可以给菜单设置样式
|
|
|
-
|
|
|
- QModelIndex curIndex = ui->treeView->indexAt(pos); //当前点击的元素的index
|
|
|
- QModelIndex index = curIndex.sibling(curIndex.row(),0); //该行的第1列元素的index
|
|
|
- if (index.isValid())
|
|
|
- {
|
|
|
- //可获取元素的文本、data,进行其他判断处理
|
|
|
- //QStandardItem* item = mModel->itemFromIndex(index);
|
|
|
- //QString text = item->text();
|
|
|
- //QVariant data = item->data(Qt::UserRole + 1);
|
|
|
- //...
|
|
|
-
|
|
|
- //添加一行菜单,进行展开
|
|
|
- menu.addAction(QStringLiteral("删除"), this, SLOT(slotTreeMenuDelete(bool)));
|
|
|
- }
|
|
|
- menu.exec(QCursor::pos()); //显示菜单
|
|
|
-}
|
|
|
-
|
|
|
-void MainWindow::slotTreeMenuExpand(bool checked)
|
|
|
-{
|
|
|
- QModelIndex curIndex = ui->treeView->currentIndex();
|
|
|
- QModelIndex index = curIndex.sibling(curIndex.row(),0); //同一行第一列元素的index
|
|
|
- if(index.isValid())
|
|
|
- {
|
|
|
- ui->treeView->expand(index);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void MainWindow::slotTreeMenuCollapse(bool checked)
|
|
|
-{
|
|
|
- QModelIndex curIndex = ui->treeView->currentIndex();
|
|
|
- QModelIndex index = curIndex.sibling(curIndex.row(),0); //同一行第一列元素的index
|
|
|
- if(index.isValid())
|
|
|
- {
|
|
|
- ui->treeView->collapse(index);
|
|
|
- }
|
|
|
+// QModelIndex curItem = ui->treeView->indexAt( pos );
|
|
|
+// QModelIndex index = curItem.sibling(curItem.row(),0);
|
|
|
+// if( !index.isValid() )
|
|
|
+// return;
|
|
|
+
|
|
|
+// QMenu *popMenu = new QMenu( this );
|
|
|
+// QAction *deleteSeed = new QAction(tr("Delete"), this);
|
|
|
+// QString qss = "QMenu{color:#E8E8E8;background:#4D4D4D;margin:2px;}\
|
|
|
+// QMenu::item{padding:3px 20px 3px 20px;}\
|
|
|
+// QMenu::indicator{width:13px;height:13px;}\
|
|
|
+// QMenu::item:selected{color:#E8E8E8;border:0px solid #575757;background:#1E90FF;}\
|
|
|
+// QMenu::separator{height:1px;background:#757575;}";
|
|
|
+// popMenu->setStyleSheet(qss);
|
|
|
+// popMenu->addAction( deleteSeed );
|
|
|
+// connect( deleteSeed, SIGNAL(triggered() ), this, SLOT( slotTreeMenuDelete()) );
|
|
|
+// popMenu->exec( QCursor::pos() );
|
|
|
+// delete popMenu;
|
|
|
}
|
|
|
//删除设定为假删除,在窗体退出的时候才更新json文件,并执行删除操作
|
|
|
/////////到这里
|
|
@@ -418,12 +390,17 @@ void MainWindow::slotTreeMenuCollapse(bool checked)
|
|
|
/// /
|
|
|
///
|
|
|
/// //
|
|
|
-void MainWindow::slotTreeMenuDelete(bool checked)
|
|
|
+void MainWindow::slotTreeMenuDelete()
|
|
|
{
|
|
|
- QModelIndex curIndex = ui->treeView->currentIndex();
|
|
|
- QModelIndex index = curIndex.sibling(curIndex.row(),0); //同一行第一列元素的index
|
|
|
- qDebug()<<curIndex;
|
|
|
- qDebug()<<index;
|
|
|
+
|
|
|
+// QModelIndex curIndex = ui->treeView->currentIndex();
|
|
|
+// QModelIndex index = curIndex.sibling(curIndex.row(),0); //同一行第一列元素的index
|
|
|
+// qDebug()<<curIndex;
|
|
|
+// qDebug()<<index;
|
|
|
+// QStandardItemModel* model = dynamic_cast<QStandardItemModel*>(ui->treeView->model());
|
|
|
+// model->removeRow(index.row(), index.parent());
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void MainWindow::initComboBox(QStringList qs){
|
|
@@ -500,12 +477,37 @@ void MainWindow::on_treeView_clicked(const QModelIndex &index)
|
|
|
QString childData = index.data().toString();
|
|
|
qDebug() << "Second-level Node: " << childData;
|
|
|
initRight(parentData,childData);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
+void MainWindow::mousePressEvent(QMouseEvent* event)
|
|
|
+{
|
|
|
+// // 调用基类的函数处理其他的鼠标点击事件
|
|
|
+// QMainWindow::mousePressEvent(event);
|
|
|
+
|
|
|
+
|
|
|
+// // 检查点击的位置是否在 treeView 的边界内
|
|
|
+// if(ui->treeView->rect().contains(event->pos()))
|
|
|
+// {
|
|
|
+// // 转换全局坐标为 treeView 的本地坐标
|
|
|
+// QPoint treeViewPos = ui->treeView->mapFromGlobal(event->globalPos());
|
|
|
+// // 检查是否有节点在点击的位置
|
|
|
+// if(!ui->treeView->indexAt(treeViewPos).isValid())
|
|
|
+// {
|
|
|
+// // 在这里执行你的操作...
|
|
|
+// qDebug() << "点击了 treeView 的空白部分";
|
|
|
+// ui->treeView->clearSelection();
|
|
|
+// ui->treeView->setCurrentIndex(QModelIndex());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// ui->treeView->clearSelection();
|
|
|
+// ui->treeView->setCurrentIndex(QModelIndex());
|
|
|
+// }
|
|
|
+}
|
|
|
+
|
|
|
void MainWindow::initRightListwidget(QListWidget* qw,const QJsonArray& qja)
|
|
|
{
|
|
|
QStringList dataList;
|
|
@@ -831,3 +833,328 @@ void MainWindow::handleOperationCompleted(QString fromfilePath)
|
|
|
qDebug() << "Source file or target folder does not exist.";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+void MainWindow::on_pushButton_4_clicked()
|
|
|
+{
|
|
|
+ QList<QStandardItem*> items1;
|
|
|
+ QStandardItemModel *model1 = static_cast<QStandardItemModel*>(ui->treeView->model());
|
|
|
+ // QStandardItem* item2 = new QStandardItem(QStringLiteral("新建测试"));
|
|
|
+ QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
|
+ QString currentDateTimeString = currentDateTime.toString("yyyy-MM-dd hh:mm:ss");
|
|
|
+ QStandardItem* item2 = new QStandardItem(currentDateTimeString);
|
|
|
+ QString add_Path=root_pro_path+"/"+ui->comboBox->currentText();
|
|
|
+ QDir dir;
|
|
|
+ if (!dir.exists(add_Path+"/"+currentDateTimeString)) {
|
|
|
+ if (dir.mkpath(add_Path+"/"+currentDateTimeString)) {
|
|
|
+ qDebug() << "Folder created successfully.";
|
|
|
+ QString filePath = add_Path+"/"+"Hotupdate.json";
|
|
|
+
|
|
|
+ QFile file(filePath);
|
|
|
+ if (!file.open(QIODevice::ReadOnly))
|
|
|
+ {
|
|
|
+ QString errorString = file.errorString();
|
|
|
+ qDebug() << "Failed to open file: " << errorString;
|
|
|
+ // 其他错误处理逻辑
|
|
|
+ }
|
|
|
+ QByteArray jsonData = file.readAll();
|
|
|
+
|
|
|
+ file.close();
|
|
|
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
|
|
+ if (jsonDoc.isNull()) {
|
|
|
+ qDebug() << "Failed to parse JSON data.";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将 JSON 数据转换为对象
|
|
|
+ QJsonObject jsonObj = jsonDoc.object();
|
|
|
+
|
|
|
+ // 使用 jsonObj 进行进一步操作,例如读取特定的键值对
|
|
|
+ QJsonObject newQ;
|
|
|
+ QJsonArray newA;
|
|
|
+ newQ.insert("children",newA);
|
|
|
+ newQ.insert("name",currentDateTimeString);
|
|
|
+ QJsonArray qaa=jsonObj["children"].toArray();
|
|
|
+ qaa.append(newQ);
|
|
|
+ jsonObj["children"]=qaa;
|
|
|
+ tool::writeJsonFile(filePath,jsonObj);
|
|
|
+ items1.append(item2);
|
|
|
+ model1->appendRow(items1);
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ qDebug() << "Failed to create folder.";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ qDebug() << "Folder already exists.";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_pushButton_5_clicked()
|
|
|
+{
|
|
|
+ // 获取选择模型
|
|
|
+ QItemSelectionModel* selectionModel = ui->treeView->selectionModel();
|
|
|
+ if (selectionModel)
|
|
|
+ {
|
|
|
+ // 获取当前选中的节点的索引
|
|
|
+ QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
|
|
|
+ QModelIndex parentIndex = selectedIndexes.first().parent();
|
|
|
+ if(parentIndex.isValid())
|
|
|
+ {
|
|
|
+ QMessageBox::information(this, "提示", "请选中一级节点");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 遍历选中的索引列表
|
|
|
+ foreach (const QModelIndex& index, selectedIndexes)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ // 打印选中节点的数据
|
|
|
+ QVariant data = index.data(Qt::DisplayRole);
|
|
|
+
|
|
|
+ qDebug() << "Selected Node Data: " << data.toString();
|
|
|
+ QString add_Path=root_pro_path+"/"+ui->comboBox->currentText()+"/"+data.toString();
|
|
|
+ QString modify_pro_config = root_pro_path+"/"+ui->comboBox->currentText()+"/"+"Hotupdate.json";
|
|
|
+ //直接对新增的版本添加config.json group1 group2 group3 group4
|
|
|
+ qDebug()<<add_Path;
|
|
|
+ QDir folder(add_Path);
|
|
|
+ QStringList subFolders = folder.entryList(QDir::Dirs | QDir::NoDotAndDotDot); // 获取文件夹列表
|
|
|
+ QString folderCount = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); // 文件夹数目
|
|
|
+
|
|
|
+ qDebug() << "Number of sub-folders: " << folderCount;
|
|
|
+ //新建版本
|
|
|
+ QDir dir;
|
|
|
+ QString version_path=add_Path+"/"+"version"+folderCount;
|
|
|
+ dir.mkpath(version_path);
|
|
|
+ //新建版本下的子文件夹等
|
|
|
+ dir.mkpath(version_path+"/"+"group1");
|
|
|
+ dir.mkpath(version_path+"/"+"group2");
|
|
|
+ dir.mkpath(version_path+"/"+"group3");
|
|
|
+ dir.mkpath(version_path+"/"+"group4");
|
|
|
+ QString filePath = version_path+"/"+"config.json"; // 指定新文件的路径和名称
|
|
|
+
|
|
|
+ QJsonArray jsonArray;
|
|
|
+ for(int i=0;i<4;i++)
|
|
|
+ {
|
|
|
+ // add obj
|
|
|
+ QJsonObject object1;
|
|
|
+ QJsonArray children1;
|
|
|
+
|
|
|
+ object1["children"] = children1;
|
|
|
+ object1["selected"] = "0";
|
|
|
+ jsonArray.append(object1);
|
|
|
+
|
|
|
+ }
|
|
|
+ QFile file(filePath);
|
|
|
+ if (file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
|
+ {
|
|
|
+ QJsonDocument jsonDocument(jsonArray);
|
|
|
+ QString jsonString = jsonDocument.toJson();
|
|
|
+
|
|
|
+ QTextStream stream(&file);
|
|
|
+ stream << jsonString; // 将JSON文本写入文件
|
|
|
+
|
|
|
+ file.close();
|
|
|
+ qDebug() << "File written successfully!";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ qDebug() << "Failed to write the file!";
|
|
|
+ }
|
|
|
+ //修改项目根json文件 modify_pro_config
|
|
|
+ //folderCount
|
|
|
+ qDebug()<<index.row();
|
|
|
+ QFile file1(modify_pro_config);
|
|
|
+ if (!file1.open(QIODevice::ReadOnly))
|
|
|
+ {
|
|
|
+ QString errorString = file1.errorString();
|
|
|
+ qDebug() << "Failed to open file: " << errorString;
|
|
|
+ // 其他错误处理逻辑
|
|
|
+ }
|
|
|
+ QByteArray jsonData = file1.readAll();
|
|
|
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
|
|
+ if (jsonDoc.isNull()) {
|
|
|
+ qDebug() << "Failed to parse JSON data.";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 将 JSON 数据转换为对象
|
|
|
+ QJsonObject jsonObj = jsonDoc.object();
|
|
|
+ QJsonArray parentArray = jsonObj["children"].toArray();
|
|
|
+ QJsonObject childObject = parentArray[index.row()].toObject();
|
|
|
+ QJsonArray nestedArray = childObject["children"].toArray();
|
|
|
+// {
|
|
|
+// "name": "version1"
|
|
|
+// }
|
|
|
+ QJsonObject temo1;
|
|
|
+ temo1["name"]="version" + folderCount;
|
|
|
+ nestedArray.append(temo1);
|
|
|
+
|
|
|
+ childObject["children"] = nestedArray;
|
|
|
+ parentArray[index.row()] = childObject;
|
|
|
+ jsonObj["children"] = parentArray;
|
|
|
+ qDebug() << "Modified QJsonObject:" << jsonObj;
|
|
|
+ tool::writeJsonFile(modify_pro_config,jsonObj);
|
|
|
+ //
|
|
|
+
|
|
|
+ QStandardItemModel* model = dynamic_cast<QStandardItemModel*>(ui->treeView->model());
|
|
|
+
|
|
|
+ if (model) {
|
|
|
+ QStandardItem* parentItem = model->itemFromIndex(index);
|
|
|
+
|
|
|
+ if (parentItem) {
|
|
|
+ QStandardItem* childItem = new QStandardItem("version"+folderCount);
|
|
|
+ parentItem->appendRow(childItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void MainWindow::on_comboBox_customContextMenuRequested(const QPoint &pos)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void MainWindow::on_pushButton_9_clicked()
|
|
|
+{
|
|
|
+
|
|
|
+// qDebug()<<ui->treeView->currentIndex();
|
|
|
+// 获取被选中的节点
|
|
|
+ QModelIndex selectedIndex = ui->treeView->currentIndex();
|
|
|
+ if(!selectedIndex.isValid())
|
|
|
+ {
|
|
|
+ // 如果没有选中任何节点,则弹出提示框
|
|
|
+ QMessageBox::information(this, "提示", "没有选中任何节点");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查选中的节点是一级节点还是二级节点
|
|
|
+ if(selectedIndex.parent().isValid())
|
|
|
+ {
|
|
|
+ // 如果选中的节点有父节点,那么它是二级节点
|
|
|
+ // 在这里执行二级节点对应的代码...
|
|
|
+ QMessageBox::StandardButton reply;
|
|
|
+ reply = QMessageBox::question(this, "Test", "确定要删除"+selectedIndex.data().toString(),
|
|
|
+ QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
|
|
|
+
|
|
|
+ if (reply == QMessageBox::Yes) {
|
|
|
+ qDebug() << "Yes was clicked";
|
|
|
+ qDebug() << "选中的是二级节点";
|
|
|
+ QModelIndex parentIndex = selectedIndex.parent();
|
|
|
+ QString del_Path=root_pro_path+"/"+ui->comboBox->currentText()+"/"+parentIndex.data().toString()+"/"+selectedIndex.data().toString();
|
|
|
+ QString modify_pro_config = root_pro_path+"/"+ui->comboBox->currentText()+"/"+"Hotupdate.json";
|
|
|
+ //删除文件夹
|
|
|
+ QDir dir(del_Path);
|
|
|
+ dir.removeRecursively();
|
|
|
+ //修改json文件
|
|
|
+ QFile file1(modify_pro_config);
|
|
|
+ if (!file1.open(QIODevice::ReadOnly))
|
|
|
+ {
|
|
|
+ QString errorString = file1.errorString();
|
|
|
+ qDebug() << "Failed to open file: " << errorString;
|
|
|
+ // 其他错误处理逻辑
|
|
|
+ }
|
|
|
+ QByteArray jsonData = file1.readAll();
|
|
|
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
|
|
+ if (jsonDoc.isNull()) {
|
|
|
+ qDebug() << "Failed to parse JSON data.";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 将 JSON 数据转换为对象
|
|
|
+ QJsonObject jsonObj = jsonDoc.object();
|
|
|
+ QJsonArray parentArray = jsonObj["children"].toArray();
|
|
|
+ QJsonObject childObject = parentArray[parentIndex.row()].toObject();
|
|
|
+ QJsonArray nestedArray = childObject["children"].toArray();
|
|
|
+
|
|
|
+ nestedArray.removeAt(selectedIndex.row());
|
|
|
+
|
|
|
+
|
|
|
+ childObject["children"] = nestedArray;
|
|
|
+ parentArray[parentIndex.row()] = childObject;
|
|
|
+ jsonObj["children"] = parentArray;
|
|
|
+ qDebug() << "Modified QJsonObject:" << jsonObj;
|
|
|
+ tool::writeJsonFile(modify_pro_config,jsonObj);
|
|
|
+
|
|
|
+ QStandardItemModel* model = dynamic_cast<QStandardItemModel*>(ui->treeView->model());
|
|
|
+
|
|
|
+ if (model) {
|
|
|
+ QStandardItem* parentItem = model->itemFromIndex(parentIndex);
|
|
|
+
|
|
|
+ if (parentItem) {
|
|
|
+ parentItem->removeRow(selectedIndex.row());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (reply == QMessageBox::No) {
|
|
|
+ qDebug() << "No was clicked";
|
|
|
+ } else {
|
|
|
+ qDebug() << "Cancel was clicked";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // 如果选中的节点没有父节点,那么它是一级节点
|
|
|
+ // 在这里执行一级节点对应的代码...
|
|
|
+ QMessageBox::StandardButton reply;
|
|
|
+ reply = QMessageBox::question(this, "Test", "确定要删除"+selectedIndex.data().toString(),
|
|
|
+ QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
|
|
|
+
|
|
|
+ if (reply == QMessageBox::Yes) {
|
|
|
+ qDebug() << "Yes was clicked";
|
|
|
+ qDebug() << "选中的是一级节点";
|
|
|
+ QString del_Path=root_pro_path+"/"+ui->comboBox->currentText()+"/"+selectedIndex.data().toString();
|
|
|
+ QString modify_pro_config = root_pro_path+"/"+ui->comboBox->currentText()+"/"+"Hotupdate.json";
|
|
|
+ //删除文件夹
|
|
|
+ QDir dir(del_Path);
|
|
|
+ dir.removeRecursively();
|
|
|
+ //修改json文件
|
|
|
+ QFile file1(modify_pro_config);
|
|
|
+ if (!file1.open(QIODevice::ReadOnly))
|
|
|
+ {
|
|
|
+ QString errorString = file1.errorString();
|
|
|
+ qDebug() << "Failed to open file: " << errorString;
|
|
|
+ // 其他错误处理逻辑
|
|
|
+ }
|
|
|
+ QByteArray jsonData = file1.readAll();
|
|
|
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
|
|
+ if (jsonDoc.isNull()) {
|
|
|
+ qDebug() << "Failed to parse JSON data.";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 将 JSON 数据转换为对象
|
|
|
+ QJsonObject jsonObj = jsonDoc.object();
|
|
|
+ QJsonArray parentArray = jsonObj["children"].toArray();
|
|
|
+
|
|
|
+
|
|
|
+ parentArray.removeAt(selectedIndex.row());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ jsonObj["children"] = parentArray;
|
|
|
+ qDebug() << "Modified QJsonObject:" << jsonObj;
|
|
|
+ tool::writeJsonFile(modify_pro_config,jsonObj);
|
|
|
+
|
|
|
+ QStandardItemModel* model = dynamic_cast<QStandardItemModel*>(ui->treeView->model());
|
|
|
+ model->removeRow(selectedIndex.row());
|
|
|
+
|
|
|
+
|
|
|
+ } else if (reply == QMessageBox::No) {
|
|
|
+ qDebug() << "No was clicked";
|
|
|
+ } else {
|
|
|
+ qDebug() << "Cancel was clicked";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|