108 lines
2.5 KiB
C++
108 lines
2.5 KiB
C++
/***************************************************************************
|
|
|
|
libMiniCash
|
|
Copyright © 2013-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 <QtGui>
|
|
#include <QtCore>
|
|
#include <QMessageBox>
|
|
#include <mceditdialog.h>
|
|
#include <mceditdialog.h>
|
|
#include <ui_mceditdialog.h>
|
|
|
|
|
|
/**
|
|
* @brief Erzeugt das Dialogfenster, im dem die Kassendatei editiert
|
|
* werden kann.
|
|
* @param parent das Elternfenster
|
|
* @param filename der Name der Kassendatei
|
|
*/
|
|
|
|
MCEditDialog::MCEditDialog( QWidget* parent, const QString& filename ) :
|
|
QDialog( parent ),
|
|
_filename( filename )
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
// Murx, FIX! das sollte über den Translator gehen
|
|
buttonBox->button( QDialogButtonBox::Ok )->setText( "Kassendatei Speichern" );
|
|
buttonBox->button( QDialogButtonBox::Cancel )->setText( "Abbrechen" );
|
|
|
|
connect( buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
|
connect( buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
connect( _startSearch, SIGNAL(clicked()), this, SLOT( onSearch() ) );
|
|
|
|
onLoadFile();
|
|
|
|
}
|
|
|
|
|
|
MCEditDialog::~MCEditDialog()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief lädt die Kassendatei
|
|
*/
|
|
|
|
void MCEditDialog::onLoadFile()
|
|
{
|
|
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;
|
|
}
|
|
|
|
_trSalesText->setPlainText( file.readAll() );
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Durchsucht die Kassendatei nach einen Schlüsselbegriff
|
|
*/
|
|
|
|
void MCEditDialog::onSearch()
|
|
{
|
|
QString src =_searchString->text();
|
|
_trSalesText->find( src );
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief sichert die ggf. geänderte Kassendatei
|
|
*/
|
|
|
|
void MCEditDialog::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();
|
|
|
|
}
|