[AssistantTool]_10_时序计算面板

Posted 暮色1994

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[AssistantTool]_10_时序计算面板相关的知识,希望对你有一定的参考价值。

[AssistantTool]_10_时序计算面板

创建时间:20210115 14:35:00

添加时序计算页面

  • 主要分两部分
    • 上部分是采用grid layout形式排布参数

添加时序图和对应输入框

  • 下半部分是一个ScrollArea, 然后放入Frame控件,并且将宽高固定,这样图片和对应位置的时序参数可以固定下来,并且在缩放窗口的时候,可以有滚动条保证各位置的图形查看和参数填写。

  • 添加时序图,作为frame背景,这样可以放上对应输入框来友好的获参数输入。

    QFrame#frame{
        border-image: url(:/assert/2021-07-31-11-04-30.png);
    }
    
  • 在frame空间中,在需要输入或显示时序的地方,放置输入框。

运行效果如下

解决字符串转double时的精度损失

  • 将字符串中小数点移动指定位,转成int类型,下面是字符创左右移动的函数。
//获取放大后的字符串
QString TimmingForm::getZoomIn(QString str,int n)
{
    QString zoomStr;
    int index =  str.indexOf(".");
    if(index < 0)
    {
        index=0;
        zoomStr = str;
    }
    else
    {
        zoomStr+= str.left(index);
        index = str.length()-index-1;
        zoomStr += str.right(index);
    }
    for(int i=0; i < (n - index); i++)
        zoomStr+="0";
    return  zoomStr;
};
//获取缩小后的字符串
QString TimmingForm::getZoomOut(QString str,int n)
{
    if(str.isEmpty())
        return "";
    QString zoomStr = str;
    if(str.left(1) == "-")
    {
        zoomStr.remove(0,1);
    }
    if(n >0)
    {
        if(zoomStr.length() <= n)
        {
            int len = (n +1 - zoomStr.length() );
            for(int i =0 ; i < len;i++)
                zoomStr = "0"+zoomStr;
        }
        if(zoomStr.length() > n)
        {
            int index = zoomStr.length()-n;
            zoomStr.insert(index,".");
            for(int i =0 ;i < zoomStr.length(); i++)
            {
                index = zoomStr.length()-1- i;
                if(index < 0)
                    break;
                if(zoomStr.mid(index,1) == "0")
                {
                    zoomStr.remove(index,1);
                    i--;
                }
                else if(zoomStr.mid(index,1) == ".")
                {
                    zoomStr.remove(index,1);
                    break;
                }
                else
                {
                    break;
                }
            }
        }
    }
    if(str.left(1) == "-")
    {
        zoomStr.insert(0,"-");
    }
    return  zoomStr;
};

添加文件读写功能

  • 从文件读取参数,构造lcd_param结构体,然后存储到list链表中,并在comm中添加此选项名称

  • 从comm选择选项个数,从list获取对应参数,覆盖写入文件中。

    void TimmingForm::loadFileToCombo()
    {
        update_lineEdit_TimeData();
        update_lineEdit_ParamData();
        update_lineEdit_TimmingData();
        QString itemName;
        struct lcd_param *lcd;
        QString fileName = "./timming.txt";
        ui->statusBar->setText("提示信息:loadFileToCombo");
        QFile file(fileName);
        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
            return;
    
        QTextStream stream(&file);
        while(!stream.atEnd())
        {
            lcd = new struct lcd_param;
            stream >> itemName >> lcd->name;
            stream >> itemName >> lcd->param_pclk;
            stream >> itemName >> lcd->param_vt;
            stream >> itemName >> lcd->param_vBlank;
            stream >> itemName >> lcd->param_vActive;
            stream >> itemName >> lcd->param_vb;
            stream >> itemName >> lcd->param_vf;
            stream >> itemName >> lcd->param_vs;
            stream >> itemName >> lcd->param_ht;
            stream >> itemName >> lcd->param_hBlank;
            stream >> itemName >> lcd->param_hActive;
            stream >> itemName >> lcd->param_hb;
            stream >> itemName >> lcd->param_hf;
            stream >> itemName >> lcd->param_hs;
            stream >> itemName >> lcd->param_hs_hps;
            stream >> itemName >> lcd->param_vs_fps;
            stream >> itemName >> lcd->param_t5_hbp;
            stream >> itemName >> lcd->param_t5_hspw;
            stream >> itemName >> lcd->param_t5_vbp;
            stream >> itemName >> lcd->param_t5_vspw;
    
            if( lcd->param_pclk != 0 && lcd->param_vt != 0 && lcd->param_ht != 0 )
            {
                list.append(lcd);
                ui->comboBox->addItem(lcd->name);
            }
        }
        file.close();
    
    }
    
    void TimmingForm::saveComboToFile()
    {
        struct lcd_param *lcd;
        ui->statusBar->setText("提示信息:saveComboToFile");
        if( ui->comboBox->count() <= 0 )
        {
            ui->statusBar->setText("Combo is empty, not save param");
            return;
        }
    
        QString fileName = "./timming.txt";
        QFile file(fileName);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
            return;
    
        qDebug() << "comboBox->count()=" << ui->comboBox->count() << "  list.count()=" <<  list.count();
        QTextStream stream(&file);
        for( int i = 0; i < ui->comboBox->count() && i < list.count(); i++ )
        {
    
            lcd = list.at(i);
            stream << "param_name " << lcd->name << "\\n";
            stream << "param_pclk " << lcd->param_pclk << "\\n";
            stream << "param_vt " << lcd->param_vt << "\\n";
            stream << "param_vBlank " << lcd->param_vBlank << "\\n";
            stream << "param_vActive " << lcd->param_vActive << "\\n";
            stream << "param_vb " << lcd->param_vb << "\\n";
            stream << "param_vf " << lcd->param_vf << "\\n";
            stream << "param_vs " << lcd->param_vs << "\\n";
            stream << "param_ht " << lcd->param_ht << "\\n";
            stream << "param_hBlank " << lcd->param_hBlank << "\\n";
            stream << "param_hActive " << lcd->param_hActive << "\\n";
            stream << "param_hb " << lcd->param_hb << "\\n";
            stream << "param_hf " << lcd->param_hf << "\\n";
            stream << "param_hs " << lcd->param_hs << "\\n";
            stream << "param_hs_hps " << lcd->param_hs_hps << "\\n";
            stream << "param_vs_fps " << lcd->param_vs_fps << "\\n";
            stream << "param_t5_hbp " << lcd->param_t5_hbp << "\\n";
            stream << "param_t5_hspw " << lcd->param_t5_hspw << "\\n";
            stream << "param_t5_vbp " << lcd->param_t5_vbp << "\\n";
            stream << "param_t5_vspw " << lcd->param_t5_vspw << "\\n";
        }
        file.close();
    }
    
  • 存储下来的文件示例 479.885x720.811@59.9302

    param_name 0_479.885x720.811@59.9302
    param_pclk 2.7027e+07
    param_vt 525.05
    param_vBlank 45.1652
    param_vActive 479.885
    param_vb 30.1446
    param_vf 9.01967
    param_vs 6.00094
    param_ht 858.919
    param_hBlank 138.108
    param_hActive 720.811
    param_hb 59.5946
    param_hf 16.0811
    param_hs 62.4324
    param_hs_hps 31466.3
    param_vs_fps 59.9302
    param_t5_hbp 122.027
    param_t5_hspw 62.4324
    param_t5_vbp 36.1455
    param_t5_vspw 6.00094
    

以上是关于[AssistantTool]_10_时序计算面板的主要内容,如果未能解决你的问题,请参考以下文章

[AssistantTool]_10_时序计算面板

[AssistantTool]_2_修改TAB样式

[AssistantTool]_2_修改TAB样式

[AssistantTool]_1_创建工程

[AssistantTool]_1_创建工程

[AssistantTool]_3_添加TAB示例