change:格式化xml单元设定一个窗口,可以选择性格式化哪些具体内容。
This commit is contained in:
@@ -10,7 +10,7 @@ void QCustomQLineEdit::dragEnterEvent(QDragEnterEvent* event)
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
QLineEdit::dragEnterEvent(event);
|
||||
//QLineEdit::dragEnterEvent(event);
|
||||
}
|
||||
|
||||
void QCustomQLineEdit::dragMoveEvent(QDragMoveEvent* event)
|
||||
@@ -28,7 +28,7 @@ void QCustomQLineEdit::dropEvent(QDropEvent* event)
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
QLineEdit::dropEvent(event);
|
||||
//QLineEdit::dropEvent(event);
|
||||
}
|
||||
|
||||
QCustomQLineEdit::~QCustomQLineEdit()
|
||||
|
||||
@@ -262,14 +262,33 @@ bool CXmlOpr::import_newer_data(const std::vector<std::string>& vec,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
std::string CXmlOpr::handle_space(const std::string& content)
|
||||
std::string CXmlOpr::handle_space(const std::string& content,
|
||||
const std::vector<std::string>& keychars)
|
||||
{
|
||||
std::string result;
|
||||
size_t pos = 0;
|
||||
size_t len = content.length();
|
||||
|
||||
std::ostringstream oss;
|
||||
for (auto i = size_t(0); i < keychars.size(); ++i) {
|
||||
if (i > 0) {
|
||||
oss << "|";
|
||||
}
|
||||
std::string op(keychars[i]);
|
||||
for (const char& c : op) {
|
||||
if (c == '|' || c == '\\' || c == '(' || c == ')' || c == '[' ||
|
||||
c == ']' || c == '{' || c == '}' || c == '^' || c == '$' ||
|
||||
c == '.' || c == '*' || c == '+' || c == '?' || c == '|' ||
|
||||
c == '\\') {
|
||||
oss << '\\'; // 添加转义字符
|
||||
}
|
||||
oss << c;
|
||||
}
|
||||
}
|
||||
|
||||
// Define a regular expression for the operators
|
||||
std::regex operators_regex(R"(&&|!=|==|<|>|\|\||\+|-|\*|/)");
|
||||
// std::regex operators_regex(R"(&&|!=|==|<|>|\|\||\+|-|\*|/)");
|
||||
std::regex operators_regex(oss.str());
|
||||
|
||||
while (pos < len) {
|
||||
size_t start_quote = content.find('"', pos);
|
||||
@@ -316,7 +335,8 @@ std::string CXmlOpr::handle_space(const std::string& content)
|
||||
|
||||
return result;
|
||||
}
|
||||
bool CXmlOpr::handle_transfer(const std::string& path)
|
||||
bool CXmlOpr::handle_transfer(const std::string& path,
|
||||
const std::vector<std::string>& keychars)
|
||||
{
|
||||
std::ifstream file(path);
|
||||
if (!file.is_open()) {
|
||||
@@ -361,13 +381,18 @@ bool CXmlOpr::handle_transfer(const std::string& path)
|
||||
pos += 1; // Move past the replaced character
|
||||
}
|
||||
|
||||
// 处理空格格式化
|
||||
std::string sec_handle = handle_space(result);
|
||||
std::ofstream ofile(path);
|
||||
if (!ofile.is_open()) {
|
||||
return false;
|
||||
}
|
||||
ofile << sec_handle;
|
||||
|
||||
if (keychars.size() < 1) {
|
||||
ofile << result;
|
||||
} else {
|
||||
// 处理空格格式化
|
||||
std::string sec_handle = handle_space(result, keychars);
|
||||
ofile << sec_handle;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -410,7 +435,8 @@ bool CXmlOpr::save()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CXmlOpr::handle_save(const std::string& path)
|
||||
bool CXmlOpr::handle_save(const std::string& path,
|
||||
const std::vector<std::string>& keychars)
|
||||
{
|
||||
if (!open(path)) {
|
||||
return false;
|
||||
@@ -419,7 +445,7 @@ bool CXmlOpr::handle_save(const std::string& path)
|
||||
if (ret != tinyxml2::XML_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
if (!handle_transfer(xml_path_)) {
|
||||
if (!handle_transfer(xml_path_, keychars)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -37,8 +37,8 @@ public:
|
||||
bool check_key_exists(const Property_t& property);
|
||||
bool check_key_exists(const std::string& key);
|
||||
bool save();
|
||||
bool handle_save(const std::string& path);
|
||||
std::string handle_space(const std::string& content);
|
||||
bool handle_save(const std::string& path, const std::vector<std::string>& keychars);
|
||||
std::string handle_space(const std::string& content, const std::vector<std::string>& keychars);
|
||||
|
||||
public:
|
||||
Element_t* copy_element(Element_t* ele);
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
bool import_newer_data(const std::vector<std::string>& vec,
|
||||
std::size_t& success_count);
|
||||
// 处理转义
|
||||
bool handle_transfer(const std::string& path);
|
||||
bool handle_transfer(const std::string& path, const std::vector<std::string>& keychars);
|
||||
|
||||
public:
|
||||
void get_attributes(Element_t* ele, Property_t& vec);
|
||||
|
||||
Reference in New Issue
Block a user