QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
FieldLabel Class Reference

The name of a key: value field in PasswordDialog, editable in place: double-click or the context menu renames it, the context menu can also remove the field (#132). More...

#include <fieldlabel.h>

Inheritance diagram for FieldLabel:
Collaboration diagram for FieldLabel:

Public Slots

void startEdit ()
 Open the in-place editor over the label.

Signals

void renamed (const QString &from, const QString &to)
 The user typed a different name and confirmed it.
void removeRequested ()
 The user chose "Remove field".
void copied (const QString &text)
 Text was copied out of the name editor, marked as a secret.

Public Member Functions

 FieldLabel (const QString &name, QWidget *parent=nullptr)
 Label for the field called name.
auto name () const -> QString
 The field's key, whole; the label shows it through Util::shownName().
void setName (const QString &name)
 Name the field name and show it.
 ~FieldLabel () override
 Takes an open editor with it: the editor is a sibling, not a child, so it would otherwise stay behind when the field is removed while its name is being edited.

Protected Member Functions

void mouseDoubleClickEvent (QMouseEvent *event) override
 A left double-click starts editing the name.
void contextMenuEvent (QContextMenuEvent *event) override
 Menu with Rename field and Remove field.
auto eventFilter (QObject *watched, QEvent *event) -> bool override
 Escape in the editor cancels the edit.

Private Member Functions

void finishEdit (bool commit)
 Close the editor, putting the label back in its place.

Private Attributes

QPointer< QLineEdit > m_editor
 The line edit open over the label while a rename is in progress; null otherwise. A sibling in the parent's form layout rather than a child, so the destructor deletes it explicitly.
QString m_name
 The field's key, whole (the text shown may be cut).

Detailed Description

The name of a key: value field in PasswordDialog, editable in place: double-click or the context menu renames it, the context menu can also remove the field (#132).

The label only reports what the user asked for; PasswordDialog owns the line edit the field belongs to and decides whether a new name is usable.

Definition at line 26 of file fieldlabel.h.

Constructor & Destructor Documentation

◆ FieldLabel()

FieldLabel::FieldLabel ( const QString & name,
QWidget * parent = nullptr )
explicit

Label for the field called name.

Parameters
namethe field's key, as shown and as written back
parentowning widget

Definition at line 18 of file fieldlabel.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~FieldLabel()

FieldLabel::~FieldLabel ( )
override

Takes an open editor with it: the editor is a sibling, not a child, so it would otherwise stay behind when the field is removed while its name is being edited.

Definition at line 48 of file fieldlabel.cpp.

Member Function Documentation

◆ contextMenuEvent()

void FieldLabel::contextMenuEvent ( QContextMenuEvent * event)
overrideprotected

Menu with Rename field and Remove field.

Parameters
eventthe context menu event

Definition at line 41 of file fieldlabel.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copied

void FieldLabel::copied ( const QString & text)
signal

Text was copied out of the name editor, marked as a secret.

Parameters
textThe text copied.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventFilter()

auto FieldLabel::eventFilter ( QObject * watched,
QEvent * event ) -> bool
overrideprotected

Escape in the editor cancels the edit.

Parameters
watchedthe editor
eventthe event to inspect
Returns
true when the event was consumed

Definition at line 95 of file fieldlabel.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finishEdit()

void FieldLabel::finishEdit ( bool commit)
private

Close the editor, putting the label back in its place.

Parameters
commitemit renamed() for a changed, non-empty name

Definition at line 117 of file fieldlabel.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseDoubleClickEvent()

void FieldLabel::mouseDoubleClickEvent ( QMouseEvent * event)
overrideprotected

A left double-click starts editing the name.

Parameters
eventthe mouse event

Definition at line 33 of file fieldlabel.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

auto FieldLabel::name ( ) const -> QString
inlinenodiscard

The field's key, whole; the label shows it through Util::shownName().

Returns
The key.

Definition at line 42 of file fieldlabel.h.

Here is the caller graph for this function:

◆ removeRequested

void FieldLabel::removeRequested ( )
signal

The user chose "Remove field".

Here is the caller graph for this function:

◆ renamed

void FieldLabel::renamed ( const QString & from,
const QString & to )
signal

The user typed a different name and confirmed it.

Parameters
fromthe name before, still shown until the receiver accepts
tothe new name, trimmed, never empty, without a colon or a line break
Here is the caller graph for this function:

◆ setName()

void FieldLabel::setName ( const QString & name)

Name the field name and show it.

Parameters
nameThe field's new key.

Definition at line 27 of file fieldlabel.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startEdit

void FieldLabel::startEdit ( )
slot

Open the in-place editor over the label.

Definition at line 50 of file fieldlabel.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_editor

QPointer<QLineEdit> FieldLabel::m_editor
private

The line edit open over the label while a rename is in progress; null otherwise. A sibling in the parent's form layout rather than a child, so the destructor deletes it explicitly.

Definition at line 110 of file fieldlabel.h.

◆ m_name

QString FieldLabel::m_name
private

The field's key, whole (the text shown may be cut).

Definition at line 112 of file fieldlabel.h.


The documentation for this class was generated from the following files: