diff options
Diffstat (limited to 'src/libaudqt/info-widget.cc')
-rw-r--r-- | src/libaudqt/info-widget.cc | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/libaudqt/info-widget.cc b/src/libaudqt/info-widget.cc index ef9b218..c1eb083 100644 --- a/src/libaudqt/info-widget.cc +++ b/src/libaudqt/info-widget.cc @@ -1,7 +1,7 @@ /* * info-widget.h - * Copyright 2006-2014 William Pitcock, Tomasz Moń, Eugene Zagidullin, - * John Lindgren, and Thomas Lange + * Copyright 2006-2017 René Bertin, Thomas Lange, John Lindgren, + * William Pitcock, Tomasz Moń, and Eugene Zagidullin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -20,6 +20,7 @@ #include "info-widget.h" #include "libaudqt.h" +#include "libaudqt-internal.h" #include <QHeaderView> @@ -97,6 +98,17 @@ EXPORT InfoWidget::InfoWidget (QWidget * parent) : header ()->hide (); setIndentation (0); resizeColumnToContents (0); + setContextMenuPolicy (Qt::CustomContextMenu); + + connect (this, & QWidget::customContextMenuRequested, [this] (const QPoint & pos) + { + auto index = indexAt (pos); + if (index.column () != 1) + return; + auto text = m_model->data (index, Qt::DisplayRole).toString (); + if (! text.isEmpty ()) + show_copy_context_menu (this, mapToGlobal (pos), text); + }); } EXPORT InfoWidget::~InfoWidget () @@ -136,20 +148,17 @@ bool InfoModel::setData (const QModelIndex & index, const QVariant & value, int m_dirty = true; auto t = Tuple::field_get_type (field_id); - if (t == Tuple::String) - { - m_tuple.set_str (field_id, value.toString ().toUtf8 ()); - emit dataChanged (index, index, {role}); - return true; - } - else if (t == Tuple::Int) - { - m_tuple.set_int (field_id, value.toInt ()); - emit dataChanged (index, index, {role}); - return true; - } + auto str = value.toString (); + + if (str.isEmpty ()) + m_tuple.unset (field_id); + else if (t == Tuple::String) + m_tuple.set_str (field_id, str.toUtf8 ()); + else /* t == Tuple::Int */ + m_tuple.set_int (field_id, str.toInt ()); - return false; + emit dataChanged (index, index, {role}); + return true; } QVariant InfoModel::data (const QModelIndex & index, int role) const @@ -170,7 +179,8 @@ QVariant InfoModel::data (const QModelIndex & index, int role) const case Tuple::String: return QString (m_tuple.get_str (field_id)); case Tuple::Int: - return m_tuple.get_int (field_id); + /* convert to string so Qt allows clearing the field */ + return QString::number (m_tuple.get_int (field_id)); default: return QVariant (); } |