1 /*****************************************************************************
2  *   Copyright (C) 2004-2014 by Thomas Fischer <fischer@unix-ag.uni-kl.de>   *
3  *                                                                           *
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 2 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 <https://www.gnu.org/licenses/>.   *
17  *****************************************************************************/
18 
19 #include "guihelper.h"
20 
21 #include <QPainter>
22 #include <QPixmap>
23 
24 #include <KIconLoader>
25 
26 #include "logging_gui.h"
27 
selectValue(QAbstractItemModel * model,const QString & value,int role)28 int GUIHelper::selectValue(QAbstractItemModel *model, const QString &value, int role)
29 {
30     int row = 0;
31     QModelIndex index;
32     const QString lowerValue = value.toLower();
33     while (row < model->rowCount() && (index = model->index(row, 0, QModelIndex())) != QModelIndex()) {
34         QString line = model->data(index, role).toString();
35         if (line.toLower() == lowerValue)
36             return row;
37         ++row;
38     }
39 
40     qCWarning(LOG_KBIBTEX_GUI) << "Could not find matching row in model for value " << value << " in role" << role;
41 
42     return -1;
43 }
44