LCOV - code coverage report
Current view: top level - src/lib - pokitmeter.cpp (source / functions) Coverage Total Hit
Project: Dokit Lines: 92.5 % 80 74
Version: Functions: 100.0 % 6 6

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

Generated by: LCOV version 2.0-1