Skip to content

Commit

Permalink
Always calculate hash value for new data in item
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Apr 7, 2013
1 parent 1f89925 commit 36a61ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/clipboarditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ bool ClipboardItem::operator ==(const QMimeData &data) const
void ClipboardItem::clear()
{
m_data->clear();
m_hash = hash(*m_data, m_data->formats());
updateDataHash();
}

void ClipboardItem::setData(QMimeData *data)
{
delete m_data;
m_data = data;
m_hash = 0;
updateDataHash();
}

void ClipboardItem::setData(const QVariant &value)
{
// rewrite all original data with edited text
m_data->clear();
m_data->setText( value.toString() );
m_hash = hash(*m_data, m_data->formats());
updateDataHash();
}

void ClipboardItem::setData(const QString &mimeType, const QByteArray &data)
{
m_data->setData(mimeType, data);
m_hash = hash(*m_data, m_data->formats());
updateDataHash();
}

QString ClipboardItem::text() const
Expand Down Expand Up @@ -105,6 +105,12 @@ QVariant ClipboardItem::data(int role) const
return QVariant();
}


void ClipboardItem::updateDataHash()
{
m_hash = hash(*m_data, m_data->formats());
}

QDataStream &operator<<(QDataStream &stream, const ClipboardItem &item)
{
const QMimeData *data = item.data();
Expand Down
2 changes: 2 additions & 0 deletions src/include/clipboarditem.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class ClipboardItem
uint dataHash() const { return m_hash; }

private:
void updateDataHash();

QMimeData *m_data;
uint m_hash;
};
Expand Down

0 comments on commit 36a61ab

Please sign in to comment.