152 lines
4.1 KiB
C++
152 lines
4.1 KiB
C++
/***************************************************************************
|
|
|
|
miniCashConnect
|
|
Copyright © 2022 christoph holzheuer
|
|
c.holzheuer@sourceworx.org
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <mcceditview.h>
|
|
#include <mcsalesitemmap.h>
|
|
#include <mcsalesmodel.h>
|
|
#include <ui_mcceditview.h>
|
|
|
|
|
|
/**
|
|
* @brief Default Konstruktor
|
|
* @param parent
|
|
*/
|
|
|
|
MCCEditView::MCCEditView( QWidget* parent )
|
|
: QWidget( parent )
|
|
|
|
{
|
|
setupUi( this );
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Default Destruktor
|
|
*/
|
|
|
|
MCCEditView::~MCCEditView()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void MCCEditView::setupDefaults( MCMainWindowBase* parent )
|
|
{
|
|
_parent = parent;
|
|
Q_ASSERT( _parent != nullptr );
|
|
|
|
/// model setzen:
|
|
_trList->setModel( &_salesModel );
|
|
|
|
_valCustId.setRegularExpression( QRegularExpression( miniCash::fCustID ) ); // Validator für die Kundennnummer
|
|
_valItemNo.setRegularExpression( QRegularExpression( miniCash::fItemNo ) ); // Validator für die Kundennnummer; // Validator für die laufende Nummer des Artikels
|
|
_valPrice.setRegularExpression( QRegularExpression( miniCash::fPrice ) ); // Validator für die Kundennnummer; // Validator für die Preisangabe
|
|
|
|
/*
|
|
_trSellerID->setValidator( &_valCustId );
|
|
_trItemNo->setValidator( &_valItemNo );
|
|
_trPrice->setValidator( &_valPrice );
|
|
*/
|
|
|
|
/*
|
|
// Doppelklick auf einen Eintrag in der View soll diesen löschen
|
|
connect( _trList, SIGNAL( doubleClicked(QModelIndex) ), this, SLOT( onRemoveEntry(QModelIndex)) );
|
|
|
|
// hosianna : key event handling ist gar nicht nötig
|
|
QShortcut* shortcutPayback = new QShortcut( QKeySequence( Qt::Key_F1 ), this );
|
|
QShortcut* shortcutSave = new QShortcut( QKeySequence( Qt::Key_F12 ), this );
|
|
|
|
connect( shortcutPayback, SIGNAL(activated()), this, SLOT( onCalculatePayback()) );
|
|
connect( shortcutSave, SIGNAL(activated()), _parent, SLOT( onSaveTransaction()) );
|
|
|
|
// Alle Transaktionen sichern
|
|
connect( _trOK, SIGNAL(clicked()), _parent, SLOT( onSaveTransaction()) );
|
|
|
|
// Felder auch mit Enter weiterschalten
|
|
connect( _trSellerID, SIGNAL(returnPressed()), this, SLOT( onMoveInputFocus()) );
|
|
connect( _trItemNo, SIGNAL(returnPressed()), this, SLOT( onMoveInputFocus()) );
|
|
|
|
// Transaktion fertig eingegeben? Dann prüfen
|
|
connect( _trPrice, SIGNAL(editingFinished()),this, SLOT( onAddSalesItem()) );
|
|
|
|
_trPos->setText( "1" );
|
|
_trCount->setText( _parent->transCount() );
|
|
*/
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief lädt die Kassendatei
|
|
*/
|
|
|
|
void MCCEditView::loadTransactions( const QString& fileName )
|
|
{
|
|
|
|
QFile file( fileName );
|
|
if( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
|
{
|
|
QString msg( "Datei '%0' konnte nicht geöffnet werden.\nFehlercode: %1" );
|
|
QMessageBox::warning( this, "Dateifehler", msg.arg( fileName, file.errorString() ) );
|
|
return;
|
|
}
|
|
|
|
QTextStream inputStream(&file);
|
|
/// nicht aggregieren
|
|
|
|
///_salesModel.clear(); <-- löscht den Header mit
|
|
///_salesModel.removeRows( 0, _salesModel.rowCount() );
|
|
/// anhängen
|
|
_salesModel.appendTransactions( inputStream );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @brief Durchsucht die Kassendatei nach einen Schlüsselbegriff
|
|
*/
|
|
|
|
void MCCEditView::onSearch()
|
|
{
|
|
/*
|
|
QString src =_searchString->text();
|
|
_trSalesText->find( src );
|
|
*/
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief sichert die ggf. geänderte Kassendatei
|
|
*/
|
|
|
|
void MCCEditView::accept()
|
|
{
|
|
// sichern
|
|
/*
|
|
QFile file( _filename );
|
|
if( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
|
|
{
|
|
QString msg( "Datei '%0' konnte nicht geschrieben werden.\nFehlercode: %1" );
|
|
QMessageBox::warning( this, "Dateifehler", msg.arg( _filename, file.errorString() ) );
|
|
return;
|
|
}
|
|
|
|
file.write(_trSalesText->toPlainText().toLatin1() );
|
|
|
|
return QDialog::accept();
|
|
*/
|
|
}
|