opti:设置自动设置列宽度,并且可以配置允许的最大宽度。
This commit is contained in:
parent
3d1fcc5dc8
commit
5761a7ff48
@ -16,7 +16,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
setWindowTitle(u8"OneLevelXmlOpr v1.2.14");
|
||||
setWindowTitle(u8"OneLevelXmlOpr v1.2.15");
|
||||
setWindowIcon(QIcon("://resource/xml.ico"));
|
||||
|
||||
QScreen* primaryScreen = QGuiApplication::primaryScreen();
|
||||
@ -26,11 +26,6 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
// setMinimumWidth(900);
|
||||
// setMinimumHeight(800);
|
||||
|
||||
width_.push_back(280);
|
||||
for (int i = 0; i < 30; ++i) {
|
||||
width_.push_back(160);
|
||||
}
|
||||
|
||||
attri_edit_ = new CAttributeEdit();
|
||||
|
||||
ui->edStatus->setReadOnly(true);
|
||||
@ -51,6 +46,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
return;
|
||||
}
|
||||
read(file);
|
||||
//ui->edStatus->setText(file);
|
||||
});
|
||||
connect(ui->btnSearch, &QPushButton::clicked, this, [&]() { search(ui->edSearchKey->text()); });
|
||||
connect(ui->btnBackup, &QPushButton::clicked, this, [&]() { backup_file(); });
|
||||
@ -115,6 +111,11 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
|
||||
ini_.set_work_exe(exe_path_);
|
||||
base_ = ini_.get_config();
|
||||
|
||||
if (base_.blank_width > 20) {
|
||||
blank_with_ = base_.blank_width;
|
||||
}
|
||||
|
||||
ui->edStatus->setText(QString::fromStdString(base_.xml_path));
|
||||
}
|
||||
|
||||
@ -180,6 +181,7 @@ void MainWidget::show_custom_menu()
|
||||
void MainWidget::generate_table_widget()
|
||||
{
|
||||
tab_widget_ = new QTableWidget();
|
||||
metrics_ = std::make_shared<QFontMetrics>(tab_widget_->font());
|
||||
tab_widget_->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(tab_widget_, &QTableWidget::itemChanged, this,
|
||||
[&](QTableWidgetItem* item) { item_changed_handle(item); });
|
||||
@ -196,13 +198,18 @@ void MainWidget::generate_table_widget()
|
||||
list.append(QString::fromStdString(item));
|
||||
}
|
||||
|
||||
col_with_.clear();
|
||||
for (auto i = 0; i < keys_.size(); ++i) {
|
||||
col_with_[i] = 0;
|
||||
}
|
||||
|
||||
tab_widget_->setColumnCount(list.size());
|
||||
tab_widget_->setHorizontalHeaderLabels(list);
|
||||
tab_widget_->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
// tab_widget_->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
|
||||
|
||||
for (auto i = 0; i < keys.size(); ++i) {
|
||||
tab_widget_->setColumnWidth(i, width_[i]);
|
||||
tab_widget_->setColumnWidth(i, col_with_[i]);
|
||||
}
|
||||
|
||||
QHBoxLayout* lay = new QHBoxLayout();
|
||||
@ -251,6 +258,10 @@ void MainWidget::push_content(const std::vector<tinyxml2::XMLElement*>& eles, st
|
||||
ui->edAllPage->setText(QString::number(all_page_));
|
||||
judge_btn_page();
|
||||
auto_add_ = false;
|
||||
|
||||
for (auto i = 0; i < keys_.size(); ++i) {
|
||||
tab_widget_->setColumnWidth(static_cast<int>(i), col_with_[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::judge_btn_page()
|
||||
@ -271,7 +282,8 @@ void MainWidget::judge_btn_page()
|
||||
|
||||
void MainWidget::read(const QString& file_path)
|
||||
{
|
||||
if (!ini_.set_xml_path(file_path.toStdString())) {
|
||||
base_.xml_path = file_path.toStdString();
|
||||
if (!ini_.set_xml_path(base_.xml_path)) {
|
||||
CUtil::msg(this, u8"没有ini配置文件或者保存ini失败。");
|
||||
return;
|
||||
}
|
||||
@ -287,6 +299,13 @@ void MainWidget::read(const QString& file_path)
|
||||
return;
|
||||
}
|
||||
|
||||
if (base_.allow_max_width < 0 || base_.allow_max_width > 1000) {
|
||||
allow_max_with_ = 100;
|
||||
}
|
||||
else {
|
||||
allow_max_with_ = base_.allow_max_width;
|
||||
}
|
||||
|
||||
generate_table_widget();
|
||||
push_content(vec_);
|
||||
current_ = vec_;
|
||||
@ -496,6 +515,9 @@ void MainWidget::insert_one_line(Element_t* ele, int row)
|
||||
// wgItem->setCheckState(Qt::Checked);
|
||||
}
|
||||
QString sda(data);
|
||||
int dwidth = metrics_->horizontalAdvance(sda) + blank_with_;
|
||||
int need_set_width = dwidth > allow_max_with_ ? allow_max_with_ : dwidth;
|
||||
col_with_[i] = col_with_[i] < need_set_width ? need_set_width : col_with_[i];
|
||||
wgItem->setText(sda);
|
||||
tab_widget_->setItem(row, i, wgItem);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
#include <QMessageBox>
|
||||
#include <unordered_map>
|
||||
#include "src/xml_opr.h"
|
||||
#include "src/config.h"
|
||||
#include "src/attribute_edit.h"
|
||||
@ -30,6 +31,7 @@ class MainWidget;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
using ump_t = std::unordered_map<int, int>;
|
||||
class MainWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -78,6 +80,9 @@ private:
|
||||
Element_t* get_current_select_key();
|
||||
QTableWidgetItem* get_current_select_item();
|
||||
|
||||
private:
|
||||
std::shared_ptr<QFontMetrics> metrics_;
|
||||
|
||||
private:
|
||||
QMenu* menu_simple_{};
|
||||
QMenu* menu_multi_{};
|
||||
@ -93,11 +98,13 @@ private:
|
||||
std::vector<Element_t*> vec_{};
|
||||
std::vector<Element_t*> current_{};
|
||||
std::vector<std::string> keys_{};
|
||||
std::vector<int> width_{};
|
||||
bool auto_add_{false};
|
||||
std::size_t cur_page_{1};
|
||||
std::size_t all_page_{1};
|
||||
CAttributeEdit* attri_edit_{};
|
||||
OprBase base_{};
|
||||
long allow_max_with_{500};
|
||||
long blank_with_{50};
|
||||
ump_t col_with_{};
|
||||
};
|
||||
#endif // MAINWIDGET_H
|
||||
|
@ -10,6 +10,8 @@ struct OprBase {
|
||||
std::string the_node{};
|
||||
std::string purpose{};
|
||||
std::string xml_path{};
|
||||
long allow_max_width{500};
|
||||
long blank_width{50};
|
||||
};
|
||||
|
||||
class CUtil
|
||||
|
@ -47,5 +47,7 @@ bool ConfigIni::parse_ini()
|
||||
opr_base_.purpose = ini_.GetValue("Basic", "purpose");
|
||||
opr_base_.the_node = ini_.GetValue("Basic", "the_node");
|
||||
opr_base_.xml_path = ini_.GetValue("Basic", "xml_path");
|
||||
opr_base_.allow_max_width = ini_.GetLongValue("Basic", "max_col_width");
|
||||
opr_base_.blank_width = ini_.GetLongValue("Basic", "blank_width");
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user