"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2bCiterModel.h" (12 Feb 2021, 7611 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


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 "c2bCiterModel.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #ifndef C2BCITERMODEL_H
    8 #define C2BCITERMODEL_H
    9 
   10 #include "c2bCiter.h"
   11 #include "c2bCiterHistory.h"
   12 
   13 #include <collectionAnalyzer.h>
   14 
   15 #include <QAbstractTableModel>
   16 #include <QColor>
   17 #include <QHash>
   18 #include <QStringList>
   19 #include <QVector>
   20 
   21 
   22 class c2bCiterModel : public QAbstractTableModel
   23 {
   24 
   25     Q_OBJECT
   26 
   27 public:
   28     explicit c2bCiterModel(QObject* parento = 0);
   29     inline ~c2bCiterModel() {}
   30 
   31     QList<int> sizeHintForColumns() const;
   32     QStringList dataSelectedCiteIds() const;
   33     QVariant data(const QModelIndex& i, int role = Qt::DisplayRole) const;
   34     c2bCiter::State currentState(const QModelIndex& current_index) const;
   35     void clearCurrentFilter(QModelIndex* current_index);
   36     void clearSelection();
   37     void loadCitations(const QString& fn);
   38     void loadCitations(const QStringList& fns);
   39     void reloadCitations(const QStringList& fns, const c2bCiter::State& state, QModelIndex* current_index);
   40     void restoreNextState(QModelIndex* current_index);
   41     void restorePreviousState(QModelIndex* current_index);
   42     void restoreState(const c2bCiter::State& s, QModelIndex* current_index);
   43     void setDocumentFilter(const QString& documentfn, QModelIndex* current_index);
   44     void setGlossaryView(QModelIndex* current_index);
   45     void setKeywordFilter(const QString& keyword, QModelIndex* current_index);
   46     void setPatternFilter(const QString& pattern, QModelIndex* current_index, const c2bCiter::Format format);
   47     void setRelatedFilter(const QString& documentfn, QModelIndex* current_index,
   48                           const c2bCiter::Format format = c2bCiter::R);
   49     void setSelectedFilter(QModelIndex* current_index);
   50     void updateFormat(const c2bCiter::Format format, QModelIndex* current_index);
   51 
   52     inline QString dataBibTeXPosition(const QModelIndex& i) const
   53     {
   54         if (_is_index_valid(i))
   55             return _bibtex_position.at(_offset(i.row()));
   56         else
   57             return QString();
   58     }
   59     inline QString dataBibTeXFile(const QModelIndex& i) const
   60     {
   61         return dataBibTeXPosition(i).remove(QRegExp(":(\\d+)$"));
   62     }
   63     inline QString dataFile(const QModelIndex& i) const
   64     {
   65         if (_is_index_valid(i))
   66             return _file.key(_offset(i.row()));
   67         else
   68             return QString();
   69     }
   70     inline QString dataUrl(const QModelIndex& i) const
   71     {
   72         if (_is_index_valid(i))
   73             return _url.at(_offset(i.row()));
   74         else
   75             return QString();
   76     }
   77     inline QString dataKeyword(const QModelIndex& i) const
   78     {
   79         if (_format == c2bCiter::K && _is_index_valid(i))
   80             return _analyzer.sentence(_offset(i.row()));
   81         else
   82             return QString();
   83     }
   84     inline c2bCiter::KeywordData keywordData(const QModelIndex& i) const
   85     {
   86         c2bCiter::KeywordData kd;
   87         if (_filter == c2bCiter::Document && _format == c2bCiter::K)
   88         {
   89             kd.bibtexfn = QString(_bibtex_position.at(_file.value(_fstring))).remove(QRegExp(":(\\d+)$"));
   90             kd.documentfn = _fstring;
   91             kd.keyword = dataKeyword(i);
   92         }
   93         else if (_filter == c2bCiter::Keyword)
   94         {
   95             kd.bibtexfn = dataBibTeXFile(i);
   96             kd.documentfn = dataFile(i);
   97             kd.keyword = _fstring;
   98         }
   99         kd.valid = !kd.bibtexfn.isEmpty() && !kd.documentfn.isEmpty() && !kd.keyword.isEmpty();
  100         return kd;
  101     }
  102     inline bool isKeywordView() const
  103     {
  104         return _format == c2bCiter::K;
  105     }
  106     inline Qt::ItemFlags flags(const QModelIndex& /* i */) const
  107     {
  108         return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
  109     }
  110     inline int count() const
  111     {
  112         return _row_count;
  113     }
  114     inline int rowCount(const QModelIndex& /* parent */ = QModelIndex()) const
  115     {
  116         return _row_count;
  117     }
  118     inline int columnCount(const QModelIndex& /* parent */ = QModelIndex()) const
  119     {
  120         return _column_count;
  121     }
  122     inline c2bCiter::Filter currentFilter() const
  123     {
  124         return _filter;
  125     }
  126     inline c2bCiter::Format currentFormat() const
  127     {
  128         return _format;
  129     }
  130     inline c2bCiter::Format lastCitationFormat() const
  131     {
  132         return _history.lastCitationFormat();
  133     }
  134     inline void restoreLastNonKeywordState(QModelIndex* current_index)
  135     {
  136         restoreState(_history.lastNonKeywordState(), current_index);
  137     }
  138     inline void restoreLastNonSelectedState(QModelIndex* current_index)
  139     {
  140         restoreState(_history.lastNonSelectedState(), current_index);
  141     }
  142 
  143 
  144 public slots:
  145     void selectCitation(const QModelIndex& i);
  146 
  147 
  148 signals:
  149     void patternFilterChanged(const QString& pattern);
  150     void statusLabel(const QString& label);
  151     void statusMessage(const QString& message);
  152 
  153 
  154 private:
  155     Q_DISABLE_COPY(c2bCiterModel)
  156 
  157     QColor _first_column_color;
  158     QString _display_ajyt(const int row, const int column) const;
  159     QString _display_it(const int row, const int column) const;
  160     QString _display_jya(const int row, const int column) const;
  161     QString _display_k(const int row, const int column) const;
  162     QString _display_r(const int row, const int column) const;
  163     QString _display_t(const int row, const int column) const;
  164     QString _display_yajt(const int row, const int column) const;
  165     QString(c2bCiterModel::*_display_ptr)(const int row, const int column) const;
  166     int _current_item(const QString& index_data) const;
  167     int _offset(const int i) const;
  168     void _add_citations(const QString& fn);
  169     void _clear();
  170     void _set_mapping();
  171     void _set_sort_indices();
  172     void _set_table_data();
  173     void _update_current_index(const int current_item, QModelIndex* current_index) const;
  174     void _update_format(const c2bCiter::Format format = c2bCiter::AJYT);
  175 
  176     inline bool _is_index_valid(const QModelIndex& i) const
  177     {
  178         const int r(i.row());
  179         return _row_count > 0 && r >= 0 && r < _row_count;
  180     }
  181     inline int _current_item(const QModelIndex& current_index) const
  182     {
  183         return _is_index_valid(current_index) ? _offset(current_index.row()) : -1;
  184     }
  185     inline int _current_item(const QModelIndex* const current_index) const
  186     {
  187         return current_index ? _current_item(*current_index) : -1;
  188     }
  189 
  190     // Collection analyzer helper
  191     collectionAnalyzer _analyzer;
  192 
  193     // History helper
  194     QString _fstring;
  195     c2bCiter::Filter _filter;
  196     c2bCiter::Format _format;
  197     c2bCiterHistory _history;
  198 
  199     // Model data
  200     QHash<QString, int> _file;
  201     QList<uint> _included_date;
  202     QStringList _author_string;
  203     QStringList _bibtex_position;
  204     QStringList _citeId;
  205     QStringList _journal;
  206     QStringList _title;
  207     QStringList _url;
  208     QStringList _year;
  209     QVector<QString> _author;
  210     QVector<QString> _search_string;
  211     QVector<bool> _is_selected;
  212     QVector<bool> _matches_filter;
  213     QVector<int> _map_ajyt;
  214     QVector<int> _map_author;
  215     QVector<int> _map_filter;
  216     QVector<int> _map_it;
  217     QVector<int> _map_jya;
  218     QVector<int> _map_t;
  219     QVector<int> _map_yajt;
  220     QVector<int>* _mapping;
  221     int _author_count;
  222     int _author_max_length;
  223     int _citation_count;
  224     int _column_count;
  225     int _journal_max_length;
  226     int _keyword_count;
  227     int _related_count;
  228     int _row_count;
  229 };
  230 
  231 #endif