#ifndef MAINWIDGET_H #define MAINWIDGET_H #include #include #include #include #include #include #include #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" struct SElement_t { SElement_t(Element_t* e, std::string& s); Element_t* ele; std::string str; }; enum ReplaceArea { AREA_SELECT, AREA_ALL_PAGE, AREA_CUR_PAGE, AREA_ALL }; struct OperElement { OperElement(Element_t* ele, int row); Element_t* element_{}; int row_{0}; }; QT_BEGIN_NAMESPACE namespace Ui { class MainWidget; } QT_END_NAMESPACE using ump_t = std::unordered_map; class MainWidget : public QWidget { Q_OBJECT public: MainWidget(QWidget* parent = nullptr); ~MainWidget(); public: void set_work_exe(char* path); void generate_table_widget(); void push_content(const std::vector& eles, std::size_t page = 1, bool auto_jump_pre = false); private: bool read(const QString& file_path); void clear_data(); void search(const QString& key); 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(); bool edit_property(Element_t* target, int row, bool is_copy); void init_menu(); void ele_update_gui(Element_t* target, const QString& pre_value = ""); void show_custom_menu(); void sort_by_repeat(std::vector& vec); void copy_multi_data(); void replace_content(bool is_common = true); void backup_file(); void base_init(const QString& cur_config); void unit_change(); bool format_xml(); void clear_tab_widget(); private: std::string extract_prefix(const std::string& name); bool compare_by_prefix(const SElement_t& se1, const SElement_t& se2); protected: void closeEvent(QCloseEvent* event); void keyPressEvent(QKeyEvent* event); void replace_str(const QString& pre, const QString& after, Element_t* ele); void replace_str(Element_t* ele, const QString& rg, const QString& after); private: void get_related_elements(std::vector& out, ReplaceArea area); private: Element_t* get_element_by_key(const QString& key); Element_t* get_element_by_row(int row); Element_t* get_current_select_key(); QTableWidgetItem* get_current_select_item(); private: std::shared_ptr metrics_; private: 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 vec_{}; std::vector current_{}; std::vector keys_{}; 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}; bool alreay_open_{false}; QHBoxLayout* lay_{}; bool unit_change_auto_{true}; }; #endif // MAINWIDGET_H