File indexing completed on 2024-05-19 05:05:30

0001 /***************************************************************************
0002  *   SPDX-License-Identifier: GPL-2.0-or-later
0003  *                                                                         *
0004  *   SPDX-FileCopyrightText: 2004-2019 Thomas Fischer <fischer@unix-ag.uni-kl.de>
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; if not, see <https://www.gnu.org/licenses/>. *
0018  ***************************************************************************/
0019 
0020 #include "guihelper.h"
0021 
0022 #include <QPainter>
0023 #include <QPixmap>
0024 
0025 #include <KIconLoader>
0026 
0027 #include "logging_gui.h"
0028 
0029 int GUIHelper::selectValue(QAbstractItemModel *model, const QString &value, int role)
0030 {
0031     int row = 0;
0032     QModelIndex index;
0033     const QString lowerValue = value.toLower();
0034     while (row < model->rowCount() && (index = model->index(row, 0, QModelIndex())) != QModelIndex()) {
0035         QString line = model->data(index, role).toString();
0036         if (line.toLower() == lowerValue)
0037             return row;
0038         ++row;
0039     }
0040 
0041     qCWarning(LOG_KBIBTEX_GUI) << "Could not find matching row in model for value " << value << " in role" << role;
0042 
0043     return -1;
0044 }
0045 
0046 int GUIHelper::selectValue(QAbstractItemModel *model, const int value, int role)
0047 {
0048     int row = 0;
0049     QModelIndex index;
0050     while (row < model->rowCount() && (index = model->index(row, 0, QModelIndex())) != QModelIndex()) {
0051         const int lineValue = model->data(index, role).toInt();
0052         if (lineValue == value)
0053             return row;
0054         ++row;
0055     }
0056 
0057     qCWarning(LOG_KBIBTEX_GUI) << "Could not find matching row in model for value " << value << " in role" << role;
0058 
0059     return -1;
0060 }