first re-commit.
This commit is contained in:
81
libMiniCash/mcvendorsdialog.cpp
Normal file
81
libMiniCash/mcvendorsdialog.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/***************************************************************************
|
||||
|
||||
miniCash
|
||||
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 <QFile>
|
||||
#include <QDebug>
|
||||
|
||||
#include <mcvendorsdialog.h>
|
||||
#include <ui_mcvendorsdialog.h>
|
||||
|
||||
MCVendorsDialog::MCVendorsDialog( QWidget* parent, const QString& filePath )
|
||||
: QDialog( parent ), _ui{new Ui::MCVendorsDialog}
|
||||
|
||||
{
|
||||
_ui->setupUi( this );
|
||||
loadVendorsFile( filePath );
|
||||
|
||||
connect( _ui->_buttonOk, &QPushButton::clicked, this,
|
||||
[=]
|
||||
{
|
||||
accept();
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
MCVendorsDialog::~MCVendorsDialog()
|
||||
{
|
||||
delete _ui;
|
||||
}
|
||||
|
||||
|
||||
void MCVendorsDialog::loadVendorsFile( const QString& filePath )
|
||||
{
|
||||
|
||||
QFile file( filePath );
|
||||
|
||||
if( !file.open(QFile::ReadOnly | QFile::Text) )
|
||||
return;
|
||||
|
||||
/// Create a data model for the mapping table from a CSV file
|
||||
int cols[]{ 0, 3, 4, 5 };
|
||||
_csvModel.setColumnCount( 4 );
|
||||
_csvModel.setHorizontalHeaderLabels( QStringList( {"Nummer", "Name", "Anschrift", "Telephon"} ) );
|
||||
_ui->_vendorsView->setModel( &_csvModel );
|
||||
_ui->_vendorsView->setStyleSheet("QHeaderView::section { background-color:#eeeeee }");
|
||||
_ui->_vendorsView->setCornerButtonEnabled( false );
|
||||
// Open the file from the resources. Instead of the file
|
||||
// Need to specify the path to your desired file
|
||||
|
||||
// Create a thread to retrieve data from a file
|
||||
QTextStream in( &file );
|
||||
in.readLine();
|
||||
//Reads the data up to the end of file
|
||||
while( !in.atEnd() )
|
||||
{
|
||||
QStringList entries = in.readLine().split( "\t" );
|
||||
// Adding to the model in line with the elements
|
||||
QList<QStandardItem *> standardItemsList;
|
||||
|
||||
for( int idx : cols )
|
||||
{
|
||||
if( entries.size() > idx )
|
||||
standardItemsList.append( new QStandardItem( entries[idx] ) );
|
||||
}
|
||||
|
||||
_csvModel.insertRow( _csvModel.rowCount(), standardItemsList );
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
}
|
Reference in New Issue
Block a user