加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mainwindow.cpp 23.94 KB
一键复制 编辑 原始数据 按行查看 历史
AGeek 提交于 2023-08-02 10:31 . 更新提示信息
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include "use_percentage_bar.h"
#include <Qdebug>
#include "flatui.h"
#include <QDebug>
#include <QDesktopServices>
#pragma execution_character_set("utf-8")
void MainWindow::winow_on_top(bool is_top)
{
if(is_top)
setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
else
setWindowFlags(windowFlags()&(~Qt::WindowStaysOnTopHint));
}
MainWindow::MainWindow(QWidget *parent) : FramelessMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->initForm();
winow_on_top(true);
// winow_on_top(false);
}
MainWindow::~MainWindow()
{
delete cpu;
delete map;
delete ram_chart;
delete flash_chart;
delete ui;
}
void MainWindow::initForm()
{
//设置标题栏控件
ui->labTitle->setText("一个极客开源::keil开发助手");
this->setWindowTitle(ui->labTitle->text());
this->setTitleBar(ui->labTitle);
//关联信号
connect(this, SIGNAL(titleDblClick()), this, SLOT(titleDblClick()));
connect(this, SIGNAL(windowStateChange(bool)), this, SLOT(windowStateChange(bool)));
//设置样式表
QStringList list;
list << "#titleBar{background:#BBBBBB;}";
list << "#titleBar{border-top-left-radius:8px;border-top-right-radius:8px;}";
list << "#widgetMain{border:2px solid #BBBBBB;background:#FFFFFF;}";
list << "#widgetMain{border-bottom-left-radius:8px;border-bottom-right-radius:8px;}";
this->setStyleSheet(list.join(""));
FlatUI::setScrollBarQss(ui->ram_scrollArea->verticalScrollBar(), 8, 120, 20, "#E5E5E5", "#D0D0D0", "#1ABC9C", "#E74C3C");
FlatUI::setScrollBarQss(ui->flash_scrollArea->verticalScrollBar(), 8, 120, 20, "#E5E5E5", "#D0D0D0", "#1ABC9C", "#E74C3C");
FlatUI::setScrollBarQss(ui->ram_table->horizontalScrollBar(), 8, 120, 20, "#E5E5E5", "#D0D0D0", "#1ABC9C", "#E74C3C");
FlatUI::setScrollBarQss(ui->ram_table->verticalScrollBar(), 8, 120, 20, "#E5E5E5", "#D0D0D0", "#1ABC9C", "#E74C3C");
FlatUI::setScrollBarQss(ui->flash_table->horizontalScrollBar(), 8, 120, 20, "#E5E5E5","#D0D0D0", "#1ABC9C", "#E74C3C");
FlatUI::setScrollBarQss(ui->flash_table->verticalScrollBar(), 8, 120, 20, "#E5E5E5", "#D0D0D0", "#1ABC9C", "#E74C3C");
FlatUI::setProgressQss(ui->ram_used_bar, 20,12,16, "#747976", "#1ABC9C");//#FAEC9C",#FFF5E7
FlatUI::setProgressQss(ui->flash_used_bar, 20,12,16, "#747976", "#1ABC9C");
main_window=this;
//map_path="./";
//project_path="./";
ui->map_path->setText(map_path);
ui->project_path->setText(project_path);
ram_pieseries=new QPieSeries();
flash_pieseries=new QPieSeries();
ram_chart=new QChart();
flash_chart=new QChart();
//QChartView
ram_chart->addSeries(ram_pieseries);
ram_chart->setTitle("文件内存分布饼图");
ram_chart->legend()->hide();
// Set the theme to one of the predefined themes
ram_chart->setTheme(QChart::ChartThemeQt);
ram_chart->setBackgroundBrush(QBrush(Qt::gray));
ram_chart->setTitleBrush(Qt::white);; // 数据集分类标题文字颜色
flash_chart->addSeries(flash_pieseries);
flash_chart->setTitle("文件flash分布饼图");
flash_chart->legend()->hide();
// Set the theme to one of the predefined themes
flash_chart->setTheme(QChart::ChartThemeQt);
flash_chart->setBackgroundBrush(QBrush(Qt::gray));
flash_chart->setTitleBrush(Qt::white);
ui->ram_chart_view->setChart(ram_chart);
ui->ram_chart_view->setRubberBand(QChartView::RectangleRubberBand);
ui->flash_chart_view->setChart(flash_chart);
ui->flash_chart_view->setRubberBand(QChartView::RectangleRubberBand);
if(map_path.length()>1&&project_path.length()>1)
{
cpu= new parse_keil_project(ui->project_path->text());
if(cpu->to_parse_keil_project(ui->project_path->text()))
{
update_cpu_info();
if(cpu->getCpu_core_name()!="8051")
{
}else {
}
}
if(cpu->getCpu_core_name()!="8051")
{
map= new parse_map_from_keil( ui->map_path->text(),cpu->IRAM.getBase_addr(),cpu->IRAM.getMax_size(),cpu->IROM.getBase_addr(),cpu->IROM.getMax_size());
if(map->to_parse_map_from_keil(ui->map_path->text()))
{
map_calculate_size_by_address(map);
update_map_info();
}
}else {
m51 =new parse_m51_from_keil(ui->map_path->text(),cpu->IRAM.getMax_size(),cpu->XRAM.getMax_size(),cpu->IROM.getMax_size());
if(m51->to_parse_m51_from_keil(ui->map_path->text()))
{
update_m51_info();
}
}
}
fflush(stdout);
}
void MainWindow::map_calculate_size_by_address(parse_map_from_keil* map)
{
for(auto ram:map->ram_list)
{
if(ram->getMax_size()>100*1024*1024)
{
uint64_t recent_base=cpu->IRAM.getBase_addr()+cpu->IRAM.getMax_size();
for(auto recent_ram :map->ram_list)
{
if(recent_ram->getBase_addr()>ram->getBase_addr())
{
if(recent_ram->getBase_addr()-ram->getBase_addr()<recent_base-ram->getBase_addr())
recent_base=recent_ram->getBase_addr();
}
}
ram->setMax_size(recent_base-ram->getBase_addr());
}
}
for(auto flash:map->flash_list)
{
if(flash->getMax_size()>100*1024*1024)
{
uint64_t recent_base=cpu->IROM.getBase_addr()+cpu->IROM.getMax_size();
for(auto recent_flash :map->flash_list)
{
if(recent_flash->getBase_addr()>flash->getBase_addr())
{
if(recent_flash->getBase_addr()-flash->getBase_addr()<recent_base-flash->getBase_addr())
recent_base=recent_flash->getBase_addr();
}
}
flash->setMax_size(recent_base-flash->getBase_addr());
}
}
}
void MainWindow::on_btn_set_project_path_clicked()
{
//获取选择的目录路径
QString selectedDir=QFileDialog::getExistingDirectory(this,"选择一个目录","./",QFileDialog::ShowDirsOnly);
//若目录路径不为空
if (!selectedDir.isEmpty())
{
//将路径中的斜杠替换为反斜杠
selectedDir = selectedDir.replace(QRegExp("\\"), "/");
//显示选择的目录路径
ui->project_path->setText(selectedDir);
ui->map_path->setText(selectedDir);
}
}
void MainWindow::set_bar_style(QProgressBar *bar,float per)
{
if( per/1.0>0.85)
{
FlatUI::setProgressQss(bar, 20,12,16, "#747976", "#E74C3C");
}else if( per>0.75)
{
FlatUI::setProgressQss(bar, 20,12,16, "#747976", "#F9D927");
}
else
{
FlatUI::setProgressQss(bar, 20,12,16, "#747976", "#1ABC9C");
}
}
void MainWindow::on_btn_set_map_path_clicked()
{
//获取选择的目录路径
QString selectedDir=QFileDialog::getExistingDirectory(this,"选择一个目录","./",QFileDialog::ShowDirsOnly);
//若目录路径不为空
if (!selectedDir.isEmpty())
{
//将路径中的斜杠替换为反斜杠
selectedDir = selectedDir.replace(QRegExp("\\"), "/");
//显示选择的目录路径
ui->map_path->setText(selectedDir);
}
}
void MainWindow::on_update_info_clicked()
{
if(cpu!=nullptr)
{
delete cpu;
cpu=nullptr;
}
cpu= new parse_keil_project(ui->project_path->text());
if(cpu->to_parse_keil_project(ui->project_path->text()))
update_cpu_info();
if(cpu->getCpu_core_name()!="8051")
{
if(map!=nullptr)
{
delete map;
map=nullptr;
}
map= new parse_map_from_keil(ui->map_path->text(),cpu->IRAM.getBase_addr(),cpu->IRAM.getMax_size(),cpu->IROM.getBase_addr(),cpu->IROM.getMax_size());
if(map->to_parse_map_from_keil(ui->map_path->text()))
{
map_calculate_size_by_address(map);
update_map_info();
}
}else {
if(m51!=nullptr)
{
delete m51;
m51=nullptr;
}
m51 =new parse_m51_from_keil(ui->map_path->text(),cpu->IRAM.getMax_size(),cpu->XRAM.getMax_size(),cpu->IROM.getMax_size());
if(m51->to_parse_m51_from_keil(ui->map_path->text()))
update_m51_info();
}
fflush(stdout);
}
void MainWindow::on_ram_table_itemSelectionChanged()
{
QList<QTableWidgetItem*> selectedItems = ui->ram_table->selectedItems();
// Reset all pie slices to not exploded (not highlighted)
foreach (QPieSlice* slice, ram_pieseries->slices()) {
slice->setExploded(false);
slice->setLabelVisible(false);
}
foreach (QTableWidgetItem* item, selectedItems) {
int row = item->row();
// qDebug() << row;
QPieSlice *slice = ram_pieseries->slices().at(row);
slice->setExploded();//突出这一块
slice->setLabelVisible();//设置这一块可见数据
slice->setLabelBrush(Qt::white);
}
}
void MainWindow::on_flash_table_itemSelectionChanged()
{
QList<QTableWidgetItem*> selectedItems = ui->flash_table->selectedItems();
// Reset all pie slices to not exploded (not highlighted)
foreach (QPieSlice* slice, flash_pieseries->slices()) {
slice->setExploded(false);
slice->setLabelVisible(false);
}
foreach (QTableWidgetItem* item, selectedItems) {
int row = item->row();
// qDebug() << row;
QPieSlice *slice = flash_pieseries->slices().at(row);
slice->setExploded();//突出这一块
slice->setLabelVisible();//设置这一块可见数据
slice->setLabelBrush(Qt::white);
}
}
void MainWindow::update_cpu_info(void)
{
ui->cpu_name->setTitle(cpu->getCpu_name());
ui->cpu_core->setText("单片机核心:"+cpu->getCpu_core_name());
ui->cpu_colck->setText(QString().sprintf("最高主频:%.2f MHz",cpu->getCpu_max_clock()/1000000.0));
ui->iram->setText(QString().sprintf("内部ram 地址:%#x 容量:%.2f KB",cpu->IRAM.getBase_addr(),cpu->IRAM.getMax_size()/1024.0));
ui->flash->setText(QString().sprintf("内部flash 地址:%#x 容量:%.2f KB",cpu->IROM.getBase_addr(),cpu->IROM.getMax_size()/1024.0));
}
void MainWindow::clearLayout(QLayout* layout) {
QLayoutItem* item;
while ((item = layout->takeAt(0))) {
QWidget* widget = item->widget();
if (widget) {
layout->removeWidget(widget); // 将小部件从布局中移除
widget->setParent(nullptr); // 设置父对象为nullptr,避免悬挂指针问题
delete widget; // 删除小部件并释放内存
}
delete item; // 删除布局项
}
}
void MainWindow::update_m51_info(void)
{
uint64_t ram_all_max_size=0;
uint64_t ram_all_used_size=0;
uint64_t ram_min_base_addr=m51->ram_list.at(0)->getBase_addr();
uint64_t flash_all_max_size=0;
uint64_t flash_all_used_size=0;
uint64_t flash_min_base_addr=m51->flash_list.at(0)->getBase_addr();
uint16_t i;
clearLayout(ui->ram_scrollAreaWidgetContents->layout());
// 移除并释放布局中的所有小部件
clearLayout(ui->flash_scrollAreaWidgetContents->layout());
// 移除并释放布局中的所有小部件
for(uint64_t row_cnt=0;row_cnt<ui->ram_table->rowCount();row_cnt++)
{
ui->ram_table->removeRow(row_cnt);
}
ui->ram_table->clear();
ram_pieseries->clear();
for(uint64_t row_cnt=0;row_cnt<ui->flash_table->rowCount();row_cnt++)
{
ui->flash_table->removeRow(row_cnt);
}
ui->flash_table->clear();
flash_pieseries->clear();
for(i=0;i<m51->ram_list.size();i++)
{
ram_all_used_size+=m51->ram_list.at(i)->getUsed_size();
ram_all_max_size+=m51->ram_list.at(i)->getMax_size();
if(ram_min_base_addr>m51->ram_list.at(0)->getBase_addr())
ram_min_base_addr=m51->ram_list.at(i)->getBase_addr();
ui->ram_scrollAreaWidgetContents->layout()->addWidget(m51->ram_list.at(i));
}
ui->ram_addr->setText(QString().sprintf("地址:%#x",ram_min_base_addr));
ui->ram_used_bar->setRange(0,ram_all_max_size);
ui->ram_used_bar->setValue(ram_all_used_size);
ui->ram_remain->setText(QString().sprintf("剩余:%.2f B",ram_all_max_size/10.0-ram_all_used_size/10.0));
if(ram_all_max_size/10.0<=1024)
{
ui->ram_used->setText(QString().sprintf("占用:%.2f B / (%.2f B)",ram_all_used_size/10.0,ram_all_max_size/10.0));
}else
{
ui->ram_used->setText(QString().sprintf("占用:%.2f B / (%.2f KB)",ram_all_used_size/1024.0,ram_all_max_size/10.0/1024.0));
}
set_bar_style(ui->ram_used_bar,ram_all_used_size/1.0/ram_all_max_size/1.0);
for(i=0;i<m51->flash_list.size();i++)
{
flash_all_used_size+=m51->flash_list.at(i)->getUsed_size();
flash_all_max_size+=m51->flash_list.at(i)->getMax_size();
if(flash_min_base_addr>m51->flash_list.at(0)->getBase_addr())
flash_min_base_addr=m51->flash_list.at(i)->getBase_addr();
ui->flash_scrollAreaWidgetContents->layout()->addWidget(m51->flash_list.at(i));
}
ui->flash_addr->setText(QString().sprintf("地址:%#x",flash_min_base_addr));
ui->flash_used_bar->setRange(0,flash_all_max_size);
ui->flash_used_bar->setValue(flash_all_used_size);
ui->flash_remain->setText(QString().sprintf("剩余:%.2f B",flash_all_max_size/10.0-flash_all_used_size/10.0));
if(flash_all_max_size/10.0<=1024)
{
ui->flash_used->setText(QString().sprintf("占用:%.2f B / (%.2f B)",flash_all_used_size/10.0,flash_all_max_size/10.0));
}else
{
ui->flash_used->setText(QString().sprintf("占用:%.2f B / (%.2f KB)",flash_all_used_size/1024.0,flash_all_max_size/10.0/1024.0));
}
set_bar_style(ui->flash_used_bar,ram_all_used_size/1.0/ram_all_max_size/1.0);
if(ui->ram_scrollArea->verticalScrollBar()!=nullptr)
FlatUI::setScrollBarQss(ui->ram_scrollArea->verticalScrollBar(), 8, 120, 20, "##E5E5E5", "#D0D0D0", "#1ABC9C", "#E74C3C");
if(ui->ram_scrollArea->verticalScrollBar()!=nullptr)
FlatUI::setScrollBarQss(ui->flash_scrollArea->verticalScrollBar(), 8, 120, 20, "#E5E5E5", "#D0D0D0", "#1ABC9C", "#E74C3C");
}
void MainWindow::setPieSliceStyle(QPieSlice* slice, qreal percentage, qreal maxPercentage)
{
// Define an array of custom green colors to represent different percentage ranges
QColor colors[] = {
QColor("#D1FF4D"), // Light Green Yellow
QColor("#C0FF3E"), // Greenish Yellow
QColor("#ADFF2F"), // Green Yellow
QColor("#7CFC00"), // Lawn Green
QColor("#00FF00"), // Lime Green
QColor("#008000"), // Green
QColor("#006400"), // Dark Green
};
// Calculate the relative percentage compared to the maxPercentage
qreal relativePercentage = (percentage / maxPercentage) * 100.0;
// Determine the index of the color based on relative percentage
int colorIndex = qMin(int(relativePercentage) / (100 / (sizeof(colors) / sizeof(colors[0]))), sizeof(colors) / sizeof(colors[0]) - 1);
// Set the color of the slice based on the color index
slice->setColor(colors[colorIndex]);
}
void MainWindow::update_map_info(void)
{
if(map->ram_list.length()==0)
return;
if(map->flash_list.length()==0)
return;
uint64_t ram_all_max_size=0;
uint64_t ram_all_used_size=0;
uint64_t ram_min_base_addr=map->ram_list.at(0)->getBase_addr();
uint64_t flash_all_max_size=0;
uint64_t flash_all_used_size=0;
uint64_t flash_min_base_addr=map->flash_list.at(0)->getBase_addr();
uint16_t i;
clearLayout(ui->ram_scrollAreaWidgetContents->layout());
// // 移除并释放布局中的所有小部件
clearLayout(ui->flash_scrollAreaWidgetContents->layout());
// // 移除并释放布局中的所有小部件
for(uint64_t row_cnt=0;row_cnt<ui->ram_table->rowCount();row_cnt++)
{
ui->ram_table->removeRow(row_cnt);
}
ui->ram_table->clear();
ram_pieseries->clear();
for(uint64_t row_cnt=0;row_cnt<ui->flash_table->rowCount();row_cnt++)
{
ui->flash_table->removeRow(row_cnt);
}
ui->flash_table->clear();
flash_pieseries->clear();
for(i=0;i<map->ram_list.size();i++)
{
ram_all_used_size+=map->ram_list.at(i)->getUsed_size();
ram_all_max_size+=map->ram_list.at(i)->getMax_size();
if(ram_min_base_addr>map->ram_list.at(0)->getBase_addr())
ram_min_base_addr=map->ram_list.at(i)->getBase_addr();
ui->ram_scrollAreaWidgetContents->layout()->addWidget(map->ram_list.at(i));
}
ui->ram_addr->setText(QString().sprintf("地址:%#x",ram_min_base_addr));
ui->ram_used_bar->setRange(0,ram_all_max_size);
ui->ram_used_bar->setValue(ram_all_used_size);
ui->ram_remain->setText(QString().sprintf("剩余:%llu B",ram_all_max_size-ram_all_used_size));
if(ram_all_max_size<=1024*1024)
{
ui->ram_used->setText(QString().sprintf("占用:%.2f KB / (%.2f KB)",ram_all_used_size/1024.0,ram_all_max_size/1024.0));
}else
{
ui->ram_used->setText(QString().sprintf("占用:%.4f MB / (%.4f MB)",ram_all_used_size/1024.0/1024.0,ram_all_max_size/1024.0/1024.0));
}
set_bar_style(ui->ram_used_bar,ram_all_used_size/1.0/ram_all_max_size/1.0);
for(i=0;i<map->flash_list.size();i++)
{
flash_all_used_size+=map->flash_list.at(i)->getUsed_size();
flash_all_max_size+=map->flash_list.at(i)->getMax_size();
if(flash_min_base_addr>map->flash_list.at(0)->getBase_addr())
flash_min_base_addr=map->flash_list.at(i)->getBase_addr();
ui->flash_scrollAreaWidgetContents->layout()->addWidget(map->flash_list.at(i));
}
ui->flash_addr->setText(QString().sprintf("地址:%#x",flash_min_base_addr));
ui->flash_used_bar->setRange(0,flash_all_max_size);
ui->flash_used_bar->setValue(flash_all_used_size);
ui->flash_remain->setText(QString().sprintf("剩余:%llu B",flash_all_max_size-flash_all_used_size));
if(flash_all_max_size<=1024*1024)
{
ui->flash_used->setText(QString().sprintf("占用:%.2f KB / (%.2f KB)",flash_all_used_size/1024.0,flash_all_max_size/1024.0));
}else
{
ui->flash_used->setText(QString().sprintf("占用:%.4f MB / (%.4f MB)",flash_all_used_size/1024.0/1024.0,flash_all_max_size/1024.0/1024.0));
}
set_bar_style(ui->flash_used_bar,flash_all_used_size/1.0/flash_all_max_size/1.0);
QList <image_item_t*> info_lsit= map->getInfo_list();
uint64_t all_ram_size = map->getAll_ram_size();
uint64_t all_flash_size =map->getAll_flash_size();
uint64_t ram_row=0;
uint64_t flash_row=0;
for(auto item:info_lsit)
{
if(item->RW_Data.toUInt()+item->ZI_Data.toUInt()!=0)
{
writeTableData(ram_table,ram_row,0,item->Object_Name);
writeTableData(ram_table,ram_row,1,QString::number(item->RW_Data.toUInt()+item->ZI_Data.toUInt()));
writeTableData(ram_table,ram_row,3,item->RW_Data);
writeTableData(ram_table,ram_row,4,item->ZI_Data);
all_ram_size+=item->RW_Data.toUInt()+item->ZI_Data.toUInt();
ram_row++;
}
if(item->Code.toUInt()+item->RO_Data.toUInt()+item->RW_Data.toUInt()!=0)
{
writeTableData(flash_table,flash_row,0,item->Object_Name);
writeTableData(flash_table,flash_row,1,QString::number(item->Code.toUInt()+item->RO_Data.toUInt()+item->RW_Data.toUInt()));
writeTableData(flash_table,flash_row,3,item->Code);
writeTableData(flash_table,flash_row,4,item->RO_Data);
writeTableData(flash_table,flash_row,5,item->RW_Data);
all_flash_size+=item->Code.toUInt()+item->RO_Data.toUInt()+item->RW_Data.toUInt();
flash_row++;
}
}
ui->ram_per->setTitle(QString().sprintf("used_ram=RW+ZI=%llu",all_ram_size));
ui->flash_per->setTitle(QString().sprintf("used_flash=RW+Code+RO=%llu",all_flash_size));
for(uint64_t row_cnt=0;row_cnt<ui->ram_table->rowCount();row_cnt++)
{
writeTableData(ram_table,row_cnt,2,QString().sprintf("%05.2f%%",ui->ram_table->item(row_cnt,1)->text().toUInt()*100.0/all_ram_size/1.0));
}
for(uint64_t row_cnt=0;row_cnt<ui->flash_table->rowCount();row_cnt++)
{
writeTableData(flash_table,row_cnt,2,QString().sprintf("%05.2f%%",ui->flash_table->item(row_cnt,1)->text().toUInt()*100.0/all_flash_size/1.0));
}
ui->ram_table->sortByColumn(2,Qt::SortOrder::DescendingOrder);
ui->flash_table->sortByColumn(2,Qt::SortOrder::DescendingOrder);
for(uint64_t row_cnt=0;row_cnt<ui->ram_table->rowCount();row_cnt++)
{
QPieSlice *slice =ram_pieseries->append(ui->ram_table->item(row_cnt,0)->text()+":"+ui->ram_table->item(row_cnt,2)->text(),ui->ram_table->item(row_cnt,1)->text().toUInt());
setPieSliceStyle(slice,ui->ram_table->item(row_cnt,2)->text().split("%")[0].toFloat(),ui->ram_table->item(0,2)->text().split("%")[0].toFloat());
}
for(uint64_t row_cnt=0;row_cnt<ui->flash_table->rowCount();row_cnt++)
{
QPieSlice *slice =flash_pieseries->append(ui->flash_table->item(row_cnt,0)->text()+":"+ui->flash_table->item(row_cnt,2)->text(),ui->flash_table->item(row_cnt,1)->text().toUInt());
setPieSliceStyle(slice,ui->flash_table->item(row_cnt,2)->text().split("%")[0].toFloat(),ui->flash_table->item(0,2)->text().split("%")[0].toFloat());
}
if(ui->ram_scrollArea->verticalScrollBar()!=nullptr)
FlatUI::setScrollBarQss(ui->ram_scrollArea->verticalScrollBar(), 8, 120, 20, "#E5E5E5", "#D0D0D0", "#1ABC9C", "#E74C3C");
if(ui->ram_scrollArea->verticalScrollBar()!=nullptr)
FlatUI::setScrollBarQss(ui->flash_scrollArea->verticalScrollBar(), 8, 120, 20, "#E5E5E5", "#D0D0D0", "#1ABC9C", "#E74C3C");
}
QString MainWindow::readTableData(ui_table_t table,int row, int column)
{
QString data;
QTableWidget* tableWidget ;
if( table==ram_table)tableWidget=ui->ram_table;
else tableWidget=ui->flash_table;
if (row < tableWidget->rowCount() && column <tableWidget->columnCount()) {
QTableWidgetItem *item =tableWidget->item(row, column);
if (item) {
data = item->text();
// qDebug() << "Data at (" << row << ", " << column << "): " << data;
}
}
return data;
}
void MainWindow::writeTableData(ui_table_t table,int row, int column, const QString &data)
{
QTableWidget* tableWidget=nullptr;
if (table == ram_table)
{
tableWidget=ui->ram_table;
}
else if (table == flash_table)
{
tableWidget = ui->flash_table;
}
else
{
qDebug() << "Invalid table specified.";
return;
}
if (row >= tableWidget->rowCount())
{
tableWidget->setRowCount(row + 1);
}
if (column >= tableWidget->columnCount())
{
tableWidget->setColumnCount(column + 1);
}
if (!tableWidget->item(row, column))
{
QTableWidgetItem *newItem = new QTableWidgetItem(data);
tableWidget->setItem(row, column, newItem);
}
else
{
tableWidget->item(row, column)->setText(data);
}
}
void MainWindow::titleDblClick()
{
on_btnMenu_Max_clicked();
}
void MainWindow::windowStateChange(bool max)
{
ui->btnMenu_Max->setText(max ? "还原" : "最大");
}
void MainWindow::on_btnMenu_Min_clicked()
{
#ifdef Q_OS_MACOS
this->setWindowFlags(this->windowFlags() & ~Qt::FramelessWindowHint);
#endif
this->showMinimized();
}
void MainWindow::on_btnMenu_Max_clicked()
{
if (this->isMaximized()) {
this->showNormal();
ui->btnMenu_Max->setText("最大");
} else {
this->showMaximized();
ui->btnMenu_Max->setText("还原");
}
}
void MainWindow::on_btnMenu_Close_clicked()
{
this->close();
}
void MainWindow::on_gitee_index_clicked()
{
QDesktopServices::openUrl(QUrl("https://gitee.com/nikolan"));
}
void MainWindow::on_icon_clicked()
{
QDesktopServices::openUrl(QUrl("https://gitee.com/nikolan/keil_development_assistant"));
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化