judge if equal in VOutline when updating curHeader

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-11-16 23:01:06 +08:00
parent 4fcdba7a11
commit 810d2f02f4
3 changed files with 15 additions and 2 deletions

View File

@ -241,7 +241,6 @@ void VEditTab::handleFocusChanged(QWidget *old, QWidget *now)
void VEditTab::updateTocFromHtml(const QString &tocHtml) void VEditTab::updateTocFromHtml(const QString &tocHtml)
{ {
qDebug() << tocHtml;
tableOfContent.type = VHeaderType::Anchor; tableOfContent.type = VHeaderType::Anchor;
QVector<VHeader> &headers = tableOfContent.headers; QVector<VHeader> &headers = tableOfContent.headers;
headers.clear(); headers.clear();

View File

@ -81,11 +81,17 @@ void VOutline::handleItemClicked(QTreeWidgetItem *item, int column)
QString anchor = itemJson["anchor"].toString(); QString anchor = itemJson["anchor"].toString();
int lineNumber = itemJson["line_number"].toInt(); int lineNumber = itemJson["line_number"].toInt();
qDebug() << "click anchor" << anchor << lineNumber; qDebug() << "click anchor" << anchor << lineNumber;
emit outlineItemActivated(VAnchor(outline.filePath, anchor, lineNumber)); curHeader.filePath = outline.filePath;
curHeader.anchor = anchor;
curHeader.lineNumber = lineNumber;
emit outlineItemActivated(curHeader);
} }
void VOutline::updateCurHeader(const VAnchor &anchor) void VOutline::updateCurHeader(const VAnchor &anchor)
{ {
if (anchor == curHeader) {
return;
}
curHeader = anchor; curHeader = anchor;
if (outline.type == VHeaderType::Anchor) { if (outline.type == VHeaderType::Anchor) {
selectAnchor(anchor.anchor); selectAnchor(anchor.anchor);

View File

@ -26,11 +26,19 @@ struct VAnchor
VAnchor() : lineNumber(-1) {} VAnchor() : lineNumber(-1) {}
VAnchor(const QString filePath, const QString &anchor, int lineNumber) VAnchor(const QString filePath, const QString &anchor, int lineNumber)
: filePath(filePath), anchor(anchor), lineNumber(lineNumber) {} : filePath(filePath), anchor(anchor), lineNumber(lineNumber) {}
inline bool operator ==(const VAnchor &p_anchor) const;
QString filePath; QString filePath;
QString anchor; QString anchor;
int lineNumber; int lineNumber;
}; };
inline bool VAnchor::operator ==(const VAnchor &p_anchor) const
{
return p_anchor.filePath == filePath &&
p_anchor.anchor == anchor &&
p_anchor.lineNumber == lineNumber;
}
class VToc class VToc
{ {
public: public: