Skip to content

Commit c848061

Browse files
committed
Enable use of Markdown and HTML in ascent descriptions
1 parent 314e508 commit c848061

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

src/ui/ascent_viewer.ui

+3
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,9 @@
11621162
<height>200</height>
11631163
</size>
11641164
</property>
1165+
<property name="undoRedoEnabled">
1166+
<bool>true</bool>
1167+
</property>
11651168
<property name="acceptRichText">
11661169
<bool>false</bool>
11671170
</property>

src/viewer/ascent_viewer.cpp

+22-11
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ void AscentViewer::updateInfoArea()
321321
{
322322
resetInfoLabels();
323323

324-
BufferRowIndex ascentBufferRowIndex = compAscents.getBufferRowIndexForViewRow(currentViewRowIndex);
324+
const BufferRowIndex ascentBufferRowIndex = compAscents.getBufferRowIndexForViewRow(currentViewRowIndex);
325325

326-
ItemID tripID = db.ascentsTable.tripIDColumn.getValueAt(ascentBufferRowIndex);
326+
const ItemID tripID = db.ascentsTable.tripIDColumn.getValueAt(ascentBufferRowIndex);
327327
if (tripID.isValid()) {
328328
BufferRowIndex tripBufferRowIndex = db.tripsTable.getBufferIndexForPrimaryKey(FORCE_VALID(tripID));
329329
tripNameLabel ->setText (compAscents.tripColumn .getFormattedValueAt(ascentBufferRowIndex).toString());
@@ -337,7 +337,7 @@ void AscentViewer::updateInfoArea()
337337
tripDatesLabel ->setText (dateRange);
338338
}
339339

340-
ItemID peakID = db.ascentsTable.peakIDColumn.getValueAt(ascentBufferRowIndex);
340+
const ItemID peakID = db.ascentsTable.peakIDColumn.getValueAt(ascentBufferRowIndex);
341341
if (peakID.isValid()) {
342342
BufferRowIndex peakBufferRowIndex = db.peaksTable.getBufferIndexForPrimaryKey(FORCE_VALID(peakID));
343343
peakNameLabel ->setText (compAscents.peakColumn .getFormattedValueAt(ascentBufferRowIndex).toString());
@@ -347,9 +347,9 @@ void AscentViewer::updateInfoArea()
347347
peakRangeLabel ->setText (compAscents.rangeColumn .getFormattedValueAt(ascentBufferRowIndex).toString());
348348
peakCountryLabel ->setText (compAscents.countryColumn .getFormattedValueAt(ascentBufferRowIndex).toString());
349349
peakContinentLabel ->setText (compAscents.continentColumn .getFormattedValueAt(ascentBufferRowIndex).toString());
350-
QString mapsLink = db.peaksTable.mapsLinkColumn .getValueAt(peakBufferRowIndex).toString();
351-
QString earthLink = db.peaksTable.earthLinkColumn .getValueAt(peakBufferRowIndex).toString();
352-
QString wikiLink = db.peaksTable.wikiLinkColumn .getValueAt(peakBufferRowIndex).toString();
350+
const QString mapsLink = db.peaksTable.mapsLinkColumn .getValueAt(peakBufferRowIndex).toString();
351+
const QString earthLink = db.peaksTable.earthLinkColumn .getValueAt(peakBufferRowIndex).toString();
352+
const QString wikiLink = db.peaksTable.wikiLinkColumn .getValueAt(peakBufferRowIndex).toString();
353353
if (!mapsLink.isEmpty() || !earthLink.isEmpty() || !wikiLink.isEmpty()) peakLinksBox->setVisible(true);
354354
if (!mapsLink.isEmpty()) {
355355
peakMapsLinkLabel ->setText("[" + tr("Google Maps") + "](" + mapsLink + ")");
@@ -365,7 +365,7 @@ void AscentViewer::updateInfoArea()
365365
}
366366
}
367367

368-
QString ascentTitle = compAscents.titleColumn .getFormattedValueAt(ascentBufferRowIndex).toString();
368+
const QString ascentTitle = compAscents.titleColumn .getFormattedValueAt(ascentBufferRowIndex).toString();
369369
if (!ascentTitle.isEmpty()) {
370370
ascentTitleLabel ->setText (compAscents.titleColumn .getFormattedValueAt(ascentBufferRowIndex).toString());
371371
ascentTitleLabel ->setVisible(true);
@@ -380,13 +380,18 @@ void AscentViewer::updateInfoArea()
380380
ascentDifficultyLabel ->setText (compAscents.difficultyColumn .getFormattedValueAt (ascentBufferRowIndex).toString());
381381
ascentPeakOrdinalLabel ->setText (compAscents.peakOrdinalColumn .getFormattedValueAt (ascentBufferRowIndex).toString());
382382

383-
QString hikersList = compAscents.hikersColumn.getFormattedValueAt(ascentBufferRowIndex).toString();
383+
const QString hikersList = compAscents.hikersColumn.getFormattedValueAt(ascentBufferRowIndex).toString();
384384
if (!hikersList.isEmpty()) {
385385
ascentParticipantsLabel ->setText (hikersList);
386386
ascentParticipantsBox->setVisible(true);
387387
}
388388

389-
descriptionTextBrowser->setText(db.ascentsTable.descriptionColumn.getValueAt(ascentBufferRowIndex).toString());
389+
const QString ascentDescription = db.ascentsTable.descriptionColumn.getValueAt(ascentBufferRowIndex).toString();
390+
if (descriptionEditable) {
391+
descriptionTextBrowser->setPlainText(ascentDescription);
392+
} else {
393+
descriptionTextBrowser->setMarkdown(ascentDescription);
394+
}
390395
}
391396

392397
/**
@@ -849,8 +854,8 @@ void AscentViewer::saveDescription()
849854
{
850855
if (currentAscentID.isInvalid() || !descriptionEditable) return;
851856

852-
QString newDescription = descriptionTextBrowser->toPlainText();
853-
bool descriptionChanged = db.ascentsTable.descriptionColumn.getValueFor(FORCE_VALID(currentAscentID)) != newDescription;
857+
const QString newDescription = descriptionTextBrowser->toPlainText();
858+
const bool descriptionChanged = db.ascentsTable.descriptionColumn.getValueFor(FORCE_VALID(currentAscentID)) != newDescription;
854859
if (descriptionChanged) {
855860
db.beginChangingData();
856861
db.ascentsTable.updateCell(*this, FORCE_VALID(currentAscentID), db.ascentsTable.descriptionColumn, newDescription);
@@ -1141,6 +1146,12 @@ void AscentViewer::handle_descriptionEditableChanged()
11411146

11421147
descriptionEditable = editDescriptionButton->isChecked();
11431148

1149+
if (descriptionEditable) {
1150+
const QString description = db.ascentsTable.descriptionColumn.getValueFor(FORCE_VALID(currentAscentID)).toString();
1151+
descriptionTextBrowser->setPlainText(description);
1152+
} else {
1153+
descriptionTextBrowser->setMarkdown(descriptionTextBrowser->toPlainText());
1154+
}
11441155
descriptionTextBrowser->setReadOnly(!descriptionEditable);
11451156
}
11461157

0 commit comments

Comments
 (0)