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
|
#include "latexlog.h"
#include "qlinemarksinfocenter.h"
LatexLogModel::LatexLogModel(QObject * parent): QAbstractTableModel(parent) {
markIDs[LT_NONE] = -1;
markIDs[LT_ERROR]=QLineMarksInfoCenter::instance()->markTypeId("error");
markIDs[LT_WARNING]=QLineMarksInfoCenter::instance()->markTypeId("warning");
markIDs[LT_BADBOX]=QLineMarksInfoCenter::instance()->markTypeId("badbox");
foundType[LT_NONE] = foundType[LT_ERROR] = foundType[LT_WARNING] = foundType[LT_BADBOX] = false;
}
int LatexLogModel::columnCount(const QModelIndex & parent) const {
return parent.isValid()?0:4;
}
int LatexLogModel::rowCount(const QModelIndex &parent) const {
return parent.isValid()?0:log.count();
}
QVariant LatexLogModel::data(const QModelIndex &index, int role) const {
if (!index.isValid()) return QVariant();
if (index.row() >= log.count() || index.row() < 0) return QVariant();
if (role == Qt::ToolTipRole) return tr("Click to jump to the line");
if (role == Qt::ForegroundRole) return log.at(index.row()).type==LT_ERROR?QBrush(QColor(Qt::red)):QBrush(QColor(Qt::blue));
if (role != Qt::DisplayRole) return QVariant();
switch (index.column()) {
case 0:
return log.at(index.row()).file.mid(log.at(index.row()).file.lastIndexOf("/")+1); //show relative names
case 1:
switch (log.at(index.row()).type) {
case LT_ERROR:
return tr("error");
case LT_WARNING:
return tr("warning");
case LT_BADBOX:
return tr("bad box");
default:
return QVariant(); //return Texmaker::tr("unknown");
}
case 2:
return tr("line")+ QString(" %1").arg(log.at(index.row()).oldline);
case 3:
return log.at(index.row()).message;
default:
return QVariant();
}
}
QVariant LatexLogModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role != Qt::DisplayRole) return QVariant();
if (orientation != Qt::Horizontal) return QVariant();
switch (section) {
case 0:
return tr("File");
case 1:
return tr("Type");
case 2:
return tr("Line");
case 3:
return tr("Message");
default:
return QVariant();
}
}
void LatexLogModel::reset() {
QAbstractTableModel::reset();
}
int LatexLogModel::count() {
return log.count();
}
void LatexLogModel::clear() {
log.clear();
}
const LatexLogEntry& LatexLogModel::at(int i) {
return log.at(i);
}
//void LatexLogModel::append(QString aFile, LogType aType, QString aOldline, int aLogline, QString aMessage) {
//log.append(LatexLogEntry(aFile, aType, aOldline, aLogline, aMessage));
//}
//Parse a latex log file to find errors, warnings, bad boxes...
void LatexLogModel::parseLogDocument(QTextDocument* doc, QString baseFileName) {
LatexOutputFilter outputFilter;
//TODO: investigate why it crashes if outputFilter is a member variable, m_infoList is set to a global variable by the LatexLogModel constructor instead here, but only if the m_filelookup member of LatexOutputFilter does exist
outputFilter.setSource(baseFileName);
outputFilter.run(doc);
log.clear();
QList<LatexLogEntry> laterLog;
for (int i = 0; i <outputFilter.m_infoList.count(); i++) {
LatexLogEntry cur = outputFilter.m_infoList.at(i);
if (cur.type == LT_ERROR) log << cur;
else laterLog << cur;
}
log << laterLog;
foundType[LT_ERROR]=outputFilter.m_nErrors>0;
foundType[LT_BADBOX]=outputFilter.m_nBadBoxes>0;
foundType[LT_WARNING]=outputFilter.m_nWarnings>0;
reset(); //show changes
}
bool LatexLogModel::found(LogType lt) const {
Q_ASSERT_X(lt>0&<<4, "found logtype", "unbound array index");
return foundType[lt];
}
int LatexLogModel::markID(LogType lt) const {
Q_ASSERT_X(lt>0&<<4, "markID logtype", "unbound array index");
return markIDs[lt];
}
int LatexLogModel::logLineNumberToLogEntryNumber(int logLine) const {
int res=-1;
for (int i=0; i<log.count();i++)
if (log.at(i).logline<=logLine)
if (res==-1 || log.at(i).logline > log.at(res).logline)
res=i;
return res;
}
bool LatexLogModel::existsReRunWarning() const{
if (!found(LT_WARNING)) return false;
static QRegExp rReRun ("(No file.*\\.(aux|toc))|"
"( Rerun )");
foreach (const LatexLogEntry& l, log) {
if (l.type != LT_WARNING || l.oldline != 0) continue;
if (l.message.contains(rReRun) && !l.message.contains("No file \\jobname .aux")) return true;
}
return false;
}
QStringList LatexLogModel::getMissingCitations() const{
QStringList sl;
static QRegExp rCitation ("Citation +[`'\"]([^`'\"]+)[`'\"] +.*undefined");
foreach (const LatexLogEntry& l, log) {
if (l.type != LT_WARNING) continue;
if (rCitation.indexIn(l.message) >= 0)
sl.append(rCitation.cap(1));
}
return sl;
}
|