func:实现了排序功能。

This commit is contained in:
taynpg 2024-05-18 01:26:52 +08:00
parent f9fd64d90f
commit 4976b5548e
10 changed files with 112 additions and 268 deletions

View File

@ -31,7 +31,7 @@ TabWidth: 4
# 构造函数的初始化列表要么都在同一行,要么都各自一行
ConstructorInitializerAllOnOneLineOrOnePerLine: true
# 每行字符的限制,0表示没有限制
ColumnLimit: 150
ColumnLimit: 100
# 允许短的块放在同一行
AllowShortBlocksOnASingleLine: false
# 是否允许短函数在一行

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
build
.vs
.cache
*.user

View File

@ -1,257 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 13.0.1, 2024-05-17T20:32:46. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{ba65acc4-67f8-4483-9557-68f8d8f20560}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="qlonglong">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">2</value>
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap">
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
<value type="bool" key="AutoTest.Framework.Boost">true</value>
<value type="bool" key="AutoTest.Framework.CTest">false</value>
<value type="bool" key="AutoTest.Framework.Catch">true</value>
<value type="bool" key="AutoTest.Framework.GTest">true</value>
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
</valuemap>
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
<value type="int" key="AutoTest.RunAfterBuild">0</value>
<value type="bool" key="AutoTest.UseGlobal">true</value>
<valuemap type="QVariantMap" key="ClangTools">
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
<value type="int" key="ClangTools.ParallelJobs">6</value>
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">vc64</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">vc64</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{244185d3-0e22-42f6-99cc-1b986ffe29c6}</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="CMake.Build.Type">Debug</value>
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}</value>
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:\code\OneLevelXmlOpr\build\vc64-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="CMake.Build.Type">Release</value>
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:\code\OneLevelXmlOpr\build\vc64-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">2</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">部署</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">部署</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph &quot;dwarf,4096&quot; -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">OneLevelXmlOpr</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeRunConfiguration.OneLevelXmlOpr</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">OneLevelXmlOpr</value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">E:/code/OneLevelXmlOpr/build/vc64-Debug</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="qlonglong">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">22</value>
</data>
<data>
<variable>Version</variable>
<value type="int">22</value>
</data>
</qtcreator>

View File

@ -11,7 +11,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
{
ui->setupUi(this);
setWindowTitle(u8"OneLevelXmlOpr v1.2.7");
setWindowTitle(u8"OneLevelXmlOpr v1.2.8");
setWindowIcon(QIcon("://resource/xml.ico"));
setMinimumWidth(900);
@ -37,7 +37,8 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
read(file);
});
connect(ui->btnSearch, &QPushButton::clicked, this, [&]() { search(); });
connect(ui->btnRead, &QPushButton::clicked, this, [&]() { read(ui->edStatus->text().trimmed()); });
connect(ui->btnRead, &QPushButton::clicked, this,
[&]() { read(ui->edStatus->text().trimmed()); });
connect(ui->btnSave, &QPushButton::clicked, this, [&]() { save(); });
connect(ui->btnExit, &QPushButton::clicked, this, [&]() { QApplication::exit(0); });
connect(ui->btnReset, &QPushButton::clicked, this, &MainWidget::reset);
@ -53,13 +54,22 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
unsigned int cur = ui->edCurPage->text().toUInt();
push_content(current_, cur);
});
connect(ui->btnResort, &QPushButton::clicked, this, [&]() {
sort_by_repeat(vec_);
std::vector<Element_t*> nvec{};
xml_.copy_and_del(vec_, nvec);
vec_.clear();
std::swap(vec_, nvec);
current_ = vec_;
push_content(current_);
});
QSettings settings;
settings.beginGroup("xmlopr");
restoreGeometry(settings.value("geometry").toByteArray());
settings.endGroup();
//QFile qss_file("://qss/lightblue.css");
// QFile qss_file("://qss/lightblue.css");
QFile qss_file("://qss/flatgray.css");
if (qss_file.open(QFile::ReadOnly)) {
qApp->setStyleSheet(qss_file.readAll());
@ -132,8 +142,10 @@ void MainWidget::generate_table_widget()
{
tab_widget_ = new QTableWidget();
tab_widget_->setContextMenuPolicy(Qt::CustomContextMenu);
connect(tab_widget_, &QTableWidget::itemChanged, this, [&](QTableWidgetItem* item) { item_changed_handle(item); });
connect(tab_widget_, &QTableWidget::customContextMenuRequested, this, &MainWidget::show_custom_menu);
connect(tab_widget_, &QTableWidget::itemChanged, this,
[&](QTableWidgetItem* item) { item_changed_handle(item); });
connect(tab_widget_, &QTableWidget::customContextMenuRequested, this,
&MainWidget::show_custom_menu);
auto config = ini_.get_config();
auto keys = splitString(config.purpose, ",");
keys_.clear();
@ -149,7 +161,7 @@ void MainWidget::generate_table_widget()
tab_widget_->setColumnCount(list.size());
tab_widget_->setHorizontalHeaderLabels(list);
tab_widget_->setSelectionBehavior(QAbstractItemView::SelectRows);
//tab_widget_->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
// tab_widget_->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
for (auto i = 0; i < keys.size(); ++i) {
tab_widget_->setColumnWidth(i, width_[i]);
@ -433,8 +445,8 @@ void MainWidget::insert_one_line(Element_t* ele, int row)
if (i == 0) {
wgItem->setFlags(wgItem->flags() & ~Qt::ItemIsEditable);
//wgItem->setFlags(wgItem->flags() | Qt::ItemIsUserCheckable);
//wgItem->setCheckState(Qt::Checked);
// wgItem->setFlags(wgItem->flags() | Qt::ItemIsUserCheckable);
// wgItem->setCheckState(Qt::Checked);
}
wgItem->setText(QString(data));
@ -517,3 +529,39 @@ tinyxml2::XMLElement* MainWidget::get_element_bykey(const QString& key)
}
return ret;
}
void MainWidget::sort_by_repeat(std::vector<Element_t*>& vec)
{
struct SElement_t {
SElement_t(Element_t* e, std::string& s)
{
ele = e;
str = std::move(s);
}
Element_t* ele{};
std::string str{};
};
std::vector<SElement_t> turn_vec{};
for (const auto& item : vec) {
const char* str = item->Attribute(keys_[0].c_str());
turn_vec.emplace_back(item, std::string(str));
}
auto compare = [&](const SElement_t& se1, const SElement_t& se2) {
std::size_t i = 0;
// 逐个字符比较,直到找到不同的字符或者某个字符串到达结尾
while (i < se1.str.length() && i < se2.str.length()) {
if (se1.str[i] != se2.str[i]) {
return se1.str[i] < se2.str[i];
}
++i;
}
// 如果有一个字符串到达结尾,而另一个还没有,则较短的字符串排在前面
return se1.str.length() < se2.str.length();
};
std::sort(turn_vec.begin(), turn_vec.end(), compare);
vec.clear();
for (const auto& item : turn_vec) {
vec.push_back(item.ele);
}
}

View File

@ -44,6 +44,7 @@ private:
void init_menu();
void ele_update_gui(Element_t* target, int row);
void show_custom_menu();
void sort_by_repeat(std::vector<Element_t*>& vec);
protected:
void closeEvent(QCloseEvent* event);

View File

@ -147,7 +147,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_4">
<widget class="QPushButton" name="btnResort">
<property name="text">
<string>重新排序</string>
</property>

View File

@ -46,3 +46,25 @@ QString CUtil::select_file(QWidget* parent, const QString& info, const QString&
QFileDialog::getOpenFileName(parent, info, QDir::homePath(), filter);
return filePath;
}
void CUtil::sort_by_repeat(std::vector<std::string>& vec)
{
std::size_t len1 = 0;
std::size_t len2 = 0;
std::size_t cur = 0;
auto compare = [&](const std::string& str1, const std::string& str2) {
len1 = str1.size();
len2 = str2.size();
if (cur >= len1 || cur >= len2) {
return len1 > len2;
}
return str1[cur] > str2[cur];
};
std::size_t max_len = 0;
for (const auto& data : vec) {
max_len = data.size() > max_len ? data.size() : max_len;
}
for (cur = 0; cur < max_len; ++cur) {
std::sort(vec.begin(), vec.end(), compare);
}
}

View File

@ -23,6 +23,7 @@ public:
static void msg(QWidget* parent, const QString& content);
static bool affirm(QWidget* parent, const QString& titile, const QString& content);
static QString select_file(QWidget* parent, const QString& info, const QString& filter);
static void sort_by_repeat(std::vector<std::string>& vec);
};
#endif

View File

@ -52,6 +52,33 @@ bool CXmlOpr::parse_xml(std::vector<tinyxml2::XMLElement*>& vec)
return true;
}
// 排序后(仅指针排序)的节点进行复制(让实际内容有序),删除原始节点
void CXmlOpr::copy_and_del(std::vector<Element_t*>& vec, std::vector<Element_t*>& out)
{
out.clear();
// 先找到最后一个节点
Element_t* last_node = parent_node_->LastChildElement(opr_base_.the_node.c_str());
Element_t* last_node_bk = last_node;
if (last_node == nullptr) {
return;
}
for (const auto& data : vec) {
Element_t* n = copy_element(data);
out.push_back(n);
insert_brother_node(last_node, n);
last_node = n;
}
// 删除原有的节点
Element_t* fnode = parent_node_->FirstChildElement(opr_base_.the_node.c_str());
Element_t* fnext = fnode->NextSiblingElement();
while (fnode != last_node_bk) {
parent_node_->DeleteChild(fnode);
fnode = fnext;
fnext = fnode->NextSiblingElement();
}
parent_node_->DeleteChild(last_node_bk);
}
void CXmlOpr::insert_brother_node(Element_t* brother, Element_t* newer)
{
if (!brother || !newer) {

View File

@ -24,6 +24,7 @@ public:
bool open(const std::string& xml_path);
void set_baseinfo(const OprBase& base);
bool parse_xml(std::vector<Element_t*>& vec);
void copy_and_del(std::vector<Element_t*>& vec, std::vector<Element_t*>& out);
void insert_brother_node(Element_t* brother, Element_t* newer);
Element_t* copy_element(Element_t* ele);
void del_element(Element_t* ele);