Simplify copying to clipboard removing one method call
removed toImage
Details
- Reviewers
davidre
Copy to clipboard works the same (both via GUI & CLI)
Diff Detail
- Repository
- R166 Spectacle
- Branch
- B411263
- Lint
No Linters Available - Unit
No Unit Test Coverage - Build Status
Buildable 15802 Build 15820: arc lint + arc unit
Apparently, this is slower than setImage() because:
Note that this is slower than setImage() because it needs to convert the QPixmap to a QImage first.
https://doc.qt.io/qt-5/qclipboard.html#setPixmap
Since we are doing the conversion via data->setImageData(mSavePixmap.toImage()); I assume that we end up with the same speed.
What's a good way to test the speed difference?
setPixmap does exactly the same thing, from Qt's source code:
void QClipboard::setPixmap(const QPixmap &pixmap, Mode mode) { QMimeData *data = new QMimeData; data->setImageData(pixmap); setMimeData(data, mode); }
and you lost the x-kde-force-image-copy hint, so I don't think this patch is neccessary.
What you can try is just not converting toImage() first because it seems Qt can do that internally/implicitly.
From qmimedata.cpp
// images and pixmaps are interchangeable if ((type == QVariant::Pixmap && data.type() == QVariant::Image) || (type == QVariant::Image && data.type() == QVariant::Pixmap)) return data;
Reverted back.
And removed toImage() - works without it. Thanks broulik!
toImage() from qtpixmap.cpp:
QImage QPixmap::toImage() const { if (isNull()) return QImage(); return data->toImage(); }
Not much computing power saved. Worth it?