bloguetronica / cp2130-conf

CP2130 Configurator (cp2130-conf) is an application that can be used to configure CP2130 devices, including VID, PID, as well as other descriptors. Most importantly, the application allows you to configure pin functions and states.
GNU General Public License v3.0
1 stars 1 forks source link

ConfiguratorWindow::on_actionInformation_triggered() requires refactoring #26

Closed samuelfmlourenco closed 1 year ago

samuelfmlourenco commented 1 year ago

In the present moment, inside "configuratorwindow.cpp", from lines 98 to 111, we have on_actionInformation_triggered() implemented as follows:

void ConfiguratorWindow::on_actionInformation_triggered()
{
    int errcnt = 0;
    QString errstr;
    InformationDialog infoDialog;
    CP2130::SiliconVersion siversion = cp2130_.getSiliconVersion(errcnt, errstr);
    infoDialog.setSiliconVersionLabelText(siversion.maj, siversion.min);
    opCheck(tr("device-information-retrieval-op"), errcnt, errstr);  // The string "device-information-retrieval-op" should be translated to "Device information retrieval"
    if (err_) {  // Fix implemented in version 1.2
        handleError();
    } else {  // If error check passes
        infoDialog.exec();
    }
}

However, in this particular case, we can declare and assign infoDialog if and only if opCheck() passes. Thus, it is possible to refactor the above function, like this:

void ConfiguratorWindow::on_actionInformation_triggered()
{
    int errcnt = 0;
    QString errstr;
    CP2130::SiliconVersion siversion = cp2130_.getSiliconVersion(errcnt, errstr);
    opCheck(tr("device-information-retrieval-op"), errcnt, errstr);  // The string "device-information-retrieval-op" should be translated to "Device information retrieval"
    if (err_) {  // Fix implemented in version 1.2
        handleError();
    } else {  // If error check passes
        InformationDialog infoDialog;
        infoDialog.setSiliconVersionLabelText(siversion.maj, siversion.min);
        infoDialog.exec();
    }
}
samuelfmlourenco commented 1 year ago

Refactored in version 1.5.