Parcourir la source

Initial project version

lal il y a 2 ans
commit
f233e25bd7
15 fichiers modifiés avec 1689 ajouts et 0 suppressions
  1. 214 0
      custommodel.cpp
  2. 44 0
      custommodel.h
  3. 21 0
      customtreeview.cpp
  4. 20 0
      customtreeview.h
  5. 99 0
      dialog.cpp
  6. 33 0
      dialog.h
  7. 37 0
      listview_ad.cpp
  8. 26 0
      listview_ad.h
  9. 64 0
      listview_delgate.cpp
  10. 22 0
      listview_delgate.h
  11. 11 0
      main.cpp
  12. 833 0
      mainwindow.cpp
  13. 94 0
      mainwindow.h
  14. 146 0
      tool.cpp
  15. 25 0
      tool.h

+ 214 - 0
custommodel.cpp

@@ -0,0 +1,214 @@
+#include "custommodel.h"
+
+CustomModel::CustomModel(QObject* parent) : QAbstractItemModel(parent)
+{
+    // 初始化数据
+    ListItem item1;
+    item1.text = "Item 1";
+
+    ListItem item2;
+    item2.text = "Item 2";
+
+    ListItem child1;
+    child1.text = "Child 1 of Item 2";
+    item2.children.append(child1);
+    item1.children.append(child1);
+    topLevelItems.append(item1);
+    topLevelItems.append(item2);
+}
+
+CustomModel::~CustomModel()
+{
+    // 清理数据
+    topLevelItems.clear();
+}
+
+QModelIndex CustomModel::index(int row, int column, const QModelIndex& parent) const
+{
+    if (!hasIndex(row, column, parent))
+        return QModelIndex();
+
+    if (!parent.isValid())
+    {
+        // 一级列表项
+        if (row < topLevelItems.size())
+            return createIndex(row, column, &topLevelItems[row]);
+    }
+    else
+    {
+        // 二级列表项
+        ListItem* parentItem = static_cast<ListItem*>(parent.internalPointer());
+        if (row < parentItem->children.size())
+            return createIndex(row, column, &parentItem->children[row]);
+    }
+
+    return QModelIndex();
+}
+
+QModelIndex CustomModel::parent(const QModelIndex& child) const
+{
+    if (!child.isValid())
+        return QModelIndex();
+
+    ListItem* childItem = static_cast<ListItem*>(child.internalPointer());
+    if (!childItem)
+        return QModelIndex();
+
+    ListItem* parentItem = nullptr;
+
+    if (childItem != &topLevelItems[0])
+    {
+        for (const ListItem& item : topLevelItems)
+        {
+            if (item.children.contains(*childItem))
+            {
+                parentItem = const_cast<ListItem*>(&item);
+                break;
+            }
+        }
+    }
+
+    if (parentItem)
+    {
+        int row = topLevelItems.indexOf(*parentItem);
+        return createIndex(row, 0, parentItem);
+    }
+
+    return QModelIndex();
+}
+
+int CustomModel::rowCount(const QModelIndex& parent) const
+{
+    if (parent.column() > 0)
+        return 0;
+
+    if (!parent.isValid())
+    {
+        // 一级列表的行数
+        return topLevelItems.size();
+    }
+    else
+    {
+        // 二级列表的行数
+        ListItem* parentItem = static_cast<ListItem*>(parent.internalPointer());
+        if (parentItem)
+            return parentItem->children.size();
+    }
+
+    return 0;
+}
+
+int CustomModel::columnCount(const QModelIndex& parent) const
+{
+    Q_UNUSED(parent);
+    // 列数为1
+    return 1;
+}
+
+QVariant CustomModel::data(const QModelIndex& index, int role) const
+{
+    if (!index.isValid())
+        return QVariant();
+
+    if (role == Qt::DisplayRole)
+    {
+        ListItem* item = static_cast<ListItem*>(index.internalPointer());
+        if (item)
+            return item->text;
+    }
+
+    return QVariant();
+}
+
+bool CustomModel::setData(const QModelIndex& index, const QVariant& value, int role)
+{
+    if (!index.isValid())
+        return false;
+
+    if (role == Qt::EditRole)
+    {
+        ListItem* item = static_cast<ListItem*>(index.internalPointer());
+        if (item)
+        {
+            item->text = value.toString();
+            emit dataChanged(index, index);
+            return true;
+        }
+    }
+
+    return false;
+}
+
+bool CustomModel::insertTopLevelItem(int row, const ListItem& item)
+{
+    if (row < 0 || row > topLevelItems.size())
+        return false;
+    beginInsertRows(QModelIndex(), row, row);
+    topLevelItems.insert(row, item);
+    endInsertRows();
+    return true;
+
+}
+
+bool CustomModel::insertChildItem(const QModelIndex& parent, int row, const ListItem& item)
+{
+    if (!parent.isValid() || row < 0 || row > rowCount(parent))
+        return false;
+    ListItem* parentItem = static_cast<ListItem*>(parent.internalPointer());
+    if (!parentItem)
+        return false;
+
+    beginInsertRows(parent, row, row);
+    parentItem->children.insert(row, item);
+    endInsertRows();
+    return true;
+}
+
+bool CustomModel::removeTopLevelItem(int row)
+{
+    if (row < 0 || row >= topLevelItems.size())
+        return false;
+    beginRemoveRows(QModelIndex(), row, row);
+    topLevelItems.removeAt(row);
+    endRemoveRows();
+    return true;
+}
+
+bool CustomModel::removeChildItem(const QModelIndex& parent, int row)
+{
+    if (!parent.isValid() || row < 0 || row >= rowCount(parent))
+        return false;
+    ListItem* parentItem = static_cast<ListItem*>(parent.internalPointer());
+    if (!parentItem)
+        return false;
+
+    beginRemoveRows(parent, row, row);
+    parentItem->children.removeAt(row);
+    endRemoveRows();
+    return true;
+}
+
+ListItem CustomModel::getItem(const QModelIndex& index) const
+{
+    if (index.isValid())
+    {
+        ListItem* item = static_cast<ListItem*>(index.internalPointer());
+        if (item)
+            return *item;
+    }
+    return ListItem();
+}
+
+Qt::ItemFlags CustomModel::flags(const QModelIndex& index) const
+{
+    if (!index.isValid())
+        return Qt::NoItemFlags;
+
+    Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+    if (index.column() == 0)
+        flags |= Qt::ItemIsUserCheckable;
+
+    return flags;
+}
+
+

+ 44 - 0
custommodel.h

@@ -0,0 +1,44 @@
+#ifndef CUSTOMMODEL_H
+#define CUSTOMMODEL_H
+
+#include "QtWidgets/qtreeview.h"
+#include <QAbstractItemModel>
+#include <QMouseEvent>>
+struct ListItem
+{
+    QString text;  // 用于显示的文本
+    QList<ListItem> children;  // 子项列表
+    bool operator==(const ListItem& other) const
+    {
+        return text == other.text && children == other.children;
+    }
+};
+
+class CustomModel : public QAbstractItemModel
+{
+    Q_OBJECT
+
+public:
+    explicit CustomModel(QObject* parent = nullptr);
+    ~CustomModel();
+
+    // 重写必要的函数
+    QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
+    QModelIndex parent(const QModelIndex& child) const override;
+    int rowCount(const QModelIndex& parent = QModelIndex()) const override;
+    int columnCount(const QModelIndex& parent = QModelIndex()) const override;
+    QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
+    Qt::ItemFlags flags(const QModelIndex& index) const override;
+    bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
+    bool insertTopLevelItem(int row, const ListItem& item);
+    bool insertChildItem(const QModelIndex& parent, int row, const ListItem& item);
+    bool removeTopLevelItem(int row);
+    bool removeChildItem(const QModelIndex& parent, int row);
+    ListItem getItem(const QModelIndex& index) const;
+
+private:
+    // 自定义数据结构用于存储一级列表和二级列表的数据
+    QList<ListItem> topLevelItems;
+};
+
+#endif // CUSTOMMODEL_H

+ 21 - 0
customtreeview.cpp

@@ -0,0 +1,21 @@
+#include "CustomTreeView.h"
+#include <QMouseEvent>
+
+CustomTreeView::CustomTreeView(QWidget *parent)
+    : QTreeView(parent)
+{
+}
+
+void CustomTreeView::mousePressEvent(QMouseEvent *event)
+{
+    QModelIndex index = indexAt(event->pos());
+    if (index.isValid() && index.parent().isValid())
+    {
+        // 这是一个二级列表项,发射信号以处理二级列表项的点击事件
+        emit subItemClicked(index);
+    }
+    else
+    {
+        QTreeView::mousePressEvent(event);
+    }
+}

+ 20 - 0
customtreeview.h

@@ -0,0 +1,20 @@
+#ifndef CUSTOMTREEVIEW_H
+#define CUSTOMTREEVIEW_H
+
+#include <QTreeView>
+
+class CustomTreeView : public QTreeView
+{
+    Q_OBJECT
+
+public:
+    explicit CustomTreeView(QWidget *parent = nullptr);
+
+protected:
+    void mousePressEvent(QMouseEvent *event) override;
+
+signals:
+    void subItemClicked(const QModelIndex &index);
+};
+
+#endif // CUSTOMTREEVIEW_H

+ 99 - 0
dialog.cpp

@@ -0,0 +1,99 @@
+#include "dialog.h"
+#include "QtCore/qdir.h"
+#include "QtCore/qjsonarray.h"
+#include "ui_dialog.h"
+#include "QMessageBox"
+#include <QPushButton>
+Dialog::Dialog(QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::Dialog)
+{
+    ui->setupUi(this);
+}
+
+Dialog::~Dialog()
+{
+    delete ui;
+}
+
+
+
+void Dialog::addDataToJsonFile(const QString& path, const QJsonObject& newData) {
+    QString config_path=path+"/config.json";
+    QString Hotupdate_path=path+"/Hotupdate.json";
+    QFile file(config_path);
+    QJsonDocument jsonDoc(newData);
+    if (file.open(QIODevice::WriteOnly)) {
+        file.write(jsonDoc.toJson());
+        file.close();
+        qDebug() << "JSON file created successfully.";
+    } else {
+        qDebug() << "Failed to create JSON file.";
+    }
+
+
+    //创建hot
+
+    QJsonArray childrenArray;
+
+    // 创建包含 "children" 数组的 JSON 对象
+    QJsonObject jsonObject;
+    jsonObject["children"] = childrenArray;
+    QFile file1(config_path);
+    QJsonDocument jsonDoc1(jsonObject);
+    if (file1.open(QIODevice::WriteOnly)) {
+        file1.write(jsonDoc1.toJson());
+        file1.close();
+        qDebug() << "JSON file created successfully.";
+    } else {
+        qDebug() << "Failed to create JSON file.";
+    }
+
+}
+
+void Dialog::on_pushButton_clicked()
+{
+    this->close();
+}
+
+
+void Dialog::on_pushButton_2_clicked()
+{
+        // 执行相应的操作
+        QString dirPath = "~/Documents/RedInterstitialData/Hotupdate2/";
+        QJsonObject newData;
+
+        QString pro_name=ui->pro_name->toPlainText();
+        QString app_id=ui->app_id->toPlainText();
+        QString config_server_pre=ui->config_server_pre->toPlainText();
+        QString file_serverpre=ui->file_serverpre->toPlainText();
+//        if(pro_name.isEmpty())
+//        {   qDebug()<<"1111";
+//            ui->pro_name->setStyleSheet("QLineEdit{border:2px solid rgb(255, 0, 0);}");
+//            QString str = QString::fromLocal8Bit("Must Not Null");
+//            ui->pro_name->setToolTip(str);
+//            return;
+//        }
+                    if(pro_name.isEmpty()||app_id.isEmpty()||config_server_pre.isEmpty()||file_serverpre.isEmpty())
+                    {
+                        QMessageBox messageBox;
+                        messageBox.setModal(false);
+                        messageBox.setText("请将信息填写完整");
+                        messageBox.exec();
+                        return;
+                    }
+
+                    QDir dir;
+                    if (!dir.mkpath(dirPath+pro_name)) {
+                        qDebug() << "Failed to create folder";
+                    }
+        QString filePath = dirPath+pro_name;
+        newData.insert("pro_name", pro_name);
+        newData.insert("app_id", app_id);
+        newData.insert("config_server_pre", config_server_pre);
+        newData.insert("file_serverpre", file_serverpre);
+
+        addDataToJsonFile(filePath,newData);
+        this->close();
+}
+

+ 33 - 0
dialog.h

@@ -0,0 +1,33 @@
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QDialog>
+#include<QAbstractButton>
+#include <QFile>
+#include <QJsonDocument>
+#include <QJsonObject>
+namespace Ui {
+class Dialog;
+}
+
+class Dialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit Dialog(QWidget *parent = nullptr);
+    void addDataToJsonFile(const QString& filename, const QJsonObject& newData);
+    ~Dialog();
+
+private slots:
+
+    void on_pushButton_clicked();
+
+    void on_pushButton_2_clicked();
+
+private:
+    Ui::Dialog *ui;
+
+};
+
+#endif // DIALOG_H

+ 37 - 0
listview_ad.cpp

@@ -0,0 +1,37 @@
+#include "listview_ad.h"
+Listview_ad::Listview_ad(QObject *parent)
+    : QAbstractListModel(parent)
+{
+}
+
+void Listview_ad::setData(const QVariantList &data)
+{
+    beginResetModel();
+    m_data = data;
+    endResetModel();
+}
+
+int Listview_ad::rowCount(const QModelIndex &parent) const
+{
+    Q_UNUSED(parent)
+    return m_data.count();
+}
+
+QVariant Listview_ad::data(const QModelIndex &index, int role) const
+{
+    if (!index.isValid())
+        return QVariant();
+
+    if (role == Qt::DisplayRole || role == Qt::EditRole)
+        return m_data.at(index.row()).toMap()["header"];
+
+    return QVariant();
+}
+
+QHash<int, QByteArray> Listview_ad::roleNames() const
+{
+    QHash<int, QByteArray> roles;
+    roles[Qt::DisplayRole] = "display";
+    roles[Qt::EditRole] = "edit";
+    return roles;
+}

+ 26 - 0
listview_ad.h

@@ -0,0 +1,26 @@
+#ifndef LISTVIEW_AD_H
+#define LISTVIEW_AD_H
+
+
+#include <QAbstractListModel>
+#include <QVariantList>
+
+class Listview_ad : public QAbstractListModel
+{
+    Q_OBJECT
+
+public:
+    explicit Listview_ad(QObject *parent = nullptr);
+
+    void setData(const QVariantList &data);
+
+    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+    QHash<int, QByteArray> roleNames() const override;
+
+private:
+    QVariantList m_data;
+};
+
+
+#endif // LISTVIEW_AD_H

+ 64 - 0
listview_delgate.cpp

@@ -0,0 +1,64 @@
+#include "Listview_delgate.h"
+
+#include <QComboBox>
+#include <QStyledItemDelegate>
+#include <QPainter>
+Listview_delgate::Listview_delgate(QObject *parent)
+    : QStyledItemDelegate(parent)
+{
+}
+
+QWidget *Listview_delgate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+    Q_UNUSED(option)
+
+    if (!index.isValid())
+        return nullptr;
+
+    QComboBox *editor = new QComboBox(parent);
+    editor->setModel(index.model()->data(index, Qt::EditRole).value<QAbstractListModel*>());
+
+    return editor;
+}
+
+void Listview_delgate::setEditorData(QWidget *editor, const QModelIndex &index) const
+{
+    if (!index.isValid())
+        return;
+
+    QComboBox *comboBox = qobject_cast<QComboBox*>(editor);
+    if (comboBox)
+    {
+        QString currentText = index.model()->data(index, Qt::EditRole).toString();
+        int currentIndex = comboBox->findText(currentText);
+        comboBox->setCurrentIndex(currentIndex);
+    }
+}
+
+void Listview_delgate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
+{
+    if (!index.isValid())
+        return;
+
+    QComboBox *comboBox = qobject_cast<QComboBox*>(editor);
+    if (comboBox)
+    {
+        QString selectedText = comboBox->currentText();
+        model->setData(index, selectedText, Qt::EditRole);
+    }
+}
+void Listview_delgate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+    QStyledItemDelegate::paint(painter, option, index);
+
+    if (index.parent().isValid())
+    {
+        // 设置字体颜色为白色
+        painter->setPen(Qt::white);
+
+        // 绘制文本
+        QString text = index.data(Qt::DisplayRole).toString();
+        painter->drawText(option.rect, Qt::AlignLeft | Qt::AlignVCenter, text);
+    }
+}
+

+ 22 - 0
listview_delgate.h

@@ -0,0 +1,22 @@
+#ifndef LISTVIEW_DELGATE_H
+#define LISTVIEW_DELGATE_H
+
+
+#include <QStyledItemDelegate>
+
+    class Listview_delgate : public QStyledItemDelegate
+{
+    Q_OBJECT
+
+public:
+    Listview_delgate(QObject *parent = nullptr);
+
+    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
+    void setEditorData(QWidget *editor, const QModelIndex &index) const override;
+    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
+    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
+
+};
+
+
+#endif // LISTVIEW_DELGATE_H

+ 11 - 0
main.cpp

@@ -0,0 +1,11 @@
+#include "mainwindow.h"
+
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+    MainWindow w;
+    w.show();
+    return a.exec();
+}

+ 833 - 0
mainwindow.cpp

@@ -0,0 +1,833 @@
+#include "mainwindow.h"
+#include "custommodel.h"
+#include "ui_mainwindow.h"
+#include "listview_ad.h"
+#include "listview_delgate.h"
+#include <QStandardItemModel>
+#include"../sample_button_slide/CustomButton.h"
+#include"../test_drag/mylistwidget.h"
+#include <QDir>
+#include <QFile>
+#include <QTextStream>
+#include <iostream>
+#include <QMimeData>
+using namespace std;
+MainWindow::MainWindow(QWidget *parent)
+    : QMainWindow(parent)
+    , ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+    //add_slide;
+    QWidget *slide_2= ui->slide_2; // 获取ceshi_2_slide控件指针
+    customB2 = new CustomButton(this); // 创建自定义控件实例
+    connect(customB2, &CustomButton::click, this, &MainWindow::onWidgetClicked);
+    // 将自定义控件添加到ceshi_2_slide控件中
+    QHBoxLayout *layout2 = new QHBoxLayout(slide_2);
+    layout2->setContentsMargins(0, 0, 0, 0);
+    layout2->addWidget(customB2);
+    layout2->setSpacing(0);
+
+    //add_slide;
+    QWidget *slide_3= ui->slide_3; // 获取ceshi_2_slide控件指针
+    customB3 = new CustomButton(this); // 创建自定义控件实例
+    connect(customB3, &CustomButton::click, this, &MainWindow::onWidgetClicked);
+    // 将自定义控件添加到ceshi_2_slide控件中
+    QHBoxLayout *layout3 = new QHBoxLayout(slide_3);
+    layout3->setContentsMargins(0, 0, 0, 0);
+    layout3->addWidget(customB3);
+    layout3->setSpacing(0);
+
+    //add_slide;
+    QWidget *slide_4= ui->slide_4; // 获取ceshi_2_slide控件指针
+    customB4 = new CustomButton(this); // 创建自定义控件实例
+    connect(customB4, &CustomButton::click, this, &MainWindow::onWidgetClicked);
+    // 将自定义控件添加到ceshi_2_slide控件中
+    QHBoxLayout *layout4 = new QHBoxLayout(slide_4);
+    layout4->setContentsMargins(0, 0, 0, 0);
+    layout4->addWidget(customB4);
+    layout4->setSpacing(0);
+
+
+    //初始化右侧u
+//    MyListWidget* my1=new MyListWidget();
+//    QVBoxLayout *layout5 = new QVBoxLayout();
+//    layout5->addWidget(my1);
+//    ui->test_frame->setLayout(layout5);
+//    connect(my1, &MyListWidget::operationCompleted, this, &MainWindow::handleOperationCompleted);
+
+        my1=new MyListWidget();
+        my1->setObjectName("listWidget");
+        QVBoxLayout *layout5 = new QVBoxLayout();
+        layout5->addWidget(my1);
+        ui->frame->setLayout(layout5);
+        qDebug()<<"widget_group"<<ui->widget_group1;
+        connect(my1, &MyListWidget::operationCompleted, this, &MainWindow::handleOperationCompleted);
+        connect(my1, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_listWidget_customContextMenuRequested(QPoint)));
+        my2=new MyListWidget();
+        my2->setObjectName("listWidget_2");
+        QVBoxLayout *layout6 = new QVBoxLayout();
+        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)));
+        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)));
+        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)));
+
+    QString folder = "/users/lal/documents/RedInterstitialData/HotUpdate2";
+    root_pro_path=folder;
+    qDebug()<<folder;
+    QStringList qs=tool::getFilesInFolder(folder);//获取项目名称列表
+    qDebug()<<qs;
+    //初始化comboBox
+    initComboBox(qs);
+    QString currentPro = ui->comboBox->currentText();
+
+
+
+
+
+    //初始化TreeView
+    QString jsonPath = folder+"/"+currentPro+"/"+"Hotupdate.json";
+    qDebug()<<jsonPath;
+    QJO=tool::readJsonFile(jsonPath);
+    // 从JSON对象中提取数据
+    QJA = QJO.value("children").toArray();
+
+    ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
+    connect(ui->treeView, &QTreeView::customContextMenuRequested, this, &MainWindow::slotTreeMenu);
+    //初始化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;
+
+    //初始化右边
+//    initRight(QString parentNode,QString childNode);
+}
+
+
+void QTreeView::mousePressEvent(QMouseEvent *event)
+{
+    QModelIndex index = indexAt(event->pos());
+    if (index.isValid() && index.parent().isValid())
+    {
+        // 这是一个二级列表项,你可以在这里处理点击事件
+        // 例如,获取二级列表项的数据并进行相应的操作
+        QVariant data = index.data(Qt::DisplayRole);
+        qDebug() << "Clicked on subitem:" << data.toString();
+    }
+    else
+    {
+        qDebug() << "Clicked on subitem false";
+        QTreeView::mousePressEvent(event);
+    }
+}
+
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+
+
+void MainWindow::readFile(const QString& filePath)//设置打开该窗体时检查路径并加载
+{
+    // 获取文件所在路径
+    QString dirPath = QFileInfo(filePath).absolutePath();
+    qDebug() << dirPath;
+    // 创建路径
+    QDir dir;
+    if (!dir.mkpath(dirPath))
+    {
+        qDebug() << "无法创建路径:" << dirPath;
+        return;
+    }
+
+    // 创建文件
+    QFile file(filePath);
+    if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
+    {
+        qDebug() << "无法创建文件:" << file.errorString();
+                                               return;
+    }
+
+    // 使用QTextStream读取文件内容
+    QTextStream in(&file);
+    while (!in.atEnd())
+    {
+        QString line = in.readLine();
+        // 处理每一行的内容
+        // TODO: 添加您的逻辑
+        qDebug() << line;
+    }
+
+    // 关闭文件
+    file.close();
+}
+
+
+void MainWindow::on_pushButton_clicked()
+{
+    dialog=new Dialog(this);
+    dialog->setModal(false);
+    dialog->show();
+}
+
+
+void MainWindow::on_pushButton_2_clicked()
+{
+    dialog=new Dialog(this);
+    dialog->setModal(false);
+    dialog->show();
+}
+
+QJsonObject MainWindow::readJsonFile(const QString& filePath)
+{
+    // 打开JSON文件
+    QFile file(filePath);
+    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+    {
+        qDebug() << "无法打开文件:" << file.errorString();
+                                        return QJsonObject();
+    }
+
+    // 读取文件内容
+    QByteArray jsonData = file.readAll();
+    file.close();
+
+    // 解析JSON数据
+    QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
+    if (!jsonDoc.isObject())
+    {
+        qDebug() << "无效的JSON文件";
+        return QJsonObject();;
+    }
+
+    // 获取JSON对象
+    QJsonObject jsonObj = jsonDoc.object();
+
+
+
+    return jsonObj;
+
+    // 处理其他字段...
+}
+
+void MainWindow::init()
+{
+    QString filePath = "~/Documents/RedInterstitialData/Hotupdate.tool/Hotupdate1.json";
+
+
+
+    QJA=tool::getJsanArra(filePath);
+    // 从JSON对象中提取数据
+    int num=QJA.count();
+        qDebug() << num;
+    QStringList pro_list;
+    for(int i=1;i<=num;i++)
+    {
+        pro_list.append(QString::number(i));
+    }
+    ui->comboBox->clear();
+    ui->comboBox->addItems(pro_list);
+
+    ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
+    connect(ui->treeView, &QTreeView::customContextMenuRequested, this, &MainWindow::slotTreeMenu);
+    //初始化当前窗口
+    int index=ui->comboBox->currentData().toString().toInt();
+    inittreeview(QJA[index]);
+
+}
+
+void MainWindow::init2()
+{
+//    QString filePath = "~/Documents/RedInterstitialData/Hotupdate2/Hotupdate2.json";
+//    QString folder = "~/Documents/RedInterstitialData/Hotupdate2";
+//    tool::generateFolderJsonFile(folder,filePath);
+//    QString jsonPath = "~/Documents/RedInterstitialData/Hotupdate2/Hotupdate2.json";
+
+
+
+//    QJO=tool::readJsonFile(jsonPath);
+//    // 从JSON对象中提取数据
+//    QJA = QJO.value("children").toArray();
+//    ui->comboBox->clear();
+
+//    ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
+//    connect(ui->treeView, &QTreeView::customContextMenuRequested, this, &MainWindow::slotTreeMenu);
+//    //初始化treeview 和 combobox
+//    QTreeView *treeView=ui->treeView;
+//    QStandardItemModel* model=new QStandardItemModel(treeView);
+//    model->setHorizontalHeaderLabels(QStringList()<<QStringLiteral("名称"));
+//    treeView->setModel(model);
+//    QStringList pro_list;
+
+//    ui->comboBox->clear();
+//    pro_list=initializeTreeView_conboBox(model->invisibleRootItem(),QJA);
+//    ui->comboBox->addItems(pro_list);
+
+
+}
+
+
+//初始化treeview 和combobox控件
+void MainWindow::initTreeView(QStandardItem* parentItem,const QJsonArray& jsonArray) {
+    QStringList pro_list;
+    for (QJsonArray::const_iterator it = jsonArray.constBegin(); it != jsonArray.constEnd(); ++it) {
+        QJsonValue jsonValue = *it;
+        qDebug()<<jsonValue;
+        // 处理每个元素,可以根据需要进行类型检查和值提取
+        if (jsonValue.isString()) {
+            QString fileName = jsonValue.toString();
+            QStandardItem* item = new QStandardItem(fileName);
+//            if(!fileName.endsWith("json"))
+//                parentItem->appendRow(item);
+            // 处理字符串值 s
+        } else if (jsonValue.isDouble()) {
+            double doubleValue = jsonValue.toDouble();
+            // 处理双精度浮点数值
+        } else if (jsonValue.isObject()) {
+            QJsonObject objectValue = jsonValue.toObject();
+            QString name = objectValue["name"].toString();
+            QStandardItem* item = new QStandardItem(name);
+            parentItem->appendRow(item);
+
+            QJsonArray childrenArray = objectValue["children"].toArray();
+            pro_list.append(name);
+            // 处理对象值
+            initTreeView(item, childrenArray);
+        }
+    }
+
+}
+
+
+
+void MainWindow::inittreeview(QJsonValueRef ref)
+{
+    //1,构造Model,这里示例具有3层关系的model构造过程
+    QStandardItemModel* model = new QStandardItemModel(ui->treeView);
+    model->setHorizontalHeaderLabels(QStringList()<<QStringLiteral("序号") << QStringLiteral("名称"));     //设置列头
+    for(int i=0;i<5;i++)
+    {
+        //一级节点,加入mModel
+        QList<QStandardItem*> items1;
+        QStandardItem* item1 = new QStandardItem(QString::number(i));
+        QStandardItem* item2 = new QStandardItem(QStringLiteral("一级节点"));
+        items1.append(item1);
+        items1.append(item2);
+        model->appendRow(items1);
+
+        for(int j=0;j<5;j++)
+        {
+            //二级节点,加入第1个一级节点
+            QList<QStandardItem*> items2;
+            QStandardItem* item3 = new QStandardItem(QString::number(j));
+            QStandardItem* item4 = new QStandardItem(QStringLiteral("二级节点"));
+            items2.append(item3);
+            items2.append(item4);
+            item1->appendRow(items2);
+        }
+    }
+    //2,给QTreeView应用model
+    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);
+    }
+}
+//删除设定为假删除,在窗体退出的时候才更新json文件,并执行删除操作
+/////////到这里
+/// ///
+/// ////
+/// ///
+/// //
+/// //
+/// /
+///
+/// //
+void MainWindow::slotTreeMenuDelete(bool checked)
+{
+    QModelIndex curIndex = ui->treeView->currentIndex();
+    QModelIndex index = curIndex.sibling(curIndex.row(),0); //同一行第一列元素的index
+    qDebug()<<curIndex;
+    qDebug()<<index;
+}
+
+void MainWindow::initComboBox(QStringList qs){
+
+    ui->comboBox->clear();
+    ui->comboBox->addItems(qs);
+}
+
+void MainWindow::initRight(QString parentNode,QString childNode){
+    //
+    QString folder = "/users/lal/documents/RedInterstitialData/HotUpdate2";
+    QString currentPro = ui->comboBox->currentText();
+    config_json_path=folder+"/"+currentPro+"/"+parentNode+"/"+childNode+"/config.json";
+    treeview_path=folder+"/"+currentPro+"/"+parentNode+"/"+childNode;
+    qDebug()<<config_json_path;
+    qDebug()<<treeview_path;
+    RQJA=tool::getJsanArra(config_json_path);
+    for (int i = 0; i < RQJA.size(); ++i) {
+        QJsonValueRef value = RQJA[i];
+        QJsonObject jsonObject = value.toObject();
+        QJsonValue jsonArrayValue = jsonObject.value("children");
+        QJsonValue  Used=jsonObject.value("selected");
+        QString used=Used.toString();
+        QJsonArray jsonArray = jsonArrayValue.toArray();
+        qDebug()<<jsonArray.size();
+        CustomButton* temb=nullptr;
+            QListWidget* rightLw;
+            if(i==0)
+            {
+                rightLw=my1;
+            }
+            else if(i==1)
+            {
+                temb=customB2;
+                rightLw=my2;
+            }
+            else if(i==2)
+            {
+                temb=customB3;
+                rightLw=my3;
+            }
+            else{
+                temb=customB4;
+                rightLw=my4;
+            }
+        if(used=="1"&&temb)
+        {
+                if(temb->dir==Qt::AlignLeft){
+                    temb->pos_right_button();
+                }
+        }
+        if(used=="0"&&temb)
+        {
+                if(temb->dir==Qt::AlignRight){
+                    temb->pos_left_button();
+                }
+        }
+        initRightListwidget(rightLw,jsonArray);
+
+    }
+
+}
+
+void MainWindow::on_treeView_clicked(const QModelIndex &index)
+{
+    // 获取第一级节点的信息
+    if(index.parent().isValid())
+    {
+        QModelIndex parentIndex = index.parent();
+        QString parentData = parentIndex.data().toString();
+        qDebug() << "First-level Node: " << parentData;
+
+        // 获取第二级节点的信息
+        QString childData = index.data().toString();
+        qDebug() << "Second-level Node: " << childData;
+        initRight(parentData,childData);
+
+    }
+
+
+}
+
+void MainWindow::initRightListwidget(QListWidget* qw,const QJsonArray& qja)
+{
+    QStringList dataList;
+    for (const QJsonValue& value : qja) {
+        if (value.isString()) {
+            QString stringValue = value.toString();
+            dataList.append(stringValue);
+        }
+    }
+    qDebug()<<"initRightListwidget";
+    qDebug()<<"dataList"<<dataList;
+    qDebug()<<"qw"<<qw;
+    qw->clear();
+    qw->addItems(dataList);
+}
+
+
+
+
+
+/////////////////////////////////////////////////////////////////////////////////////////////右侧右击事件
+void MainWindow::on_listWidget_customContextMenuRequested(const QPoint &pos)
+{
+    qDebug()<<"1111111";
+    QListWidgetItem* curItem = my1->itemAt( pos );
+    if( curItem == NULL )
+        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 );
+    this->qlw=my1;
+    connect( deleteSeed, SIGNAL(triggered() ), this, SLOT( deleteSeedSlot()) );
+    popMenu->exec( QCursor::pos() );
+    delete popMenu;
+    delete deleteSeed;
+}
+void MainWindow::on_listWidget_2_customContextMenuRequested(const QPoint &pos)
+{
+    QListWidgetItem* curItem = my2->itemAt( pos );
+    if( curItem == NULL )
+        return;
+
+    QMenu *popMenu = new QMenu( this );
+    QAction *deleteSeed = new QAction(tr("Delete"), this);
+    popMenu->addAction( deleteSeed );
+    this->qlw=my2;
+    connect( deleteSeed, SIGNAL(triggered() ), this, SLOT( deleteSeedSlot()));
+    popMenu->exec( QCursor::pos() );
+    delete popMenu;
+    delete deleteSeed;
+}
+/////daozheer 可以删除项 还没有修改json文件
+void MainWindow::deleteSeedSlot()
+{
+    qDebug()<<"deleteSeedSlot";
+    QListWidgetItem * item = this->qlw->currentItem();
+    qDebug()<<this->qlw;
+    if( item == NULL )
+        return;
+
+    int curIndex = this->qlw->row(item);
+    qDebug()<<curIndex;
+    auto curItem=this->qlw->takeItem(curIndex);
+    qDebug()<<curItem->text();
+
+//    updateConfig(ui->listWidget);//更新对应的config.json文件
+    QString deal_file_path;
+    QString group_name;
+    int group_index;
+    if(qlw->objectName()=="listWidget")
+    {
+        group_name="group1";
+        group_index=0;
+    }
+    else if(qlw->objectName()=="listWidget_2")
+    {
+        group_name="group2";
+        group_index=1;
+    }
+    else if(qlw->objectName()=="listWidget_3")
+    {
+        group_name="group3";
+        group_index=2;
+    }
+    else
+    {
+        group_name="group4";
+        group_index=3;
+    }
+    deal_file_path=treeview_path+"/"+group_name+"/"+curItem->text();
+    QFile file(deal_file_path);
+    file.remove();
+    QJsonObject groupObject = RQJA[group_index].toObject();
+    QJsonArray childrenArray = groupObject["children"].toArray();
+    childrenArray.removeAt(curIndex);
+    groupObject["children"] = childrenArray;
+    RQJA[group_index] = groupObject;
+    writeBackToConfigJson();
+    delete item;
+
+}
+
+
+
+
+
+void MainWindow::on_listWidget_3_customContextMenuRequested(const QPoint &pos)
+{
+    QListWidgetItem* curItem = my3->itemAt( pos );
+    if( curItem == NULL )
+        return;
+
+    QMenu *popMenu = new QMenu( this );
+    QAction *deleteSeed = new QAction(tr("Delete"), this);
+    popMenu->addAction( deleteSeed );
+    this->qlw=my3;
+    connect( deleteSeed, SIGNAL(triggered() ), this, SLOT( deleteSeedSlot()) );
+    popMenu->exec( QCursor::pos() );
+    delete popMenu;
+    delete deleteSeed;
+}
+
+
+void MainWindow::on_listWidget_4_customContextMenuRequested(const QPoint &pos)
+{
+    QListWidgetItem* curItem = my4->itemAt( pos );
+    if( curItem == NULL )
+        return;
+
+    QMenu *popMenu = new QMenu( this );
+    QAction *deleteSeed = new QAction(tr("Delete"), this);
+    popMenu->addAction( deleteSeed );
+    this->qlw=my4;
+    connect( deleteSeed, SIGNAL(triggered() ), this, SLOT( deleteSeedSlot()) );
+    popMenu->exec( QCursor::pos() );
+    delete popMenu;
+    delete deleteSeed;
+}
+/////////////////////////////////////////////////////////////////////////////////////////////右侧右击事件
+
+
+
+//滑块点击slot函数
+void MainWindow::onWidgetClicked()
+{
+    QObject *senderObj = sender(); // 获取发出信号的对象指针
+    if(RQJA.empty())return;
+
+    if (senderObj)
+    {
+        QWidget *clickedWidget = qobject_cast<QWidget*>(senderObj); // 将指针转换为QWidget指针
+        if (clickedWidget)
+        {
+            QString widgetName = clickedWidget->parentWidget()->objectName(); // 获取控件的对象名称
+            if(widgetName=="slide_2")
+            {
+                    if(customB2->dir==Qt::AlignLeft)
+                    {
+                        //变为1
+                        QJsonValueRef selectedValueRef = RQJA[1].toObject()["selected"];
+                        selectedValueRef = "1";
+                        qDebug()<<RQJA;
+                    }
+                    else{
+                        //变为0
+                        QJsonValueRef selectedValueRef = RQJA[1].toObject()["selected"];
+                        selectedValueRef = "0";
+                        qDebug()<<RQJA;
+                    }
+            }
+            else if(widgetName=="slide_3")
+            {
+                    if(customB3->dir==Qt::AlignLeft)
+                    {
+                        //变为1
+                        QJsonValueRef selectedValueRef = RQJA[2].toObject()["selected"];
+                        selectedValueRef = "1";
+                        qDebug()<<RQJA;
+                    }
+                    else{
+                        //变为0
+                        QJsonValueRef selectedValueRef = RQJA[2].toObject()["selected"];
+                        selectedValueRef = "0";
+                        qDebug()<<RQJA;
+                    }
+            }
+            else
+            {
+                    if(customB4->dir==Qt::AlignLeft)
+                    {
+                        //变为1
+                        QJsonValueRef selectedValueRef = RQJA[3].toObject()["selected"];
+                        selectedValueRef = "1";
+                        qDebug()<<RQJA;
+                    }
+                    else{
+                        //变为0
+                        QJsonValueRef selectedValueRef = RQJA[3].toObject()["selected"];
+                        selectedValueRef = "0";
+                        qDebug()<<RQJA;
+                    }
+            }
+            writeBackToConfigJson();
+        }
+    }
+}
+//修改config文件
+void MainWindow::writeBackToConfigJson(){
+    if(!config_json_path.endsWith("json"))return;
+    qDebug()<<config_json_path;
+    QFile jsonFile(config_json_path);
+    if (jsonFile.open(QIODevice::WriteOnly)) {
+        QJsonDocument jsonDoc(RQJA);
+        QByteArray jsonData = jsonDoc.toJson();
+        qint64 bytesWritten = jsonFile.write(jsonData);
+        if (bytesWritten == -1) {
+            qDebug() << "Failed to write data to file.";
+        } else {
+            qDebug() << "Data written to file successfully.";
+        }
+        jsonFile.close();
+    } else {
+        qDebug() << "Failed to open file for writing.";
+    }
+}
+//重新选择项目进行初始化
+void MainWindow::on_comboBox_currentTextChanged(const QString &arg1)
+{
+    clearRight();
+    QString folder = "/users/lal/documents/RedInterstitialData/HotUpdate2";
+    QString currentPro = ui->comboBox->currentText();
+    //初始化TreeView
+    QString jsonPath = folder+"/"+currentPro+"/"+"Hotupdate.json";
+    QJO=tool::readJsonFile(jsonPath);
+    // 从JSON对象中提取数据
+    QJA = QJO.value("children").toArray();
+
+    ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
+    connect(ui->treeView, &QTreeView::customContextMenuRequested, this, &MainWindow::slotTreeMenu);
+    //初始化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;
+
+}
+
+void MainWindow::clearRight()
+{
+    my1->clear();
+    my2->clear();
+    my3->clear();
+    my4->clear();
+    this->customB2->pos_left_button();
+    this->customB3->pos_left_button();
+    this->customB4->pos_left_button();
+}
+
+
+void MainWindow::handleOperationCompleted(QString fromfilePath)
+{
+
+    QStringList parts = fromfilePath.split("/");
+    QObject *senderObj = sender();
+    QListWidget *LW = qobject_cast<QListWidget*>(senderObj);
+    //QString tofilePath1 = "/Users/lal/QT_pro/build-test_tool1-Qt_6_3_1_for_macOS-Debug/test_tool1.app/Contents/MacOS/~/Documents/RedInterstitialData/HotUpdate2/pro2/tes1/version1/group3";
+
+
+    QString group_name;
+    int group_index;
+    if(LW->objectName()=="listWidget")
+    {
+        group_name="group1";
+        group_index=0;
+    }
+    else if(LW->objectName()=="listWidget_2")
+    {
+        group_name="group2";
+        group_index=1;
+    }
+    else if(LW->objectName()=="listWidget_3")
+    {
+        group_name="group3";
+        group_index=2;
+    }
+    else
+    {
+        group_name="group4";
+        group_index=3;
+    }
+    QString tofilePath1 = treeview_path+"/"+group_name;
+
+
+    QFile sourceFile(fromfilePath);
+    QFile targetFile(tofilePath1 + "/" +parts[parts.size()-1]);
+    if (sourceFile.exists() && QDir(tofilePath1).exists()) {
+        if (sourceFile.copy(targetFile.fileName())) {
+            qDebug() << "File copied successfully.";
+            LW->addItem(parts[parts.size()-1]);
+            qDebug()<<this->parent();
+            QJsonObject groupObject = RQJA[group_index].toObject();
+            QJsonArray childrenArray = groupObject["children"].toArray();
+            childrenArray.append(parts[parts.size()-1]);
+            groupObject["children"] = childrenArray;
+            RQJA[group_index] = groupObject;
+            writeBackToConfigJson();
+
+        } else {
+            qDebug() << "Failed to copy file.";
+            QMessageBox::information(this, "失败", "文件名重复");
+        }
+    } else {
+        qDebug() << "Source file or target folder does not exist.";
+    }
+}

+ 94 - 0
mainwindow.h

@@ -0,0 +1,94 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include "QtGui/qstandarditemmodel.h"
+#include "QtWidgets/qlistview.h"
+#include "QtWidgets/qlistwidget.h"
+#include "dialog.h"
+#include <QMainWindow>
+#include <QDir>
+#include <QFile>
+#include <QTextStream>
+#include <QFile>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonArray>
+#include <QDebug>
+#include"../sample_button_slide/CustomButton.h"
+#include"../test_drag/mylistwidget.h"
+#include "tool.h"
+QT_BEGIN_NAMESPACE
+namespace Ui { class MainWindow; }
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    MainWindow(QWidget *parent = nullptr);
+
+    ~MainWindow();
+
+
+private:
+    Ui::MainWindow *ui;
+    Dialog *dialog;
+    QJsonArray QJA;//保存了左侧树的结构  QJA QJsonArray([{"children":[{"name":"version1"},{"name":"version2"},{"name":"version3"}],"name":"tes1"},{"children":[],"name":"tet2"}])
+    QJsonArray RQJA;//保存右侧的分组的结构
+    QListWidget* qlw;
+    QJsonObject QJO;
+    CustomButton* customB2;
+    CustomButton* customB3;
+    CustomButton* customB4;
+
+
+    MyListWidget* my1;
+    MyListWidget* my2;
+    MyListWidget* my3;
+    MyListWidget* my4;
+
+
+    QString config_json_path;
+    QString treeview_path;
+    QString root_pro_path;
+    void add_slide();
+    void readFile(const QString& filePath);
+    QJsonObject readJsonFile(const QString& filePath);
+    void init();
+    void inittreeview(QJsonValueRef qvr);
+    void init2();
+    void initTreeView(QStandardItem* parentItem,const QJsonArray& jsonArray);
+    void initComboBox(QStringList jsonPath);
+    void initRight(QString parentNode,QString childNode);
+    void initRightListwidget(QListWidget* qv,const QJsonArray& qja);
+    void updateConfig(QListWidget* qw);
+    void writeBackToConfigJson();
+    void clearRight();
+private slots:
+
+
+    void on_pushButton_clicked();
+    void on_pushButton_2_clicked();
+    void on_pushButton_4_clicked();
+
+    void slotTreeMenu(const QPoint &pos);
+    void slotTreeMenuExpand(bool checked = false);
+    void slotTreeMenuCollapse(bool checked = false);
+    void slotTreeMenuDelete(bool checked = false);
+
+
+    void on_treeView_clicked(const QModelIndex &index);
+    void on_listWidget_customContextMenuRequested(const QPoint &pos);
+    void deleteSeedSlot();
+    void on_listWidget_2_customContextMenuRequested(const QPoint &pos);
+    void on_listWidget_3_customContextMenuRequested(const QPoint &pos);
+    void on_listWidget_4_customContextMenuRequested(const QPoint &pos);
+
+    void onWidgetClicked();
+    void on_comboBox_currentTextChanged(const QString &arg1);
+    void handleOperationCompleted(QString fromfilePath);
+
+
+};
+#endif // MAINWINDOW_H

+ 146 - 0
tool.cpp

@@ -0,0 +1,146 @@
+#include "tool.h"
+#include "QtCore/qdir.h"
+
+#include <QDirIterator>
+
+const QString tool::dir_path="/users/lal/documents/RedInterstitialData/HotUpdate2";
+QJsonObject tool::generateFolderJson(const QString& folderPath) {
+//    QDir folderDir(folderPath);
+//    QJsonObject folderObject;
+//    folderObject["name"] = folderDir.dirName();
+
+//    QJsonArray childrenArray;
+
+//    // 遍历文件夹中的子项,包括子文件夹和文件
+//    QDir::Filters filters = QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot;
+//    QDirIterator it(folderPath, filters, QDirIterator::Subdirectories);
+//    while (it.hasNext()) {
+//        it.next();
+
+//        // 如果是文件夹,递归生成 JSON 数据并添加到子项中
+//        if (it.fileInfo().isDir()) {
+//            qDebug()<<it.filePath();
+//            QJsonObject childObject = generateFolderJson(it.filePath());
+//            childrenArray.append(childObject);
+//        }
+
+//        // 如果是文件,直接将文件名添加到子项中
+//        else {
+//            QString fileName = it.fileName();
+//            childrenArray.append(fileName);
+//        }
+//    }
+
+//    folderObject["children"] = childrenArray;
+//    return folderObject;
+    QDir folderDir(folderPath);
+    QJsonObject folderObject;
+    folderObject["name"] = folderDir.dirName();
+
+    QJsonArray childrenArray;
+
+    // 遍历文件夹中的子项,包括子文件夹和文件
+    QDir::Filters filters = QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot;
+    QStringList entries = folderDir.entryList(filters);
+    for (const QString& entry : entries) {
+        QString entryPath = folderDir.filePath(entry);
+        QFileInfo fileInfo(entryPath);
+        if (fileInfo.exists() && fileInfo.isDir())
+        {
+            childrenArray.append(generateFolderJson(entryPath));
+        }
+
+        else childrenArray.append(entry);
+    }
+
+    folderObject["children"] = childrenArray;
+    return folderObject;
+}
+
+// 生成文件夹的 JSON 文件
+void tool::generateFolderJsonFile(const QString& folderPath, const QString& jsonFilePath) {
+    QJsonObject rootObject = tool::generateFolderJson(folderPath);
+
+    QJsonDocument jsonDoc(rootObject);
+    QByteArray jsonData = jsonDoc.toJson(QJsonDocument::Indented);
+
+    QFile jsonFile(jsonFilePath);
+    if (jsonFile.open(QIODevice::WriteOnly)) {
+        jsonFile.write(jsonData);
+        jsonFile.close();
+        qDebug() << "JSON file generated successfully.";
+    } else {
+        qDebug() << "Failed to generate JSON file.";
+    }
+}
+
+
+//获取文件json数据
+QJsonArray tool::getJsanArra(const QString& filePath){
+    QFile file(filePath);
+    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+        // 处理文件打开错误
+        return QJsonArray();
+    }
+
+    // 解析原始 JSON 文件内容
+    QByteArray fileData = file.readAll();
+    QJsonDocument jsonDoc = QJsonDocument::fromJson(fileData);
+    file.close();
+    QJsonArray json=jsonDoc.array();
+    return json;
+}
+QJsonObject tool::readJsonFile(const QString& filePath)
+{
+    // 打开JSON文件
+    QFile file(filePath);
+    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+    {
+        qDebug() << "无法打开文件:" << file.errorString();
+                                        return QJsonObject();
+    }
+
+    // 读取文件内容
+    QByteArray jsonData = file.readAll();
+    file.close();
+
+    // 解析JSON数据
+    QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
+    if (!jsonDoc.isObject())
+    {
+        qDebug() << "无效的JSON文件";
+        return QJsonObject();;
+    }
+
+    // 获取JSON对象
+    QJsonObject jsonObj = jsonDoc.object();
+
+
+
+    return jsonObj;
+
+    // 处理其他字段...
+}
+QStringList tool::getFilesInFolder(const QString& folderPath)
+{
+    QDir folderDir(folderPath);
+
+    QStringList fileList;
+
+    // 获取文件夹中的所有文件
+    QStringList nameFilters;
+
+    QDir::Filters filters = QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot;
+    QStringList entries = folderDir.entryList(filters);
+    qDebug()<<"entries "<<entries;
+    for (const QString& entry : entries) {
+        QString entryPath = folderDir.filePath(entry);
+        QFileInfo fileInfo(entryPath);
+        if (fileInfo.exists() && fileInfo.isDir())
+        {
+            fileList.append(fileInfo.fileName());
+        }
+    }
+
+    return fileList;
+}

+ 25 - 0
tool.h

@@ -0,0 +1,25 @@
+#ifndef TOOL_H
+#define TOOL_H
+
+#include <QDialog>
+#include<QAbstractButton>
+#include <QFile>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include "QtCore/qjsonarray.h"
+class tool
+{
+public:
+    static QJsonArray getJsanArra(const QString& filePath);
+    static void generateFolderJsonFile(const QString& folderPath, const QString& jsonFilePath);
+    static QJsonObject generateFolderJson(const QString& folderPath);
+    static QJsonObject readJsonFile(const QString& filePath);
+    static QStringList getFilesInFolder(const QString& folderPath);
+    static const QString dir_path;
+    tool(){}
+private:
+
+
+};
+
+#endif // TOOL_H