"Fossies" - the Fresh Open Source Software Archive

Member "cppcheck-1.89/gui/showtypes.cpp" (1 Sep 2019, 3830 Bytes) of package /windows/misc/cppcheck-1.89.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "showtypes.cpp" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Cppcheck - A tool for static C/C++ code analysis
    3  * Copyright (C) 2007-2016 Cppcheck team.
    4  *
    5  * This program is free software: you can redistribute it and/or modify
    6  * it under the terms of the GNU General Public License as published by
    7  * the Free Software Foundation, either version 3 of the License, or
    8  * (at your option) any later version.
    9  *
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  *
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   17  */
   18 
   19 #include <QSettings>
   20 #include "common.h"
   21 #include "showtypes.h"
   22 #include "errorlogger.h"
   23 
   24 ShowTypes::ShowTypes()
   25 {
   26     load();
   27 }
   28 
   29 ShowTypes::~ShowTypes()
   30 {
   31     save();
   32 }
   33 
   34 ShowTypes::ShowType ShowTypes::SeverityToShowType(Severity::SeverityType severity)
   35 {
   36     switch (severity) {
   37     case Severity::none:
   38         return ShowTypes::ShowNone;
   39     case Severity::error:
   40         return ShowTypes::ShowErrors;
   41     case Severity::style:
   42         return ShowTypes::ShowStyle;
   43     case Severity::warning:
   44         return ShowTypes::ShowWarnings;
   45     case Severity::performance:
   46         return ShowTypes::ShowPerformance;
   47     case Severity::portability:
   48         return ShowTypes::ShowPortability;
   49     case Severity::information:
   50         return ShowTypes::ShowInformation;
   51     default:
   52         return ShowTypes::ShowNone;
   53     }
   54 }
   55 
   56 Severity::SeverityType ShowTypes::ShowTypeToSeverity(ShowTypes::ShowType type)
   57 {
   58     switch (type) {
   59     case ShowTypes::ShowStyle:
   60         return Severity::style;
   61 
   62     case ShowTypes::ShowErrors:
   63         return Severity::error;
   64 
   65     case ShowTypes::ShowWarnings:
   66         return Severity::warning;
   67 
   68     case ShowTypes::ShowPerformance:
   69         return Severity::performance;
   70 
   71     case ShowTypes::ShowPortability:
   72         return Severity::portability;
   73 
   74     case ShowTypes::ShowInformation:
   75         return Severity::information;
   76 
   77     case ShowTypes::ShowNone:
   78     default:
   79         return Severity::none;
   80     }
   81 }
   82 
   83 ShowTypes::ShowType ShowTypes::VariantToShowType(const QVariant &data)
   84 {
   85     const int value = data.toInt();
   86     if (value < ShowTypes::ShowStyle || value > ShowTypes::ShowErrors) {
   87         return ShowTypes::ShowNone;
   88     }
   89     return (ShowTypes::ShowType)value;
   90 }
   91 
   92 void ShowTypes::load()
   93 {
   94     QSettings settings;
   95     mVisible[ShowStyle] = settings.value(SETTINGS_SHOW_STYLE, true).toBool();
   96     mVisible[ShowErrors] = settings.value(SETTINGS_SHOW_ERRORS, true).toBool();
   97     mVisible[ShowWarnings] = settings.value(SETTINGS_SHOW_WARNINGS, true).toBool();
   98     mVisible[ShowPortability] = settings.value(SETTINGS_SHOW_PORTABILITY, true).toBool();
   99     mVisible[ShowPerformance] = settings.value(SETTINGS_SHOW_PERFORMANCE, true).toBool();
  100     mVisible[ShowInformation] = settings.value(SETTINGS_SHOW_INFORMATION, true).toBool();
  101 }
  102 
  103 void ShowTypes::save() const
  104 {
  105     QSettings settings;
  106     settings.setValue(SETTINGS_SHOW_STYLE, mVisible[ShowStyle]);
  107     settings.setValue(SETTINGS_SHOW_ERRORS, mVisible[ShowErrors]);
  108     settings.setValue(SETTINGS_SHOW_WARNINGS, mVisible[ShowWarnings]);
  109     settings.setValue(SETTINGS_SHOW_PORTABILITY, mVisible[ShowPortability]);
  110     settings.setValue(SETTINGS_SHOW_PERFORMANCE, mVisible[ShowPerformance]);
  111     settings.setValue(SETTINGS_SHOW_INFORMATION, mVisible[ShowInformation]);
  112 }
  113 
  114 bool ShowTypes::isShown(ShowTypes::ShowType category) const
  115 {
  116     return mVisible[category];
  117 }
  118 
  119 bool ShowTypes::isShown(Severity::SeverityType severity) const
  120 {
  121     return isShown(ShowTypes::SeverityToShowType(severity));
  122 }
  123 
  124 void ShowTypes::show(ShowTypes::ShowType category, bool showing)
  125 {
  126     mVisible[category] = showing;
  127 }