Compare commits

...

1 Commits

5 changed files with 48 additions and 3 deletions

View File

@ -63,6 +63,8 @@ target_link_libraries(${TARGET_APP} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_include_directories(${TARGET_APP} PRIVATE ${CORE_LIB_DIR}/)
target_link_libraries(${TARGET_APP} PRIVATE GenericCore)
target_include_directories(${TARGET_APP} PRIVATE ${QR_LIB_DIR}/src)
target_link_libraries(${TARGET_APP} PRIVATE qrcode)
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.

View File

@ -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);
}

View File

@ -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

View File

@ -10,6 +10,7 @@
#include <QPushButton>
#include <QSpinBox>
#include <QTableView>
#include "model/metadata.h"
ItemDetailMapper::ItemDetailMapper(QWidget* parent)
: QWidget{parent} {
@ -101,12 +102,13 @@ bool ItemDetailMapper::submit() { return m_mapper->submit(); }
void ItemDetailMapper::revert() { m_mapper->revert(); }
void ItemDetailMapper::onCurrentIndexChanged(const QModelIndex& current,
const QModelIndex& previous) {
const QModelIndex& /*previous*/) {
if (!isEnabled()) {
setEnabled(true);
}
m_mapper->setCurrentModelIndex(current);
updateButtons(current.row());
emitContentChanged(current);
}
void ItemDetailMapper::rowsInserted(const QModelIndex& parent, int start, int end) {
@ -147,3 +149,12 @@ void ItemDetailMapper::updateButtons(int row) {
m_previousButton->setEnabled(row > 0);
m_nextButton->setEnabled(row < m_model->rowCount() - 1);
}
void ItemDetailMapper::emitContentChanged(const QModelIndex& currentIndex) {
// BUG QR-Code isn't updated after changes through the ItemDetailMapper #18
QString toStringText = "";
if (currentIndex.isValid()) {
toStringText = currentIndex.data(ToStringRole).toString();
}
emit contentChanged(toStringText);
}

View File

@ -24,6 +24,7 @@ class ItemDetailMapper : public QWidget {
void revert();
signals:
void contentChanged(const QString text);
private slots:
void onCurrentIndexChanged(const QModelIndex& current, const QModelIndex& previous);
@ -32,6 +33,7 @@ class ItemDetailMapper : public QWidget {
void toPrevious();
void toNext();
void updateButtons(int row);
void emitContentChanged(const QModelIndex& currentIndex);
private:
/// *** members ***