SSD4实验二 分析1、显示所选UAR组件内容的描述当用户输入一个有效的UAR组件列表号并单击“显示”按钮时,应用程序将在输出文本框中显示对该组件内容的描述。

1、需求分析

(1)显示所选UAR组件内容的描述 

• 当用户输入一个有效的UAR组件列表号并单击“显示”按钮时,应用程序将在输出文本框中显示对该组件内容的描述。

• 当用户输入无效输入值或根本不输入任何值并单击“显示”按钮时,应用程序会通知用户消息框中的错误,提示他们输入有效数字范围内的值(例如,“请输入值1到7”),当用户输入值时,会突出显示无效输入。

(2)搜索已显示的UAR组件内容描述中的关键字或短语

• 当用户输入关键字并且该关键字出现在当前显示在输出文本框中显示的内容 描述中时,应用程序应该显示关键字首次出现的位置(从描述开始的字符数的偏移量); 以及 关键字最后出现的位置(从描述开始的字符数的偏移量);

• 一个消息框,指示该关键字在内容描述中出现的次数,并询问用户是否希望在 相同的描述中搜索不同的关键字。

• 当用户输入一个关键字,并且该关键字不出现在当前显示在输出文本框中的内 容描述中时,应用程序应该显示出来 o.发送一个消息框,通知用户没有找到该字符串, 并询问用户是否想要搜索相同的描述和不同的关键字。

• 当用户点击“搜索”按钮,但没有输入关键字时,应用程序应该输入 显示一个 提示框,提示用户输入关键字;以及 在用户确认提示后,指示用户输入关键字。

• 如果用户想要在相同的描述中搜索不同的关键字,应用程序应该突出显示(即, 选择)之前在输入文本中输入的关键字,指导用户应该输入新的关键字;

• 否则,当用户不想搜索相同的描述时,应用程序应该清除两个输入文本框的内 容,并指导用户如何重新开始搜索过程;

• 当用户输入关键字并且当前没有显示UAR组件内容描述时,应用程序应该 显 示一个消息框,提示用户选择要搜索的UAR组件内容描述;以及 指导用户如何继续使 用该应用程序,即,如果没有输入组件编号,则该应用程序应将焦点设置为默认文本框; 否则,该应用程序应将焦点设置为“显示”按钮。

• 当用户点击“退出”按钮时,应用程序应该会关闭。

2、概要设计 

1、实验比较简单,未定义抽象数据类型

2、具体控件使用Qt软件自带的ui通过拖拽形成

3、显示模块

• 当在显示框中输入值1-7,并点显示按钮时,让右侧的文本栏中显示该数字对应的文本

• 点击显示按钮时,检测当显示的显示框中不符合要求时,设计一个警告框

• 设置一个监听器当显示框内的内容发生变化时,清空所有内容

4、搜索模块

• 点击搜索按钮时,检测右侧文本栏的内容和搜索框里的内容,如果为空,根据情况设计分别设置一个警告框

• 否则如果右侧的文本栏里不包含搜索框里的内容,就跳出一个消息框,可以选则继续搜索该内容或者换个内容搜索,如果换个内容则会清空所有内容

• 检测右侧的文本栏里不包含搜索框里的内容,就跳出一个消息框,可以选则继续搜索该内容或者换个内容搜索,如果换个内容则会清空所有内容

• 检测右侧的文本栏里包含搜索框里的内容,设计两个label来显示第一次和最后一次的坐标(如果只出现一次就不显示最后一次),并设计就跳出一个消息框,可以选择继续搜索该内容或者换个内容搜索,如果换个内容则会清空所有内容

5、焦点模块

• 进入界面时焦点在显示框中

• 点击显示按钮之后如果显示框中的内容不符合要求,焦点聚集在显示框中并全选显示框的内容

• 点击显示按钮之后如果显示框中的内容符合要求,焦点聚集在搜索框中

• 点击搜索按钮之后如果右侧文本栏里的内容为空且显示框为空,焦点聚集在显示框否则显示按钮上

• 点击搜索按钮之后如果右侧文本栏里的内容不为空,焦点聚集在显示框上

• 点击搜索按钮之后如果右侧文本栏内容不为空而搜索框为空则焦点聚集在搜索框

• 点击搜索按钮之后如果右侧文本栏内容不为空而搜索框为空则焦点聚集在搜索框

• 每次刷新界面后焦点聚集在显示框中

6、快捷键模块

• 分别设置显示和搜索按钮的快捷键,分别以ctrl+D和ctrl+S来表示

3、详细设计

1、显示模块

• 根据对应的数字显示相应的文本

2、搜索模块

• 由于该文本搜索时是不区分大小写的,不妨将文本框里和搜索框里的内容都当作小写

        QString s1=ui->textEdit->toPlainText();

        QString s2=ui->lineEdit_2->text();

        s1=s1.toLower();

        s2=s2.toLower(); 

       • 统计字符串出现次数

        int oldLength=s1.length();

        QString s0=s1;

        s0.replace(s2,"");

        int newLength=s0.length();

        int count=(oldLength-newLength)/s2.length();

        • 消息框设置

        QMessageBox msgbx(this);

        msgbx.setWindowTitle("Search String");

        msgbx.setText("The number of occurences of '"+s2+"'  is:"+a+'\n'+"Search same text?");

        msgbx.setStandardButtons(QMessageBox::Save|QMessageBox::Close) ;

        msgbx.button(QMessageBox::Save)->setText("是(Y)");

        msgbx.button(QMessageBox::Close)->setText("否(N)");

        int ret=msgbx.exec();

        if(ret==QMessageBox::Save)

        {

            ui->lineEdit_2->setFocus();

            ui->lineEdit_2->selectAll();;

        }

        if(ret==QMessageBox::Close)

        {

            ui->textEdit->clear();

            ui->lineEdit->clear();

            ui->lineEdit_2->clear();

            ui->label_13->clear();

            ui->label_14->clear();

            ui->lineEdit->setFocus();

        }

 3、焦点模块

 • 行编辑设置焦点

        ui->lineEdit_2->setFocus();

        • 设置选中

        ui->lineEdit_2->selectAll();

  • 按钮设置焦点

        ui->pushButton->setDefault(false);

 4、快捷键模块

4.调试分析

• 调试过程中遇到的问题是如何解决的以及对设计与实现的回顾讨论和分析;

刚开始不知道如何设置快捷键,在网上搜索最终发现Qt中可以直接在ui设计界面 手动设置,根本不需要代码

• 经验和体会

这个实验所要完成的功能很简单,但是其中设计的细节很多,比如遇到问题时设计 相应的消息提示框,出现相应变化之后光标的位置发生相应的变化,快捷键的设置 等,这些步骤看似麻烦,但其实都是为用户着想的体现,能让用户对该产品有着更 好的体验,以后在自己设计产品的时候也要学习这种思想,来让自己设计的软件对 用户更友好

5. 用户使用说明

1、在显示栏中输入1-7之间的数字

2、点击显示按钮

3、在搜索栏中输入想要搜索的字符串

4、点击搜索按钮

5、如果包含该字符串的话,在found后会出现第一次和最后一次出现的坐标(如果只出现一次不会出现最后一次),并出现消息对话框,点击是可以修改搜索内容,点击否会从步骤1开始

6、如果不包含该字符串,出现消息对话框,点击是可以修改搜索内容,点击否会从步骤1开始

6 .测试结果

  1. 显示框中输入合法内容,并点击显示按钮后

 

        2、显示框中输入不合法内容,并点击按钮,跳出警告框,并选中显示框中的内容且聚 焦于此

                

        3、当搜索框为空时,点击搜索按钮

 

        4、当文本框为空时而显示栏不为空时,点击搜索按钮

        5、当文本框为空时且显示栏为空时,点击搜索按钮

        6、当搜索不到内容时

》点击是

》点击否

8、当搜索到内容且出现不只一次

》点击是

》点击否

7.附录

1、ssd1test1.pro

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use

# any Qt feature that has been marked deprecated (the exact warnings

# depend on your compiler). Please consult the documentation of the

# deprecated API in order to know how to port your code away from it.

DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.

# In order to do so, uncomment the following line.

# You can also select to disable deprecated APIs only up to a certain version of Qt.

#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \

    main.cpp \

    mainwindow.cpp

HEADERS += \

    mainwindow.h

FORMS += \

    mainwindow.ui

# Default rules for deployment.

qnx: target.path = /tmp/$${TARGET}/bin

else: unix:!android: target.path = /opt/$${TARGET}/bin

!isEmpty(target.path): INSTALLS += target

2、mainwindow.h

#ifndef MAINWINDOW_H

#define MAINWINDOW_H

#include <QMainWindow>

QT_BEGIN_NAMESPACE

namespace Ui { class MainWindow; }

QT_END_NAMESPACE

class MainWindow : public QMainWindow

{

    Q_OBJECT

public:

    MainWindow(QWidget *parent = nullptr);

    ~MainWindow();

    QString getLineEdit1();

    QString getLineEdit2();

private slots:

    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void on_pushButton_3_clicked();

    void on_lineEdit_cursorPositionChanged(int arg1, int arg2);

    void on_lineEdit_textChanged(const QString &arg1);

private:

    Ui::MainWindow *ui;

};

#endif // MAINWINDOW_H

3、main.cpp

#include "mainwindow.h"

#include <QApplication>

int main(int argc, char *argv[])

{

    QApplication a(argc, argv);

    MainWindow w;

    w.show();

    return a.exec();

}

4、mainwindow.cpp

#include "mainwindow.h"

#include "ui_mainwindow.h"

#include<QMessageBox>

#include<QDebug>

MainWindow::MainWindow(QWidget *parent)

    : QMainWindow(parent)

    , ui(new Ui::MainWindow)

{

    ui->setupUi(this);

    ui->lineEdit->setFocus();

}

MainWindow::~MainWindow()

{

    delete ui;

}

QString MainWindow::getLineEdit1()

{

    return ui->lineEdit->text();

}

QString MainWindow::getLineEdit2()

{

    return ui->lineEdit_2->text();

}

void MainWindow::on_pushButton_clicked()

{

    if(ui->lineEdit->text()=="1")

    {

        ui->textEdit->setText("This should be a unique identifier for the purposes of filing. If more than one person is working on the project or more than one analysis technique is being used, this identifier could contain letters and numbers. For example, if Chris Smith and Jan Koo are both doing an analysis, the identifier might be CS1 or JK75. If both a heuristic evaluation and a think-aloud usability study were used, the identifiers might be HE6 or TA89. Follow the unique identifier with the word 'Problem,' if the report pertains to a usability problem of the interface, or the words 'Good Feature,' if it describes an aspect of the interface you feel should be preserved in any redesign.");

        ui->lineEdit_2->setFocus();

    }

    else if(ui->lineEdit->text()=="2")

    {

        ui->textEdit->setText("This description will be used as the 'name' of this UAR when you talk about its relation to other UARs. Make the name as short as possible (about three to five words) but still descriptive and distinguishable from other aspects of the system. If this UAR is about a problem (as opposed to a good feature), make sure you have a name that describes the problem, rather than a solution.");

        ui->lineEdit_2->setFocus();

    }

    else if(ui->lineEdit->text()=="3")

    {

        ui->textEdit->setText("This is the objective supporting material that justifies your identifying the aspect as worthy of report. This section needs to contain enough information for a reader of this UAR to understand what triggered the report. For an HE report, for instance, this could be an image of a cluttered screen and the heuristic about aesthetics and minimalist design. In a think-aloud study this is usually what was on the screen (a screen shot or description), what the user did (keystrokes, mouse movements), what the system did in response to any user actions, and what the user said. You need to include enough pertinent information about the identification of an aspect for the reader to understand what the analyst was thinking when the aspect was identified (for HE) or what the user was trying to do when the aspect either hindered or facilitated his or her progress.");

        ui->lineEdit_2->setFocus();

    }

    else if(ui->lineEdit->text()=="4")

    {

        ui->textEdit->setText("This is your interpretation of the evidence. That is, for a think-aloud usability test, why you think what happened happened, or, for an HE, why you think the aspect was designed the way it was. You need to provide enough content in this explanation for the reader to understand the problem-even if they do not know the system or domain as well as you do.");

        ui->lineEdit_2->setFocus();

    }

    else if(ui->lineEdit->text()=="5")

    {

        ui->textEdit->setText("This is your reasoning about how important it is to either fix this problem or preserve this good feature. This includes how frequently the users will experience this aspect, whether they are likely to learn how it works, whether it will affect new users, casual users, experienced users, etc.");

        ui->lineEdit_2->setFocus();

    }

    else if(ui->lineEdit->text()=="6")

    {

        ui->textEdit->setText("If this aspect is a problem (as opposed to a good feature to be preserved in the next version of the software), this is the place to propose a solution. It is not necessary to have a solution as soon as you identify a problem-you might find after analyzing the whole interface that many problems are related and can all be fixed by making a single broad change instead of making several small changes. However, if you do propose a possible solution, report any potential design trade-offs that you see");

        ui->lineEdit_2->setFocus();

    }

    else if(ui->lineEdit->text()=="7")

    {

        ui->textEdit->setText("It is often the case that UARs are related to each other. This is where you record which UARs this one is related to and a statement about how it is related. Make sure that all the related UARs point to each other. It is a common mistake to enter the pointer into a newly created UAR, but neglect to go back to the previous ones that it relates to and update their UARs.");

        ui->lineEdit_2->setFocus();

    }

    else

    {

        QMessageBox::warning(this,"Search String","Please enter values between 1 and 7","确定");

        ui->lineEdit->selectAll();

        ui->lineEdit->setFocus();

    }

}

void MainWindow::on_pushButton_2_clicked()

{

    QString s1=ui->textEdit->toPlainText();

    QString s2=ui->lineEdit_2->text();

    //显然给出的实例中是不区分大小写的

    s1=s1.toLower();

    s2=s2.toLower();

    qDebug()<<s1;

    //如果右侧文本栏里的内容为空且显示框为空,焦点聚集在显示框否则显示按钮上

    if(s1==""&&ui->lineEdit->text()=="")

    {

        QMessageBox::warning(this,"Search String","Please select text");

        ui->lineEdit->setFocus();

    }

    else if (s1==""&&ui->lineEdit->text()!="")

    {

      QMessageBox::warning(this,"Search String","Please select text");

      ui->pushButton->setDefault(true);

    }

    //如果搜索框为空,焦点聚集在搜索框中

    else if(s2=="")

    {

        QMessageBox::warning(this,"Search String","Please enter a search string");

        ui->lineEdit_2->setFocus();

    }

    else if(!s1.contains(s2))

    {/*

        QMessageBox::warning(this,"Search String","String '"+s2+"' not found"+'\n'+"Search same text again?","是(Y)","否(N)");*/

        QMessageBox msgbx(this);

        msgbx.setWindowTitle("Search String");

        msgbx.setText("String '"+s2+"' not found"+'\n'+"Search same text again?");

        msgbx.setStandardButtons(QMessageBox::Save|QMessageBox::Close);

        msgbx.button(QMessageBox::Save)->setText("是(Y)");

        msgbx.button(QMessageBox::Close)->setText("否(N)");

        int ret=msgbx.exec();

        if(ret==QMessageBox::Save)

        {

            ui->lineEdit_2->setFocus();

            ui->lineEdit_2->selectAll();

        }

        if(ret==QMessageBox::Close)

        {

            ui->textEdit->clear();

            ui->lineEdit->clear();

            ui->lineEdit_2->clear();

            ui->label_13->clear();

            ui->label_14->clear();

            ui->lineEdit->setFocus();

        }

    }

    else

    {

        //统计指定字符串出现的次数

        int oldLength=s1.length();

        QString s0=s1;

        s0.replace(s2,"");

        int newLength=s0.length();

        int count=(oldLength-newLength)/s2.length();

        char a[10];

        char b[10];

        char c[10];

        itoa(count,a,10);

        //根据提供的可执行文件可知下标从一开始

        itoa(s1.indexOf(s2)+1,b,10);

        itoa(s1.lastIndexOf(s2)+1,c,10);

        //根据count的值来判断label内容

        if(count==1)

        {

            ui->label_13->setText(tr("Occurrence 1:Position:")+b);

        }

        else

        {

            ui->label_14->setText(tr("Occurrence ")+a+tr(":Position:")+c);

            ui->label_13->setText(tr("Occurrence 1:Position:")+b);

        }

        QMessageBox msgbx(this);

        msgbx.setWindowTitle("Search String");

        msgbx.setText("The number of occurences of '"+s2+"' is:"+a+'\n'+"Search same text?");

        msgbx.setStandardButtons(QMessageBox::Save|QMessageBox::Close);

        msgbx.button(QMessageBox::Save)->setText("是(Y)");

        msgbx.button(QMessageBox::Close)->setText("否(N)");

        int ret=msgbx.exec();

        if(ret==QMessageBox::Save)

        {

            ui->lineEdit_2->setFocus();

            ui->lineEdit_2->selectAll();;

        }

        if(ret==QMessageBox::Close)

        {

            ui->textEdit->clear();

            ui->lineEdit->clear();

            ui->lineEdit_2->clear();

            ui->label_13->clear();

            ui->label_14->clear();

            ui->lineEdit->setFocus();

        }

    }

}

void MainWindow::on_pushButton_3_clicked()

{

    this->close();

}

void MainWindow::on_lineEdit_cursorPositionChanged(int arg1, int arg2)

{

    ui->pushButton->setDefault(false);

}

void MainWindow::on_lineEdit_textChanged(const QString &arg1)

{

    ui->textEdit->clear();

    ui->label_13->clear();

    ui->label_14->clear();

    ui->lineEdit_2->clear();

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值