Editor feature for RDB item comments, bindkeys for waive and edit

This commit is contained in:
Matthias Koefferlein 2024-04-27 21:09:14 +02:00
parent 9ef51ca981
commit 0b5473c153
3 changed files with 150 additions and 60 deletions

View File

@ -480,51 +480,7 @@
<property name="spacing">
<number>6</number>
</property>
<item row="2" column="3">
<widget class="QToolButton" name="waive_pb">
<property name="toolTip">
<string>Waive</string>
</property>
<property name="text">
<string>W</string>
</property>
<property name="icon">
<iconset resource="../../icons/icons.qrc">
<normaloff>:/waived_16px.png</normaloff>:/waived_16px.png</iconset>
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QToolButton" name="nophoto_pb">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Remove snapshot&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../icons/icons.qrc">
<normaloff>:/nophoto_16px.png</normaloff>:/nophoto_16px.png</iconset>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="flags_pb">
<property name="toolTip">
<string>Set or reset flag</string>
</property>
<property name="text">
<string>Flag</string>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
</property>
</widget>
</item>
<item row="2" column="6">
<item row="2" column="7">
<widget class="QToolButton" name="photo_pb">
<property name="toolTip">
<string>Add snapshot</string>
@ -538,28 +494,24 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QToolButton" name="important_pb">
<item row="2" column="3">
<widget class="QToolButton" name="waive_pb">
<property name="toolTip">
<string>Important</string>
<string>Waive</string>
</property>
<property name="text">
<string>Imp</string>
<string>W</string>
</property>
<property name="icon">
<iconset resource="../../icons/icons.qrc">
<normaloff>:/important_16px.png</normaloff>:/important_16px.png</iconset>
<normaloff>:/waived_16px.png</normaloff>:/waived_16px.png</iconset>
</property>
<property name="shortcut">
<string>Ctrl+W</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="info_label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0" colspan="7">
<item row="1" column="0" colspan="8">
<widget class="QFrame" name="frame_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@ -605,7 +557,38 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
</item>
<item row="0" column="0" colspan="7">
<item row="2" column="5">
<widget class="QToolButton" name="important_pb">
<property name="toolTip">
<string>Important</string>
</property>
<property name="text">
<string>Imp</string>
</property>
<property name="icon">
<iconset resource="../../icons/icons.qrc">
<normaloff>:/important_16px.png</normaloff>:/important_16px.png</iconset>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QToolButton" name="nophoto_pb">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Remove snapshot&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../icons/icons.qrc">
<normaloff>:/nophoto_16px.png</normaloff>:/nophoto_16px.png</iconset>
</property>
</widget>
</item>
<item row="0" column="0" colspan="8">
<widget class="QFrame" name="frame_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@ -662,6 +645,43 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="info_label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="flags_pb">
<property name="toolTip">
<string>Set or reset flag</string>
</property>
<property name="text">
<string>Flag</string>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QToolButton" name="edit_pb">
<property name="toolTip">
<string>Edit Comment</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../icons/icons.qrc">
<normaloff>:/edit_16px.png</normaloff>:/edit_16px.png</iconset>
</property>
<property name="shortcut">
<string>F2</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

View File

@ -39,6 +39,7 @@
#include <QMessageBox>
#include <QHeaderView>
#include <QKeyEvent>
#include <QInputDialog>
namespace rdb
{
@ -1690,6 +1691,7 @@ MarkerBrowserPage::MarkerBrowserPage (QWidget * /*parent*/)
connect (list_down_pb, SIGNAL (clicked ()), this, SLOT (list_down_clicked ()));
connect (flags_pb, SIGNAL (clicked ()), this, SLOT (flag_button_clicked ()));
connect (important_pb, SIGNAL (clicked ()), this, SLOT (important_button_clicked ()));
connect (edit_pb, SIGNAL (clicked ()), this, SLOT (edit_button_clicked ()));
connect (waive_pb, SIGNAL (clicked ()), this, SLOT (waived_button_clicked ()));
connect (photo_pb, SIGNAL (clicked ()), this, SLOT (snapshot_button_clicked ()));
connect (nophoto_pb, SIGNAL (clicked ()), this, SLOT (remove_snapshot_button_clicked ()));
@ -2104,6 +2106,8 @@ MarkerBrowserPage::update_info_text ()
size_t n_category = 0;
const rdb::Item *item = 0;
size_t n_item = 0;
std::string comment;
size_t n_comment = 0;
for (QModelIndexList::const_iterator selected_item = selected.begin (); selected_item != selected.end (); ++selected_item) {
@ -2115,6 +2119,11 @@ MarkerBrowserPage::update_info_text ()
item = i;
++n_item;
if (! item->comment ().empty () && item->comment () != comment) {
comment = item->comment ();
++n_comment;
}
const rdb::Cell *c = mp_database->cell_by_id (item->cell_id ());
if (c && c != cell) {
cell = c;
@ -2162,6 +2171,12 @@ MarkerBrowserPage::update_info_text ()
info += "</p>";
}
if (! comment.empty () && n_comment == 1) {
info += "<p style=\"color:gray\">";
tl::escape_to_html (info, comment);
info += "</p>";
}
info += "<p/>";
if (item && n_item == 1) {
@ -2901,7 +2916,61 @@ MarkerBrowserPage::flag_menu_selected ()
}
}
void
void
MarkerBrowserPage::edit_button_clicked ()
{
if (! mp_database) {
return;
}
MarkerBrowserListViewModel *list_model = dynamic_cast<MarkerBrowserListViewModel *> (markers_list->model ());
if (! list_model) {
return;
}
std::string str;
QModelIndexList selected = markers_list->selectionModel ()->selectedIndexes ();
for (QModelIndexList::const_iterator selected_item = selected.begin (); selected_item != selected.end (); ++selected_item) {
if (selected_item->column () == 0) {
const rdb::Item *i = list_model->item (selected_item->row ());
if (! i->comment ().empty ()) {
if (str.empty ()) {
str = i->comment ();
} else if (str != i->comment ()) {
str.clear ();
break;
}
}
}
}
bool ok = false;
#if QT_VERSION >= 0x50200
QString new_text = QInputDialog::getMultiLineText (this, QObject::tr ("Edit Marker Comment"), QObject::tr ("Comment"), tl::to_qstring (str), &ok);
str = tl::to_string (new_text);
#else
QString new_text = QInputDialog::getText (this, QObject::tr ("Edit Marker Comment"), QObject::tr ("Comment"), QLineEdit::Normal, tl::to_qstring (tl::escape_string (str)), &ok);
str = tl::unescape_string (tl::to_string (new_text));
#endif
if (ok) {
QModelIndexList selected = markers_list->selectionModel ()->selectedIndexes ();
for (QModelIndexList::const_iterator selected_item = selected.begin (); selected_item != selected.end (); ++selected_item) {
if (selected_item->column () == 0) {
const rdb::Item *i = list_model->item (selected_item->row ());
mp_database->set_item_comment (i, str);
}
}
update_info_text ();
}
}
void
MarkerBrowserPage::waived_button_clicked ()
{
if (! mp_database) {

View File

@ -179,6 +179,7 @@ public slots:
void flag_menu_selected ();
void important_button_clicked ();
void waived_button_clicked ();
void edit_button_clicked ();
void snapshot_button_clicked ();
void remove_snapshot_button_clicked ();
void revisit_non_waived ();