Parent: [4d1f67] (diff)

Download this file

restable.h    186 lines (156 with data), 5.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* Copyright (C) 2006 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _RESTABLE_H_INCLUDED_
#define _RESTABLE_H_INCLUDED_
#include "autoconfig.h"
#include <Qt>
#include <string>
#include <map>
#include <vector>
#include <memory>
#include "ui_restable.h"
#include "docseq.h"
#include "plaintorich.h"
class ResTable;
typedef std::string (FieldGetter)(const std::string& fldname, const Rcl::Doc& doc);
class RecollModel : public QAbstractTableModel {
Q_OBJECT
public:
RecollModel(const QStringList fields, QObject *parent = 0);
// Reimplemented methods
virtual int rowCount (const QModelIndex& = QModelIndex()) const;
virtual int columnCount(const QModelIndex& = QModelIndex()) const;
virtual QVariant headerData (int col, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const;
virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole ) const;
virtual void saveAsCSV(FILE *fp);
virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
// Specific methods
virtual void readDocSource();
virtual void setDocSource(std::shared_ptr<DocSequence> nsource);
virtual std::shared_ptr<DocSequence> getDocSource() {return m_source;}
virtual void deleteColumn(int);
virtual const std::vector<std::string>& getFields() {return m_fields;}
virtual const std::map<std::string, QString>& getAllFields()
{
return o_displayableFields;
}
virtual void addColumn(int, const std::string&);
// Some column name are aliases/translator for base document field
// (ie: date, datetime->mtime). Help deal with this:
virtual std::string baseField(const std::string&);
// Ignore sort() call because
virtual void setIgnoreSort(bool onoff) {m_ignoreSort = onoff;}
friend class ResTable;
signals:
void sortDataChanged(DocSeqSortSpec);
private:
mutable std::shared_ptr<DocSequence> m_source;
std::vector<std::string> m_fields;
std::vector<FieldGetter*> m_getters;
static std::map<std::string, QString> o_displayableFields;
bool m_ignoreSort;
FieldGetter* chooseGetter(const std::string&);
HighlightData m_hdata;
};
class ResTable;
// Modified textBrowser for the detail area
class ResTableDetailArea : public QTextBrowser {
Q_OBJECT;
public:
ResTableDetailArea(ResTable* parent = 0);
public slots:
virtual void createPopupMenu(const QPoint& pos);
private:
ResTable *m_table;
};
class ResTablePager;
class QUrl;
class RclMain;
class ResTable : public QWidget, public Ui::ResTable
{
Q_OBJECT
public:
ResTable(QWidget* parent = 0)
: QWidget(parent),
m_model(0), m_pager(0), m_detail(0), m_detaildocnum(-1),
m_rclmain(0), m_ismainres(true)
{
setupUi(this);
init();
}
virtual ~ResTable() {}
virtual RecollModel *getModel() {return m_model;}
virtual ResTableDetailArea* getDetailArea() {return m_detail;}
virtual int getDetailDocNumOrTopRow();
void setRclMain(RclMain *m, bool ismain);
public slots:
virtual void onTableView_currentChanged(const QModelIndex&);
virtual void on_tableView_entered(const QModelIndex& index);
virtual void setDocSource(std::shared_ptr<DocSequence> nsource);
virtual void saveColState();
virtual void resetSource();
virtual void readDocSource(bool resetPos = true);
virtual void onSortDataChanged(DocSeqSortSpec);
virtual void createPopupMenu(const QPoint& pos);
virtual void onDoubleClick(const QModelIndex&);
virtual void menuPreview();
virtual void menuSaveToFile();
virtual void menuSaveSelection();
virtual void menuEdit();
virtual void menuEditAndQuit();
virtual void menuOpenWith(QAction *);
virtual void menuCopyFN();
virtual void menuCopyURL();
virtual void menuExpand();
virtual void menuPreviewParent();
virtual void menuOpenParent();
virtual void menuShowSnippets();
virtual void menuShowSubDocs();
virtual void createHeaderPopupMenu(const QPoint&);
virtual void deleteColumn();
virtual void addColumn();
virtual void resetSort(); // Revert to natural (relevance) order
virtual void saveAsCSV();
virtual void linkWasClicked(const QUrl&);
virtual void makeRowVisible(int row);
virtual void takeFocus();
signals:
void docPreviewClicked(int, Rcl::Doc, int);
void docSaveToFileClicked(Rcl::Doc);
void previewRequested(Rcl::Doc);
void editRequested(Rcl::Doc);
void openWithRequested(Rcl::Doc, string cmd);
void headerClicked();
void docExpand(Rcl::Doc);
void showSubDocs(Rcl::Doc);
void showSnippets(Rcl::Doc);
friend class ResTablePager;
friend class ResTableDetailArea;
private:
void init();
RecollModel *m_model;
ResTablePager *m_pager;
ResTableDetailArea *m_detail;
int m_detaildocnum;
Rcl::Doc m_detaildoc;
int m_popcolumn;
RclMain *m_rclmain;
bool m_ismainres;
};
#endif /* _RESTABLE_H_INCLUDED_ */