SSD4 实验二 《UAR 组件》

目录

1.需求分析

主要功能:

具体功能(具有与用户交互性的提示性的标识):

1.显示所选 UAR 组件内容的描述 :

2.在显示的 UAR 组件内容说明中搜索关键字或短语

2.概要设计

1):首先确定开发工具:

2):数据结构定义:

3).具体功能的概要设计:

3.详细设计(分模块介绍)

1).设置焦点功能和全选内容:

 2).警告框功能:

 3).带确定和取消事件的警告框功能:

4).判断子串串是否在字符串中,及记录其首次出现,最后一次出现,出现次数

5).如果文本框1内容改变,那么文本浏览器的内容要消失

 6).快捷键,ui界面直接设置

 4.调试分析

 1).查询了一些QMessageBox的用法,知道了怎样添加确定和取消按钮的事件。

2).查询了焦点应该怎么设置,学习了焦点的设置方法

5.用户使用说明

6.测试结果(只展示部分)

1).输错lineEdit1的内容,,点击display:

2).没有找到lineEdit2中的内容,点击Search

3).在2中点击确认:

4).找到了内容:

5).鼠标悬停在按钮上

 7.附录


1.需求分析

本实验的需求分析就是为了完全拷贝一个图形化界面,并实现其功能。如下所示:

程序所要实现功能的详细阐述:

主要功能:

  1. 当用户通过编号选择 UAR 组件时,应用程序应该显示组件内容的描述;
  2. 当用户指定关键字或短语时,应用程序应该在显示的描述中搜索该关键字或短语的出现次数,并显示出现次数的计数以及第一次和最后一次出现的位置,以描述开头的偏移数表示。

具体功能(具有与用户交互性的提示性的标识):

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

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

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

2.在显示的 UAR 组件内容说明中搜索关键字或短语

• 当用户输入一个关键字,并且该关键字出现在当前显示在输出文本框中的内容描述中时,应用程序应该显示

o 关键字第一次出现的位置(描述开头的字符数偏移量);

o 关键字最后一次出现的位置(描述开头的字符数偏移量);

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

述中搜索不同的关键字。

• 当用户输入一个关键字,而该关键字并没有出现在当前显示在输出文本框中的内容描述中,应用程序应该会显示出来

o 一个消息框通知用户没有找到该字符串,并询问用户是否想要搜索相同的描述以寻找不 同的关键字。

• 当用户点击“搜索”按钮但没有输入关键字时,应用程序应该

o 显示一个提示用户输入关键字的消息框;

o 在用户确认提示后,引导用户输入关键字的位置。

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

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

• 当用户输入关键字且当前没有显示 UAR 组件内容描述时,应用程序应该

o 显示消息框,提示用户选择要搜索的 UAR 组件内容描述;

o 指导用户如何继续使用应用程序,即如果没有输入组件编号,应用程序应将焦点设置为

默认文本框;否则,应用程序应该将焦点设置为“显示”按钮。

2.概要设计

1):首先确定开发工具:

还是依照习惯,采用了Qt 5.12.1开发,语言是C++。

2):数据结构定义:

实验比较简单,没有采取特别的抽象的数据结构,仅仅是使用了Qt自带的组件,组件如下:

其次,定义了几个QString类型的变量,用来存储7个字符串,并用state来表示当前所选中的字符串是哪一个。

 

3).具体功能的概要设计:

  1. display按钮点击事件的实现逻辑:

2.search按钮点击事件的实现逻辑:

3.详细设计(分模块介绍)

1).设置焦点功能和全选内容:

   例如:

ui->lineEdit->setFocus();
ui->lineEdit->selectAll();

 2).警告框功能:

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

 3).带确定和取消事件的警告框功能:

        ui->lineEdit_2->setFocus();
        ui->lineEdit_2->selectAll();
        QMessageBox box;
        box.setWindowTitle(tr("Search String"));
        box.setIcon(QMessageBox::Warning);
        QString s="string:'"+str+"'not found";
        QString s2="Search same text again?";
        QString hh="\n";//利用append()函数在字符串后添加换行
        box.setText(s.append(hh)+s2);
        QPushButton *agreeBut=box.addButton(tr("确认"),QMessageBox::AcceptRole);
        QPushButton *rejectBut=box.addButton(tr("取消"),QMessageBox::RejectRole);
        box.exec();
        if(box.clickedButton() == (QAbstractButton*)agreeBut)
        {
         box.close();
        }else if (box.clickedButton() == (QAbstractButton*)rejectBut) {
         ui->lineEdit->clear();
         ui->lineEdit_2->clear();
         ui->textBrowser->clear();
         ui->label_13->clear();
         ui->label_14->clear();
         box.close();
        }

4).判断子串串是否在字符串中,及记录其首次出现,最后一次出现,出现次数

    例如:

if (state==1) {
        for(int i=0;i<str1.length();i++){
            if (str.compare(str1.mid(i,str.length()),Qt::CaseInsensitive)==0){
                cnt++;
                if (cnt==1){
                    show1(1,i+1);
                }
                last=i+1;
            }
        }
        show2(cnt,last);
}

5).如果文本框1内容改变,那么文本浏览器的内容要消失

void MainWindow::on_lineEdit_textChanged(const QString &arg1)
{
    //这个逻辑描述一下,就是输入了,文本浏览器内容就会消失,同时状态被改变,相当于没有选中,除非点击展示按钮
    ui->textBrowser->clear();
    ui->lineEdit_2->clear();
    state=0;
}

 6).快捷键,ui界面直接设置

 

 4.调试分析

 1).查询了一些QMessageBox的用法,知道了怎样添加确定和取消按钮的事件。

2).查询了焦点应该怎么设置,学习了焦点的设置方法

5.用户使用说明

详情请见需求分析中的内容

6.测试结果(只展示部分)

1).输错lineEdit1的内容,,点击display:

2).没有找到lineEdit2中的内容,点击Search

3).在2中点击确认:

4).找到了内容:

5).鼠标悬停在按钮上

 

 7.附录

 mainwindow.h:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void Search(int state,QString str);
    void show1(int occur,int pos);
    void show2(int occur,int pos);

    void on_pushButton_3_clicked();

    void on_lineEdit_textChanged(const QString &arg1);

    void on_lineEdit_2_textChanged(const QString &arg1);

private:
    Ui::MainWindow *ui;
    QString str1;
    QString str2;
    QString str3;
    QString str4;
    QString str5;
    QString str6;
    QString str7;
    int state=0;
};

#endif // MAINWINDOW_H

mainwindow.cpp:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include<QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle(tr("UAR Components"));
    setWindowIcon(QIcon("images/ic.png"));
    menuBar()->setVisible(false);//隐藏菜单栏
    ui->mainToolBar->setVisible(false);//隐藏工具栏
    str1="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.";
    str2="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.";
    str3="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.";
    str4="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.";
    str5="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.";
    str6="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";
    str7="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.";
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QString line1 = ui->lineEdit->text();
    //三种比较QString是否相等的方法
    if (!(line1.compare("1")==0)&&!(line1.compare("2")==0)&&!(line1.compare("3")==0)&&!(line1.compare("4")==0)&&!(line1.compare("5")==0)&&!(line1.compare("6")==0)&&!(line1.compare("7")==0)){
        ui->lineEdit->setFocus();
        ui->lineEdit->selectAll();
        QMessageBox::warning(this,tr("Search String"),tr("Please enter values between 1 and 7"));
        state=0;
    }else if ((line1.compare("1")==0)) {
        ui->textBrowser->setText(str1);
        state=1;
        ui->lineEdit_2->setFocus();
        ui->lineEdit_2->selectAll();
    }else if((line1.compare("2")==0)){
        ui->textBrowser->setText(str2);
        state=2;
        ui->lineEdit_2->setFocus();
        ui->lineEdit_2->selectAll();
    }else if((line1.compare("3")==0)){
        ui->textBrowser->setText(str3);
        state=3;
        ui->lineEdit_2->setFocus();
        ui->lineEdit_2->selectAll();
    }else if((line1.compare("4")==0)){
        ui->textBrowser->setText(str4);
        state=4;
        ui->lineEdit_2->setFocus();
        ui->lineEdit_2->selectAll();
    }else if((line1.compare("5")==0)){
        ui->textBrowser->setText(str5);
        state=5;
        ui->lineEdit_2->setFocus();
        ui->lineEdit_2->selectAll();
    }else if((line1.compare("6")==0)){
        ui->textBrowser->setText(str6);
        state=6;
        ui->lineEdit_2->setFocus();
        ui->lineEdit_2->selectAll();
    }else if((line1.compare("7")==0)){
        ui->textBrowser->setText(str7);
        state=7;
        ui->lineEdit_2->setFocus();
        ui->lineEdit_2->selectAll();
    }
}

void MainWindow::on_pushButton_2_clicked()
{
    QString line2 = ui->lineEdit_2->text();
    Search(state,line2);
}

void MainWindow::Search(int state, QString str)
{
    int cnt=0;
    int last=0;
    if (state==0){
        if (ui->lineEdit->text().compare("")==0){
            ui->lineEdit->setFocus();
            qDebug()<<this->focusWidget()->objectName();
        }else{
            ui->pushButton->setFocus();
            qDebug()<<this->focusWidget()->objectName();
        }
        QMessageBox::warning(this,tr("Search String"),tr("Please select text"));
        return;
    }else if (str.compare("")==0) {
        QMessageBox::warning(this,tr("Search String"),tr("Please enter a search string!"));
        ui->lineEdit_2->setFocus();
        return;
    }else if (state==1) {
        for(int i=0;i<str1.length();i++){
            if (str.compare(str1.mid(i,str.length()),Qt::CaseInsensitive)==0){
                cnt++;
                if (cnt==1){
                    show1(1,i+1);
                }
                last=i+1;
            }
        }
        show2(cnt,last);
    }else if (state==2) {
        for(int i=0;i<str2.length();i++){
            if (str.compare(str2.mid(i,str.length()),Qt::CaseInsensitive)==0){
                cnt++;
                if (cnt==1){
                    show1(1,i+1);
                }
                last=i+1;
            }
        }
        show2(cnt,last);
    }else if (state==3) {
        for(int i=0;i<str3.length();i++){
            if (str.compare(str3.mid(i,str.length()),Qt::CaseInsensitive)==0){
                cnt++;
                if (cnt==1){
                    show1(1,i+1);
                }
                last=i+1;
            }
        }
        show2(cnt,last);
    }else if (state==4) {
        for(int i=0;i<str4.length();i++){
            if (str.compare(str4.mid(i,str.length()),Qt::CaseInsensitive)==0){
                cnt++;
                if (cnt==1){
                    show1(1,i+1);
                }
                last=i+1;
            }
        }
        show2(cnt,last);
    }else if (state==5) {
        for(int i=0;i<str5.length();i++){
            if (str.compare(str5.mid(i,str.length()),Qt::CaseInsensitive)==0){
                cnt++;
                if (cnt==1){
                    show1(1,i+1);
                }
                last=i+1;
            }
        }
        show2(cnt,last);
    }else if (state==6) {
        for(int i=0;i<str6.length();i++){
            if (str.compare(str6.mid(i,str.length()),Qt::CaseInsensitive)==0){
                cnt++;
                if (cnt==1){
                    show1(1,i+1);
                }
                last=i+1;
            }
        }
        show2(cnt,last);
    }else if (state==1) {
        for(int i=0;i<str7.length();i++){
            if (str.compare(str7.mid(i,str.length()),Qt::CaseInsensitive)==0){
                cnt++;
                if (cnt==1){
                    show1(1,i+1);
                }
                last=i+1;
            }
        }
        show2(cnt,last);
    }
    if (cnt==0){
        ui->lineEdit_2->setFocus();
        ui->lineEdit_2->selectAll();
        QMessageBox box;
        box.setWindowTitle(tr("Search String"));
        box.setIcon(QMessageBox::Warning);
        QString s="string:'"+str+"'not found";
        QString s2="Search same text again?";
        QString hh="\n";//利用append()函数在字符串后添加换行
        box.setText(s.append(hh)+s2);
        QPushButton *agreeBut=box.addButton(tr("确认"),QMessageBox::AcceptRole);
        QPushButton *rejectBut=box.addButton(tr("取消"),QMessageBox::RejectRole);
        box.exec();
        if(box.clickedButton() == (QAbstractButton*)agreeBut)
        {
         box.close();
        }else if (box.clickedButton() == (QAbstractButton*)rejectBut) {
         ui->lineEdit->clear();
         ui->lineEdit_2->clear();
         ui->textBrowser->clear();
         ui->label_13->clear();
         ui->label_14->clear();
         box.close();
        }
    }else{
        ui->lineEdit_2->setFocus();
        ui->lineEdit_2->selectAll();
        QMessageBox box;
        box.setWindowTitle(tr("Search String"));
        box.setIcon(QMessageBox::Warning);
        QString s="The number of occurences of '"+str+"' is:"+QString::number(cnt);
        QString s2="Search same text again?";
        QString hh="\n";//利用append()函数在字符串后添加换行
        box.setText(s.append(hh)+s2);
        QPushButton *agreeBut=box.addButton(tr("确认"),QMessageBox::AcceptRole);
        QPushButton *rejectBut=box.addButton(tr("取消"),QMessageBox::RejectRole);
        box.exec();
        if(box.clickedButton() == (QAbstractButton*)agreeBut)
        {
         box.close();
        }else if (box.clickedButton() == (QAbstractButton*)rejectBut) {
         ui->lineEdit->clear();
         ui->lineEdit_2->clear();
         ui->textBrowser->clear();
         ui->label_13->clear();
         ui->label_14->clear();
         ui->lineEdit->setFocus();
         box.close();
        }
    }
}


void MainWindow::show1(int occur, int pos)
{
    if (occur==0){
        return;
    }
  ui->label_13->setText("Occurrence"+QString::number(occur)+": Position: "+QString::number(pos));
}

void MainWindow::show2(int occur, int pos)
{
    if (occur==0){
        return;
    }
  ui->label_14->setText("Occurrence"+QString::number(occur)+": Position: "+QString::number(pos));
}

void MainWindow::on_pushButton_3_clicked()
{
    this->close();
}

void MainWindow::on_lineEdit_textChanged(const QString &arg1)
{
    //这个逻辑描述一下,就是输入了,文本浏览器内容就会消失,同时状态被改变,相当于没有选中,除非点击展示按钮
    ui->textBrowser->clear();
    ui->lineEdit_2->clear();
    state=0;
}

void MainWindow::on_lineEdit_2_textChanged(const QString &arg1)
{
    ui->label_13->clear();
    ui->label_14->clear();
}
  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值