2024-05-15 08:34:54 +08:00
|
|
|
#ifndef MAINWIDGET_H
|
|
|
|
#define MAINWIDGET_H
|
|
|
|
|
2024-05-16 13:17:49 +08:00
|
|
|
#include <QAction>
|
2024-08-27 17:30:48 +08:00
|
|
|
#include <QMenu>
|
2024-05-15 13:17:24 +08:00
|
|
|
#include <QMessageBox>
|
2024-08-27 17:30:48 +08:00
|
|
|
#include <QTableWidget>
|
|
|
|
#include <QWidget>
|
2024-05-24 10:03:58 +08:00
|
|
|
#include <unordered_map>
|
2025-04-03 14:51:18 +08:00
|
|
|
#include <QHBoxLayout>
|
2024-05-15 08:34:54 +08:00
|
|
|
|
2024-09-14 00:02:48 +08:00
|
|
|
#include "conf_setting.h"
|
|
|
|
#include "src/attribute_edit.h"
|
|
|
|
#include "src/config.h"
|
|
|
|
#include "src/history.h"
|
|
|
|
#include "src/uhistory.h"
|
|
|
|
#include "src/xml_opr.h"
|
|
|
|
|
2024-05-20 23:36:44 +08:00
|
|
|
struct SElement_t {
|
2024-05-21 15:27:54 +08:00
|
|
|
SElement_t(Element_t* e, std::string& s);
|
2024-08-27 17:30:48 +08:00
|
|
|
Element_t* ele;
|
2024-05-21 15:27:54 +08:00
|
|
|
std::string str;
|
|
|
|
};
|
|
|
|
|
2024-08-27 17:30:48 +08:00
|
|
|
enum ReplaceArea {
|
|
|
|
AREA_SELECT,
|
|
|
|
AREA_ALL_PAGE,
|
|
|
|
AREA_CUR_PAGE,
|
|
|
|
AREA_ALL
|
|
|
|
};
|
2024-05-21 15:27:54 +08:00
|
|
|
|
|
|
|
struct OperElement {
|
|
|
|
OperElement(Element_t* ele, int row);
|
|
|
|
Element_t* element_{};
|
2024-08-27 17:30:48 +08:00
|
|
|
int row_{0};
|
2024-05-20 23:36:44 +08:00
|
|
|
};
|
|
|
|
|
2024-05-15 08:34:54 +08:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
namespace Ui {
|
|
|
|
class MainWidget;
|
|
|
|
}
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2024-05-24 10:03:58 +08:00
|
|
|
using ump_t = std::unordered_map<int, int>;
|
2024-05-15 08:34:54 +08:00
|
|
|
class MainWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2024-05-15 10:59:43 +08:00
|
|
|
MainWidget(QWidget* parent = nullptr);
|
2024-05-15 08:34:54 +08:00
|
|
|
~MainWidget();
|
|
|
|
|
2024-05-15 10:59:43 +08:00
|
|
|
public:
|
|
|
|
void set_work_exe(char* path);
|
|
|
|
void generate_table_widget();
|
2024-09-14 00:02:48 +08:00
|
|
|
void push_content(const std::vector<Element_t*>& eles, std::size_t page = 1,
|
|
|
|
bool auto_jump_pre = false);
|
2024-05-15 10:59:43 +08:00
|
|
|
|
|
|
|
private:
|
2024-08-27 17:30:48 +08:00
|
|
|
bool read(const QString& file_path);
|
2025-04-03 14:51:18 +08:00
|
|
|
void clear_data();
|
2024-05-21 15:27:54 +08:00
|
|
|
void search(const QString& key);
|
2024-05-15 23:55:11 +08:00
|
|
|
void item_changed_handle(QTableWidgetItem* item);
|
|
|
|
void save();
|
|
|
|
void copy_select_line();
|
|
|
|
void insert_one_line(Element_t* ele, int row);
|
|
|
|
void del_select_line();
|
|
|
|
void reset();
|
|
|
|
void judge_btn_page();
|
|
|
|
void copy_key();
|
2024-08-28 09:35:45 +08:00
|
|
|
bool edit_property(Element_t* target, int row, bool is_copy);
|
2024-05-16 13:17:49 +08:00
|
|
|
void init_menu();
|
2024-08-28 09:35:45 +08:00
|
|
|
void ele_update_gui(Element_t* target, const QString& pre_value = "");
|
2024-05-17 22:46:33 +08:00
|
|
|
void show_custom_menu();
|
2024-05-18 01:26:52 +08:00
|
|
|
void sort_by_repeat(std::vector<Element_t*>& vec);
|
2024-05-18 02:12:19 +08:00
|
|
|
void copy_multi_data();
|
2024-05-20 00:32:26 +08:00
|
|
|
void replace_content(bool is_common = true);
|
2024-05-19 23:09:01 +08:00
|
|
|
void backup_file();
|
2025-04-03 14:51:18 +08:00
|
|
|
void base_init(const QString& cur_config);
|
2024-08-27 17:30:48 +08:00
|
|
|
void unit_change();
|
2024-09-14 00:02:48 +08:00
|
|
|
bool format_xml();
|
2025-04-03 14:51:18 +08:00
|
|
|
void clear_tab_widget();
|
2024-05-16 08:04:55 +08:00
|
|
|
|
2024-08-20 16:47:09 +08:00
|
|
|
private:
|
|
|
|
std::string extract_prefix(const std::string& name);
|
|
|
|
bool compare_by_prefix(const SElement_t& se1, const SElement_t& se2);
|
|
|
|
|
2024-05-16 08:04:55 +08:00
|
|
|
protected:
|
|
|
|
void closeEvent(QCloseEvent* event);
|
2024-05-16 10:33:51 +08:00
|
|
|
void keyPressEvent(QKeyEvent* event);
|
2024-05-19 23:57:50 +08:00
|
|
|
void replace_str(const QString& pre, const QString& after, Element_t* ele);
|
2024-05-20 00:32:26 +08:00
|
|
|
void replace_str(Element_t* ele, const QString& rg, const QString& after);
|
2024-05-21 15:27:54 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void get_related_elements(std::vector<OperElement*>& out, ReplaceArea area);
|
|
|
|
|
2024-05-15 17:34:07 +08:00
|
|
|
private:
|
2024-08-27 17:30:48 +08:00
|
|
|
Element_t* get_element_by_key(const QString& key);
|
|
|
|
Element_t* get_element_by_row(int row);
|
|
|
|
Element_t* get_current_select_key();
|
2024-05-15 23:55:11 +08:00
|
|
|
QTableWidgetItem* get_current_select_item();
|
2024-05-15 17:34:07 +08:00
|
|
|
|
2024-05-24 10:03:58 +08:00
|
|
|
private:
|
2024-08-27 17:30:48 +08:00
|
|
|
std::shared_ptr<QFontMetrics> metrics_;
|
2024-05-24 10:03:58 +08:00
|
|
|
|
2024-05-15 08:34:54 +08:00
|
|
|
private:
|
2024-08-27 17:30:48 +08:00
|
|
|
QMenu* menu_simple_{};
|
|
|
|
QMenu* menu_multi_{};
|
|
|
|
QAction* ac_edit_property_{};
|
|
|
|
QAction* ac_copy_curline_{};
|
|
|
|
QAction* ac_del_curline_{};
|
|
|
|
QAction* ac_copy_key_{};
|
|
|
|
Ui::MainWidget* ui;
|
|
|
|
CXmlOpr xml_{};
|
|
|
|
std::string exe_path_{};
|
|
|
|
QTableWidget* tab_widget_{};
|
|
|
|
std::vector<Element_t*> vec_{};
|
|
|
|
std::vector<Element_t*> current_{};
|
2024-05-15 17:34:07 +08:00
|
|
|
std::vector<std::string> keys_{};
|
2024-08-27 17:30:48 +08:00
|
|
|
bool auto_add_{false};
|
|
|
|
std::size_t cur_page_{1};
|
|
|
|
std::size_t all_page_{1};
|
|
|
|
CAttributeEdit* attri_edit_{};
|
|
|
|
long allow_max_with_{500};
|
|
|
|
long blank_with_{50};
|
|
|
|
ump_t col_with_{};
|
|
|
|
CGroupSetting* group_set_{};
|
|
|
|
CGroupIni* ini_oper_{};
|
|
|
|
CHistory* his_{};
|
|
|
|
OneGroupIni cur_config_{};
|
|
|
|
bool u_{false};
|
2025-04-03 14:51:18 +08:00
|
|
|
bool alreay_open_{false};
|
|
|
|
QHBoxLayout* lay_{};
|
|
|
|
bool unit_change_auto_{true};
|
2024-05-15 08:34:54 +08:00
|
|
|
};
|
2024-05-15 10:59:43 +08:00
|
|
|
#endif // MAINWIDGET_H
|