Changeset - ccdd0ce1b556
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-10-10 11:55:51
hy@ozderya.net
check integrity of the command
2 files changed with 36 insertions and 2 deletions:
0 comments (0 inline, 0 general)
commandwidget.cpp
Show inline comments
 
@@ -48,10 +48,38 @@ void CommandWidget::onDeleteClicked()
 

	
 
void CommandWidget::onSendClicked()
 
{
 
    emit sendCommand(ui->leCommand->text(), ui->pbASCII->isChecked());
 
    auto command = ui->leCommand->text();
 

	
 
    if (command.isEmpty())
 
    {
 
        qWarning() << "Enter a command to send!";
 
        ui->leCommand->setFocus(Qt::OtherFocusReason);
 
        return;
 
    }
 

	
 
    if (!isASCIIMode()) // hex mode
 
    {
 
        command = command.remove(' ');
 
        // check if nibbles are missing
 
        if (command.size() % 2 == 1)
 
        {
 
            qWarning() << "HEX command is missing a nibble at the end!";
 
            ui->leCommand->setFocus(Qt::OtherFocusReason);
 
            int textSize = ui->leCommand->text().size();
 
            ui->leCommand->setSelection(textSize-1, textSize);
 
            return;
 
        }
 
    }
 

	
 
    emit sendCommand(command, ui->pbASCII->isChecked());
 
}
 

	
 
void CommandWidget::onASCIIToggled(bool checked)
 
{
 
    ui->leCommand->setMode(checked);
 
}
 

	
 
bool CommandWidget::isASCIIMode()
 
{
 
    return ui->pbASCII->isChecked();
 
}
commandwidget.h
Show inline comments
 
@@ -37,10 +37,16 @@ public:
 

	
 
signals:
 
    void deleteRequested(CommandWidget* thisWidget); // emitted when delete button is clicked
 
    void sendCommand(QString command, bool ascii);   // emitted when send button clicked
 

	
 
    // emitted when send button is clicked
 
    //
 
    // in case of hex mode, command text should be a hexadecimal
 
    // string containing hexadecimal characters only (not even spaces)
 
    void sendCommand(QString command, bool ascii);
 

	
 
private:
 
    Ui::CommandWidget *ui;
 
    bool isASCIIMode(); // true: ascii mode, false hex mode
 

	
 
private slots:
 
    void onDeleteClicked();
0 comments (0 inline, 0 general)