LCOV - code coverage report
Current view: top level - src/lib - pokitmeter.cpp (source / functions) Coverage Total Hit
Project: Dokit Lines: 92.6 % 81 75
Version: Functions: 100.0 % 12 12

            Line data    Source code
       1              : // SPDX-FileCopyrightText: 2022-2024 Paul Colby <git@colby.id.au>
       2              : // SPDX-License-Identifier: LGPL-3.0-or-later
       3              : 
       4              : /*!
       5              :  * \file
       6              :  * Declares the PokitMeter namespace.
       7              :  */
       8              : 
       9              : #include "qtpokit/pokitmeter.h"
      10              : 
      11              : #include <QCoreApplication>
      12              : 
      13              : namespace PokitMeter {
      14              : 
      15              : namespace {
      16              :     class Private
      17              :     {
      18        11552 :         Q_DECLARE_TR_FUNCTIONS(PokitMeter)
      19              :     };
      20              : }
      21              : 
      22              : /// Returns \a range as a user-friendly string.
      23         4598 : QString toString(const CurrentRange &range)
      24         2972 : {
      25         7570 :     switch (range) {
      26          410 :     case CurrentRange::_10mA:     return Private::tr("Up to 10mA");
      27          410 :     case CurrentRange::_30mA:     return Private::tr("Up to 30mA");
      28         3252 :     case CurrentRange::_150mA:    return Private::tr("Up to 150mA");
      29          410 :     case CurrentRange::_300mA:    return Private::tr("Up to 300mA");
      30         2678 :     case CurrentRange::_2A:       return Private::tr("Up to 2A");
      31          410 :     case CurrentRange::AutoRange: return Private::tr("Auto-range");
      32            0 :     default:                      return QString();
      33         2972 :     }
      34         2972 : }
      35              : 
      36              : /*!
      37              :  *  Returns the maximum value for \a range in (integer) microamps, or the string "Auto".
      38              :  *  If \a range is not a known valid value, then an null QVariant is returned.
      39              :  */
      40         1938 : QVariant maxValue(const CurrentRange &range)
      41         2244 : {
      42         4182 :     switch (range) {
      43         1066 :     case CurrentRange::_10mA:     return    10'000;
      44          902 :     case CurrentRange::_30mA:     return    30'000;
      45         1312 :     case CurrentRange::_150mA:    return   150'000;
      46          492 :     case CurrentRange::_300mA:    return   300'000;
      47          328 :     case CurrentRange::_2A:       return 2'000'000;
      48           97 :     case CurrentRange::AutoRange: return Private::tr("Auto");
      49            0 :     default:                      return QVariant();
      50         2244 :     }
      51         2244 : }
      52              : 
      53              : /// Returns \a range as a user-friendly string.
      54         2052 : QString toString(const ResistanceRange &range)
      55         2208 : {
      56         4260 :     switch (range) {
      57          410 :     case ResistanceRange::_160:      return Private::tr("Up to 160Ω");
      58          410 :     case ResistanceRange::_330:      return Private::tr("Up to 330Ω");
      59          410 :     case ResistanceRange::_890:      return Private::tr("Up to 890Ω");
      60          410 :     case ResistanceRange::_1K5:      return Private::tr("Up to 1.5KΩ");
      61          734 :     case ResistanceRange::_10K:      return Private::tr("Up to 10KΩ");
      62          410 :     case ResistanceRange::_100K:     return Private::tr("Up to 100KΩ");
      63          656 :     case ResistanceRange::_470K:     return Private::tr("Up to 470KΩ");
      64          410 :     case ResistanceRange::_1M:       return Private::tr("Up to 1MΩ");
      65          410 :     case ResistanceRange::AutoRange: return Private::tr("Auto-range");
      66            0 :     default:                         return QString();
      67         2208 :     }
      68         2208 : }
      69              : 
      70              : /*!
      71              :  *  Returns the maximum value for \a range in (integer) ohms, or the string "Auto".
      72              :  *  If \a range is not a known valid value, then an null QVariant is returned.
      73              :  */
      74         3762 : QVariant maxValue(const ResistanceRange &range)
      75         4356 : {
      76         8118 :     switch (range) {
      77         1558 :     case ResistanceRange::_160:      return       160;
      78         1394 :     case ResistanceRange::_330:      return       330;
      79         1230 :     case ResistanceRange::_890:      return       890;
      80         1066 :     case ResistanceRange::_1K5:      return     1'500;
      81          902 :     case ResistanceRange::_10K:      return    10'000;
      82          738 :     case ResistanceRange::_100K:     return   100'000;
      83          820 :     case ResistanceRange::_470K:     return   470'000;
      84          328 :     case ResistanceRange::_1M:       return 1'000'000;
      85           97 :     case ResistanceRange::AutoRange: return Private::tr("Auto");
      86            0 :     default:                         return QVariant();
      87         4356 :     }
      88         4356 : }
      89              : 
      90              : /// Returns \a range as a user-friendly string.
      91         4788 : QString toString(const VoltageRange &range)
      92         3192 : {
      93         7980 :     switch (range) {
      94          984 :     case VoltageRange::_300mV:    return Private::tr("Up to 300mV");
      95         4946 :     case VoltageRange::_2V:       return Private::tr("Up to 2V");
      96          410 :     case VoltageRange::_6V:       return Private::tr("Up to 6V");
      97          410 :     case VoltageRange::_12V:      return Private::tr("Up to 12V");
      98          410 :     case VoltageRange::_30V:      return Private::tr("Up to 30V");
      99          410 :     case VoltageRange::_60V:      return Private::tr("Up to 60V");
     100          410 :     case VoltageRange::AutoRange: return Private::tr("Auto-range");
     101            0 :     default:                      return QString();
     102         3192 :     }
     103         3192 : }
     104              : 
     105              : /*!
     106              :  *  Returns the maximum value for \a range in (integer) millivolts, or the string "Auto".
     107              :  *  If \a range is not a known valid value, then an null QVariant is returned.
     108              :  */
     109         2546 : QVariant maxValue(const VoltageRange &range)
     110         2948 : {
     111         5494 :     switch (range) {
     112         1804 :     case VoltageRange::_300mV:    return    300;
     113         1066 :     case VoltageRange::_2V:       return  2'000;
     114          902 :     case VoltageRange::_6V:       return  6'000;
     115          738 :     case VoltageRange::_12V:      return 12'000;
     116          574 :     case VoltageRange::_30V:      return 30'000;
     117          328 :     case VoltageRange::_60V:      return 60'000;
     118           97 :     case VoltageRange::AutoRange: return Private::tr("Auto");
     119            0 :     default:                      return QVariant();
     120         2948 :     }
     121         2948 : }
     122              : 
     123              : }
        

Generated by: LCOV version 2.2-1