File indexing completed on 2024-05-19 05:35:17

0001 //////////////////////////////////////////////////////////////////////////////
0002 // oxygenexceptionmodel.cpp
0003 // -------------------
0004 //
0005 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0006 //
0007 // SPDX-License-Identifier: MIT
0008 //////////////////////////////////////////////////////////////////////////////
0009 
0010 #include "oxygenexceptionmodel.h"
0011 
0012 #include <KLocalizedString>
0013 
0014 namespace Oxygen
0015 {
0016 //_______________________________________________
0017 const QString ExceptionModel::m_columnTitles[ExceptionModel::nColumns] = {QStringLiteral(""), i18n("Exception Type"), i18n("Regular Expression")};
0018 
0019 //__________________________________________________________________
0020 QVariant ExceptionModel::data(const QModelIndex &index, int role) const
0021 {
0022     // check index, role and column
0023     if (!index.isValid())
0024         return QVariant();
0025 
0026     // retrieve associated file info
0027     const InternalSettingsPtr &configuration(get(index));
0028 
0029     // return text associated to file and column
0030     if (role == Qt::DisplayRole) {
0031         switch (index.column()) {
0032         case ColumnType: {
0033             switch (configuration->exceptionType()) {
0034             case InternalSettings::ExceptionWindowTitle:
0035                 return i18n("Window Title");
0036 
0037             default:
0038             case InternalSettings::ExceptionWindowClassName:
0039                 return i18n("Window Class Name");
0040             }
0041         }
0042 
0043         case ColumnRegExp:
0044             return configuration->exceptionPattern();
0045         default:
0046             return QVariant();
0047             break;
0048         }
0049 
0050     } else if (role == Qt::CheckStateRole && index.column() == ColumnEnabled) {
0051         return configuration->enabled() ? Qt::Checked : Qt::Unchecked;
0052 
0053     } else if (role == Qt::ToolTipRole && index.column() == ColumnEnabled) {
0054         return i18n("Enable/disable this exception");
0055     }
0056 
0057     return QVariant();
0058 }
0059 
0060 //__________________________________________________________________
0061 QVariant ExceptionModel::headerData(int section, Qt::Orientation orientation, int role) const
0062 {
0063     if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < nColumns) {
0064         return m_columnTitles[section];
0065     }
0066 
0067     // return empty
0068     return QVariant();
0069 }
0070 }