Skip to content

Commit

Permalink
The scaned picture is enabled as an alternative view of the card
Browse files Browse the repository at this point in the history
  • Loading branch information
belohoub committed Apr 11, 2024
1 parent 7a7854d commit b76c481
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 237 deletions.
1 change: 0 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ set(ubcards_SRCS
qrcodereader.cpp
qrcodegenerator.cpp
qrcodeimageprovider.cpp
historymodel.cpp
filehelper.cpp
cardstorage.cpp
cardstoragemodel.cpp
Expand Down
22 changes: 21 additions & 1 deletion app/cardstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,36 @@ CardStorage::CardStorage(QObject *parent) :

m_storageModel = new CardStorageModel(this);

/* No image */
m_image = QImage();
m_imageID = "";

/* TODO add signals/slots */

}

/**
* Prepare an image to save image
*
* When ID is empty string, image for the ID is NOT updated
*
*/
void CardStorage::updateImage(const QString &id, const QImage &image) {
m_image = image;
m_imageID = id;
}

void CardStorage::updateCard(const QString &id, const QString &text, const QString &type, const QString &name, const QString &category) {
if (!m_storageModel->setCardById(id, text, type, name, category)) {
/* In case of invalid ID, insert a new card */
QString newId = m_storageModel->add(text, type, name, category, QImage());
QString newId = m_storageModel->add(text, type, name, category, m_image);
}

/* No image - the Image has been already used */
m_image = QImage();
m_imageID = "";


/* emit signal with added ID */
emit cardUpdated();
}
Expand Down
4 changes: 4 additions & 0 deletions app/cardstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CardStorage : public QObject, public QQuickImageProvider
CardStorageModel* storage() const;

Q_INVOKABLE void updateCard(const QString &id, const QString &text, const QString &type, const QString &name, const QString &category);
Q_INVOKABLE void updateImage(const QString &id, const QImage &image);

public slots:

Expand All @@ -52,6 +53,9 @@ private slots:
QQuickWindow *m_mainWindow;

CardStorageModel *m_storageModel;

QImage m_image;
QString m_imageID;
};


Expand Down
14 changes: 11 additions & 3 deletions app/cardstoragemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ int CardStorageModel::rowCount(const QModelIndex &parent) const
return m_settings.value("all").toStringList().count();
}

QVariant CardStorageModel::data(const QModelIndex &index, int role) const
QVariant CardStorageModel::dataById(const QString &id, int role) const
{
QVariant ret;
QString id = m_settings.value("all").toStringList().at(index.row());

m_settings.beginGroup(id);
switch (role) {
case RoleText:
Expand All @@ -63,7 +63,8 @@ QVariant CardStorageModel::data(const QModelIndex &index, int role) const
ret = m_settings.value("category");
break;
case RoleImageSource:
ret = "image://history/" + id;
//ret = "image://history/" + id;
ret = m_storageLocation + id + ".jpg";
break;
case RoleTimestamp:
ret = m_settings.value("timestamp").toDateTime().toString();
Expand All @@ -74,6 +75,13 @@ QVariant CardStorageModel::data(const QModelIndex &index, int role) const
return ret;
}

QVariant CardStorageModel::data(const QModelIndex &index, int role) const
{
QString id = m_settings.value("all").toStringList().at(index.row());

return dataById(id, role);
}


QHash<int, QByteArray> CardStorageModel::roleNames() const
{
Expand Down
1 change: 1 addition & 0 deletions app/cardstoragemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CardStorageModel: public QAbstractListModel, public QQuickImageProvider

int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant dataById(const QString &id, int role) const;
QHash<int, QByteArray> roleNames() const override;

QString add(const QString &text, const QString &type, const QString &name, const QString &category, const QImage &image);
Expand Down
120 changes: 0 additions & 120 deletions app/historymodel.cpp

This file was deleted.

38 changes: 0 additions & 38 deletions app/historymodel.h

This file was deleted.

2 changes: 0 additions & 2 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ int main(int argc, char *argv[])

FileHelper fh;
qmlRegisterType<QRCodeGenerator>("UBcards", 0, 1, "QRCodeGenerator");
qmlRegisterUncreatableType<HistoryModel>("UBcards", 0, 1, "HistoryModel", "use qrCodeReader.history");

CardStorage storage;
view.engine()->rootContext()->setContextProperty("cardStorage", &storage);
qmlRegisterUncreatableType<CardStorageModel>("UBcards", 0, 1, "CardStorageModel", "use cardStorage.model");

view.engine()->addImageProvider(QStringLiteral("qrcode"), new QRCodeImageProvider);
view.engine()->addImageProvider(QStringLiteral("reader"), &reader);
view.engine()->addImageProvider(QStringLiteral("history"), reader.history());

view.engine()->rootContext()->setContextProperty(QStringLiteral("fileHelper"), &fh);

Expand Down
5 changes: 4 additions & 1 deletion app/qml/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function stringToBarcode (type, str)
{
switch (type)
{
case undefined:
case undefined:case undefined:
case 'CODE-128':
if (/^-?\d+$/.test(str)) {
/* Numeric-only codes are type C*/
Expand All @@ -62,6 +62,9 @@ function stringToBarcode (type, str)

case 'CODE-39':
return "*" + str.toUpperCase().replace (/[^A-Z\s\d-$%./+]/g, "") + "*";

case 'PICTURE':
return "";
}
}

Expand Down
27 changes: 15 additions & 12 deletions app/qml/ubcards.qml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ MainView {
ListElement { name: "EAN-8" ; font: "../fonts/ean13_new.ttf" }
ListElement { name: "I2/5" ; font: "../fonts/I2of5_new.ttf" }
ListElement { name: "QR-Code" ; font: "" }
ListElement { name: "PICTURE" ; font: "" }
}

Component {
Expand Down Expand Up @@ -208,16 +209,15 @@ MainView {

onValidChanged: {
if (qrCodeReader.valid) {
// A New card has been scanned
if (pageStack.depth > 1) {
/* When existing card is modified, the editCard view is already opened, the current depth is 2 */
/* First, close the old editCartd view */
/* First, close the old views */
pageStack.pop()
/* Now open the viewCard view for a modified card */
pageStack.push(editPageComponent, {type: qrCodeReader.type, text: qrCodeReader.text, name: qrCodeReader.name, category: qrCodeReader.category, imageSource: qrCodeReader.imageSource, editable: false, cardID: qrCodeReader.ID});
} else {
/* When new card is created, editCard view will be opened at depth 2, the current depth is 1 */
pageStack.push(editPageComponent, {type: qrCodeReader.type, text: qrCodeReader.text, name: qrCodeReader.name, category: qrCodeReader.category, imageSource: qrCodeReader.imageSource, editable: true});
}

/* Open the editCard view for a new card */
cardStorage.updateImage("", qrCodeReader.image);
pageStack.push(editPageComponent, {type: qrCodeReader.type, text: qrCodeReader.text, name: qrCodeReader.name, category: qrCodeReader.category, imageSource: qrCodeReader.imageSource, editable: true});
}
}
}
Expand Down Expand Up @@ -949,17 +949,20 @@ MainView {
}
}

/* This should be visible only if code-type generation is not available */
/* This should be visible only if code-type generation is not available OR PICTURE code type is selected */
Item {
width: parent.width
height: (!(hasCodeFont(editPage.type))) ? cardCodeImage.height : 0
visible: !(hasCodeFont(editPage.type))
height: (editPage.type === "PICTURE") ? cardCodeImage.height : 0
visible: (editPage.type === "PICTURE")

Image {
Layout.fillWidth: true
id: cardCodeImage
visible: !(hasCodeFont(editPage.type))
source: hasCodeFont(editPage.type) ? "" : editPage.imageSource
width: parent.width - units.gu(5)
anchors.margins: units.gu(5)
anchors.centerIn: parent
visible: (editPage.type === "PICTURE")
source: (editPage.type === "PICTURE") ? editPage.imageSource : ""
}
}

Expand Down
Loading

0 comments on commit b76c481

Please sign in to comment.