Displaying a QR code in the EditItemDialog containing the full data of the current item as a string.
This commit is contained in:
@ -1,13 +1,15 @@
|
||||
#include "edititemdialog.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "../views/itemdetailmapper.h"
|
||||
|
||||
EditItemDialog::EditItemDialog(QTableView* tableView, QWidget* parent)
|
||||
: AbstractDialog(QDialogButtonBox::Close, parent)
|
||||
, m_tableView(tableView) {}
|
||||
, m_tableView(tableView)
|
||||
, m_qrCodeDisplay(new QLabel("QR Code")) {}
|
||||
|
||||
void EditItemDialog::createContent() {
|
||||
if (m_contentContainer) {
|
||||
@ -16,9 +18,17 @@ void EditItemDialog::createContent() {
|
||||
|
||||
setWindowTitle(tr("Edit item..."));
|
||||
|
||||
m_contentContainer = new QWidget(this);
|
||||
QHBoxLayout* innerLayout = new QHBoxLayout(this);
|
||||
m_contentContainer->setLayout(innerLayout);
|
||||
|
||||
m_detailMapper = new ItemDetailMapper(this);
|
||||
m_detailMapper->setModelMappings(m_tableView);
|
||||
m_contentContainer = m_detailMapper;
|
||||
innerLayout->addWidget(m_detailMapper);
|
||||
|
||||
updateQRCode();
|
||||
connect(m_detailMapper, &ItemDetailMapper::contentChanged, this, &EditItemDialog::updateQRCode);
|
||||
innerLayout->addWidget(m_qrCodeDisplay);
|
||||
|
||||
m_outerLayout->insertWidget(0, m_contentContainer);
|
||||
}
|
||||
@ -32,3 +42,16 @@ void EditItemDialog::reject() {
|
||||
m_detailMapper->revert();
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
void EditItemDialog::updateQRCode(const QString text) {
|
||||
QImage unscaledImage;
|
||||
if (text.isEmpty()) {
|
||||
unscaledImage = QImage("://no-picture-taking.png");
|
||||
} else {
|
||||
unscaledImage = m_generator.generateQr(text);
|
||||
}
|
||||
QImage image = unscaledImage.scaled(250, 250);
|
||||
|
||||
m_qrCodeDisplay->setPixmap(QPixmap::fromImage(image));
|
||||
m_qrCodeDisplay->setToolTip(text);
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#ifndef EDITITEMDIALOG_H
|
||||
#define EDITITEMDIALOG_H
|
||||
|
||||
#include "QrCodeGenerator.h"
|
||||
#include "abstractdialog.h"
|
||||
|
||||
class QDoubleSpinBox;
|
||||
@ -23,6 +24,9 @@ class EditItemDialog : public AbstractDialog {
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
|
||||
private slots:
|
||||
void updateQRCode(const QString text = "");
|
||||
|
||||
private:
|
||||
QTableView* m_tableView = nullptr;
|
||||
ItemDetailMapper* m_detailMapper;
|
||||
@ -41,6 +45,9 @@ class EditItemDialog : public AbstractDialog {
|
||||
|
||||
QLabel* m_factorLabel = nullptr;
|
||||
QDoubleSpinBox* m_factorBox = nullptr;
|
||||
|
||||
QLabel* m_qrCodeDisplay = nullptr;
|
||||
QrCodeGenerator m_generator;
|
||||
};
|
||||
|
||||
#endif // EDITITEMDIALOG_H
|
||||
|
||||
Reference in New Issue
Block a user