File indexing completed on 2024-11-24 04:34:14

0001 /***************************************************************************
0002  *   SPDX-License-Identifier: GPL-2.0-or-later
0003  *                                                                         *
0004  *   SPDX-FileCopyrightText: 2004-2021 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 #ifndef KBIBTEX_DATA_FILEMODEL_H
0021 #define KBIBTEX_DATA_FILEMODEL_H
0022 
0023 #include <QAbstractItemModel>
0024 #include <QLatin1String>
0025 #include <QList>
0026 #include <QStringList>
0027 
0028 #include <NotificationHub>
0029 #include <Element>
0030 
0031 #ifdef HAVE_KF
0032 #include "kbibtexdata_export.h"
0033 #endif // HAVE_KF
0034 
0035 class File;
0036 class Entry;
0037 
0038 /**
0039 @author Thomas Fischer
0040  */
0041 class KBIBTEXDATA_EXPORT FileModel : public QAbstractTableModel, private NotificationListener
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     static const int NumberRole;
0047     static const int SortRole;
0048 
0049     explicit FileModel(QObject *parent = nullptr);
0050 
0051     File *bibliographyFile() const;
0052     virtual void setBibliographyFile(File *file);
0053 
0054     QModelIndex parent(const QModelIndex &index) const override;
0055     bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
0056     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0057     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0058     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0059     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0060     Qt::ItemFlags flags(const QModelIndex &index) const override;
0061 
0062     void clear();
0063     virtual bool removeRow(int row, const QModelIndex &parent = QModelIndex());
0064     bool removeRowList(const QList<int> &rows);
0065     bool insertRow(QSharedPointer<Element> element, int row, const QModelIndex &parent = QModelIndex());
0066 
0067     QSharedPointer<Element> element(int row) const;
0068     int row(QSharedPointer<Element> element) const;
0069     /// Notifies the model that a given element has been modifed
0070     void elementChanged(int row);
0071 
0072     void notificationEvent(int eventId) override;
0073 
0074 Q_SIGNALS:
0075     void bibliographySystemChanged();
0076 
0077 private:
0078     File *m_file;
0079     QMap<QString, QString> colorToLabel;
0080 
0081     void readConfiguration();
0082     static QString leftSqueezeText(const QString &text, int n);
0083     QString entryText(const Entry *entry, const QString &raw, const QString &rawAlt, const QStringList &rawAliases, int role, bool followCrossRef) const;
0084 };
0085 
0086 #endif // KBIBTEX_DATA_FILEMODEL_H