/*************************************************************************** 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 #include #include #include 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 standardItemsList; for( int idx : cols ) { if( entries.size() > idx ) standardItemsList.append( new QStandardItem( entries[idx] ) ); } _csvModel.insertRow( _csvModel.rowCount(), standardItemsList ); } file.close(); }