Commit eaf56f88 authored by Allan Anderson's avatar Allan Anderson
Browse files

BUG:309774 - Add capability to copy an investment activity type or...

BUG:309774 - Add capability to copy an investment activity type or detail/description to memo field.
parent e1731c69
......@@ -276,7 +276,7 @@ void CSVDialog::init()
connect(m_pageSeparator->ui->comboBox_fieldDelimiter, SIGNAL(currentIndexChanged(int)), m_investProcessing, SLOT(fieldDelimiterChanged()));
connect(m_pageSeparator->ui->comboBox_fieldDelimiter, SIGNAL(activated(int)), m_investProcessing, SLOT(fieldDelimiterChanged()));
connect(m_pageSeparator->ui->comboBox_fieldDelimiter, SIGNAL(activated(int)), m_pageSeparator, SLOT(delimiterActivated(int)));
connect(m_pageSeparator->ui->comboBox_fieldDelimiter, SIGNAL(activated(int)), m_pageSeparator, SLOT(delimiterActivated()));
connect(m_pageSeparator->ui->comboBox_fieldDelimiter, SIGNAL(activated(int)), this, SLOT(delimiterChanged()));
connect(m_pageSeparator->ui->comboBox_fieldDelimiter, SIGNAL(currentIndexChanged(int)), this, SLOT(delimiterChanged()));
......@@ -404,6 +404,9 @@ void CSVDialog::readSettings()
if (!found) {
return;
}
// Allow payee col to be set here.
connect(m_pageBanking->ui->comboBoxBnk_payeeCol, SIGNAL(currentIndexChanged(int)), this, SLOT(payeeColumnSelected(int)));
disconnect(m_pageLinesDate->ui->spinBox_skip, SIGNAL(valueChanged(int)), this, SLOT(startLineChanged(int)));
m_profileExists = true;
QString txt = "Profiles-" + m_profileList[i];
......@@ -486,6 +489,8 @@ void CSVDialog::readSettings()
break;
}
connect(m_pageLinesDate->ui->spinBox_skip, SIGNAL(valueChanged(int)), this, SLOT(startLineChanged(int)));
// Index change after an activate, when payeeColumnCopy(), causes a second connect with confusing msg. so...
disconnect(m_pageBanking->ui->comboBoxBnk_payeeCol, SIGNAL(currentIndexChanged(int)), this, SLOT(payeeColumnSelected(int)));
}
void CSVDialog::reloadUISettings()
......@@ -712,6 +717,7 @@ void CSVDialog::readFile(const QString& fname)
}
m_importError = false;
m_payeeColAdded = false;
int columnCount = 0;
MyMoneyStatement st = MyMoneyStatement();
if (!fname.isEmpty()) {
......@@ -776,7 +782,8 @@ void CSVDialog::readFile(const QString& fname)
}
ui->tableWidget->setColumnCount(m_maxColumnCount + 1);
m_lineNum = 0;
int delimiterCount[4] = {0};
int totalDelimiterCount[4] = {0};
m_possibleDelimiter = 0;
if (m_firstRead) {
m_importIsValid = false;
......@@ -785,9 +792,10 @@ void CSVDialog::readFile(const QString& fname)
for (int i = 0; i < m_lineList.count(); i++) {
QString data = m_lineList[i];
for (int count = 0; count < 4; count++) { // Four possible delimiters
// Count delimiters to find most likely one to use .
delimiterCount[count] = data.count(m_parse->m_fieldDelimiterCharList[count]);
if (delimiterCount[count] > delimiterCount[m_possibleDelimiter]) {
// Count delimiters to find most likely one to use.
// Changed to sum total file, not just individual lines.
totalDelimiterCount[count] += data.count(m_parse->m_fieldDelimiterCharList[count]);
if (totalDelimiterCount[count] > totalDelimiterCount[m_possibleDelimiter]) {
m_possibleDelimiter = count;
}
}
......@@ -820,7 +828,6 @@ void CSVDialog::readFile(const QString& fname)
m_pageBanking->ui->comboBoxBnk_debitCol->addItem(t);
// Will have to reload comboboxes after exit.
}
m_columnTypeList<<QString(); // need one extra for payee column copy
m_firstRead = false;
}
if (m_fileEndLine == 0) {
......@@ -829,7 +836,7 @@ void CSVDialog::readFile(const QString& fname)
if (m_fileEndLine > m_pageLinesDate->m_trailerLines) {
m_endLine = m_fileEndLine - m_pageLinesDate->m_trailerLines;
} else {
m_endLine = m_fileEndLine; // Ignore m_trailerLines as > file length.
m_endLine = m_fileEndLine; // Ignore m_trailerLines as > file length.
}
m_pageLinesDate->ui->spinBox_skip->setMaximum(m_fileEndLine);
m_pageLinesDate->ui->spinBox_skipToLast->setMaximum(m_fileEndLine);
......@@ -846,7 +853,6 @@ void CSVDialog::readFile(const QString& fname)
connect(m_pageBanking->ui->comboBoxBnk_numberCol, SIGNAL(activated(int)), this, SLOT(numberColumnSelected(int)));
connect(m_pageBanking->ui->comboBoxBnk_dateCol, SIGNAL(currentIndexChanged(int)), this, SLOT(dateColumnSelected(int)));
connect(m_pageBanking->ui->comboBoxBnk_dateCol, SIGNAL(activated(int)), this, SLOT(dateColumnSelected(int)));
connect(m_pageBanking->ui->comboBoxBnk_payeeCol, SIGNAL(currentIndexChanged(int)), this, SLOT(payeeColumnSelected(int)));
connect(m_pageBanking->ui->comboBoxBnk_payeeCol, SIGNAL(activated(int)), this, SLOT(payeeColumnSelected(int)));
m_pageLinesDate->ui->spinBox_skipToLast->setValue(m_endLine);
......@@ -870,8 +876,8 @@ void CSVDialog::readFile(const QString& fname)
// user now ready to continue && line is in wanted range
//
if ((m_importNow) && (line >= m_startLine - 1) && (line <= m_pageLinesDate->ui->spinBox_skipToLast->value() - 1)) {
reloadUISettings(); // Need to reload column settings
int ret = (processQifLine(m_inBuffer)); // parse a line
reloadUISettings(); // Need to reload column settings
int ret = processQifLine(m_inBuffer); // parse a line
if (ret == KMessageBox::Ok) {
csvImportTransaction(st);
} else
......@@ -938,21 +944,22 @@ void CSVDialog::displayLine(const QString& data)
// split data into fields
//
m_columnList = m_parse->parseLine(data);
m_endColumn = m_maxColumnCount;
if ((m_memoColCopied) || (m_payeeColCopied)) {
while (m_columnList.count() < m_maxColumnCount) {
m_columnList << ""; // Get m_columnList to correct size
}
}
// If making copy of memocol or payeecol, check the columns actually exist...
if ((!m_firstPass) && (m_payeeColumn <= m_columnCountList[m_lineNum]) && (m_memoColumn <= m_columnCountList[m_lineNum])) {
if ((m_memoColCopied) && (m_memoColCopy < m_columnList.count())) { // but exclude short header lines
m_columnList<<m_columnList[m_memoColCopy];
} else if ((m_payeeColCopied) && (m_payeeColumn < m_columnList.count())) { // but exclude short header lines
m_columnList<<m_columnList[m_payeeColumn];
m_columnTypeList[m_columnList.count() - 1] = "memo";
for (int i = 0; i < m_memoColList.count(); i++) {
if (m_memoColList[i] == m_payeeColumn) {
continue;
}
m_columnTypeList[m_memoColList[i]] = "memo";
}
if ((m_memoColCopied) && (m_memoColCopy < m_columnList.count())) { // ...then make the copy here
m_columnList[m_endColumn - 1] = m_columnList[m_payeeColumn];
m_columnTypeList[m_columnTypeList.count() - 1] = "memo";
} else if ((m_payeeColCopied) && (m_payeeColumn < m_columnList.count())) { // ...or here
m_columnList[m_endColumn - 1] = m_columnList[m_payeeColumn];
m_columnTypeList[m_columnTypeList.count() - 1] = "memo";
}
}
m_inBuffer.clear();
QStringList::const_iterator constIterator;
QString txt;
......@@ -1040,7 +1047,7 @@ int CSVDialog::processQifLine(QString& iBuff) // parse input line
iBuff = iBuff.remove(m_textDelimiterCharacter);
memo.clear();// memo & number may not have been used
m_trData.number.clear();// .. so need to clear prior contents
for (int i = 0; i < m_columnList.count(); i++) { // check each column
for (int i = 0; i < m_columnList.count(); i++) {
// Use actual column count for this line instead of m_endColumn, which could be greater.
if (m_columnTypeList[i] == "number") {
txt = m_columnList[i];
......@@ -1069,7 +1076,6 @@ int CSVDialog::processQifLine(QString& iBuff) // parse input line
txt = txt.remove('\'');
if ((!m_firstPass) && (m_memoColCopied)) {
m_columnList[m_payeeColumn] = txt ;
columnType(m_memoColumn) = "memo";
}
m_trData.payee = txt;
m_qifBuffer = m_qifBuffer + 'P' + txt + '\n'; // Detail column
......@@ -1151,8 +1157,9 @@ int CSVDialog::processQifLine(QString& iBuff) // parse input line
txt = m_columnList[m_payeeColumn];
m_columnList[i] = txt;
}
if (!memo.isEmpty())
if (!memo.isEmpty()) {
memo += '\n';// separator for multiple memos
}
memo += txt;// next memo
}//end of memo field
}//end of col loop
......@@ -1248,7 +1255,7 @@ void CSVDialog::slotImportClicked()
}
if ((m_dateSelected) && (m_payeeSelected) &&
((m_amountSelected || (m_debitSelected && m_creditSelected)))) {
m_importNow = true; // all necessary data is present
m_importNow = true; // all necessary data is present
int skp = m_pageLinesDate->ui->spinBox_skip->value() - 1;
if (skp > m_endLine) {
......@@ -1257,7 +1264,7 @@ void CSVDialog::slotImportClicked()
m_importError = true;
return;
}
if (m_importError) { // possibly from wrong decimal symbol
if (m_importError) { // possibly from wrong decimal symbol or date format
return;
}
m_parse->setSymbolFound(false);
......@@ -1318,6 +1325,7 @@ int CSVDialog::columnNumber(const QString& msg)
void CSVDialog::clearColumnsSelected()
{
// User has clicked clear button
if (m_fileType == "Banking") {
clearPreviousColumn();
clearSelectedFlags();
......@@ -1332,7 +1340,11 @@ void CSVDialog::clearColumnsSelected()
void CSVDialog::clearSelectedFlags()
{
for (int i = 0; i < m_maxColumnCount; i++) {
m_columnTypeList[i].clear(); // set to all empty
m_columnTypeList[i].clear(); // set to all empty but keep size
}
if (m_columnTypeList.contains("memo")) { // need to remove a payee copy item
int pos = m_columnTypeList.indexOf("memo");
m_columnTypeList.takeAt(pos);
}
m_dateSelected = false;
......@@ -1627,14 +1639,14 @@ int CSVDialog::validateColumn(const int& col, QString& type)
if ((!m_pageBanking->m_bankingPageInitialized) || (m_fileType != "Banking")) {
return KMessageBox::Ok;
}
if (m_columnsNotSet) { // Don't check columns until they've been selected.
if (m_columnsNotSet) { // Don't check columns until they've been selected.
return KMessageBox::Ok;
}
// First check if selection is in range
if ((col < 0) || (col >= m_endColumn)) {
return KMessageBox::No;
}
// selection is in range
// selection is in range
if (m_columnTypeList[col] == type) {// already selected
return KMessageBox::Ok;
}
......@@ -1660,9 +1672,16 @@ int CSVDialog::validateColumn(const int& col, QString& type)
m_memoColCopied = true;
m_memoColCopy = col;
m_pageBanking->ui->comboBoxBnk_memoCol->setItemText(col, QString().setNum(col + 1) + '*');
m_payeeColumn = m_endColumn;
type = "payee";
m_columnTypeList[m_payeeColumn] = "payee";
m_payeeColumn = col;
m_columnTypeList[col] = type;
m_columnTypeList << "memo"; // the payeecolumn copy goes here
if (m_columnList.count() < m_columnTypeList.count()) {
m_columnList << "";
m_maxColumnCount ++;
m_endColumn ++;
}
m_memoColumn = m_endColumn;
m_payeeSelected = true;
m_columnCountList << m_maxColumnCount + 1;
return rc;
......@@ -1807,7 +1826,7 @@ void CSVDialog::dateColumnSelected(int col)
int ret = validateColumn(col, type);
if (ret == KMessageBox::Ok) {
m_pageBanking->ui->comboBoxBnk_dateCol->setCurrentIndex(col); // accept new column
m_pageBanking->ui->comboBoxBnk_dateCol->setCurrentIndex(col); // accept new column
m_dateSelected = true;
m_dateColumn = col;
m_columnTypeList[m_dateColumn] = type;
......@@ -1820,13 +1839,11 @@ void CSVDialog::dateColumnSelected(int col)
void CSVDialog::memoColumnSelected(int col)
{
if (!m_pageBanking->m_bankingPageInitialized) {
return;
}
if ((col < 0) || (col >= m_endColumn)) { // out of range so...
m_pageBanking->ui->comboBoxBnk_memoCol->setCurrentIndex(-1); // ..clear selection
return;
}
// Prevent check of column settings until user sees them.
if ((col < 0) || (col >= m_endColumn) || (m_columnsNotSet)) { // out of range so...
m_pageBanking->ui->comboBoxBnk_memoCol->setCurrentIndex(-1); // ..clear selection
return;
}
QString type = "memo";
m_memoColumn = col;
......@@ -1847,24 +1864,34 @@ void CSVDialog::memoColumnSelected(int col)
return;
}
if (m_columnTypeList[col] == "payee") {
if (m_memoColList.contains(col)) {
return;
if ((m_memoColList.contains(col)) && (m_payeeColAdded)) {
return; // This copypayee column has been added already, probably from resource file
}
if (m_pageBanking->isVisible()) {
int rc = KMessageBox::questionYesNo(0, i18n("<center>The '<b>%1</b>' field already has this column selected.</center>"
int rc = KMessageBox::Yes;
if (m_pageBanking->isVisible()) { // Don't show msg. if we got here from resource file load
rc = KMessageBox::questionYesNo(0, i18n("<center>The '<b>%1</b>' field already has this column selected.</center>"
"<center>If you wish to copy the Payee data to the memo field, click 'Yes'.</center>",
m_columnTypeList[col]));
}
if (rc == KMessageBox::Yes) {
m_payeeColCopied = true;
m_payeeColAdded = true; // Indicate that extra col has been added alread
m_pageBanking->ui->comboBoxBnk_memoCol->setItemText(col, QString().setNum(col + 1) + '*');
if (!m_memoColList.contains(col)) {
m_memoColList << col;
}
m_columnTypeList << "memo";
if (m_columnList.count() < m_columnTypeList.count()) {
m_columnList << "";
m_maxColumnCount ++;
m_endColumn ++;
}
m_memoColumn = m_endColumn;
m_memoColList << col;
m_columnTypeList[m_memoColumn] = "memo";
m_memoSelected = true;
m_columnCountList << m_maxColumnCount + 1;
return;
}
}
} else {
// clashes with prior selection
m_memoSelected = false;// clear incorrect selection
......@@ -1885,7 +1912,7 @@ void CSVDialog::memoColumnSelected(int col)
void CSVDialog::payeeColumnSelected(int col)
{
if (col < 0) { // it is unset
if (col < 0) { // it is unset
m_wizard->button(QWizard::NextButton)->setEnabled(false);
return;
}
......@@ -2114,6 +2141,10 @@ void CSVDialog::dateFormatSelected(int dF)
}
m_dateFormatIndex = dF;
m_date = m_dateFormats[m_dateFormatIndex];
if (m_importError) {
readFile(m_inFileName);
markUnwantedRows();
}
}
void CSVDialog::decimalSymbolSelected(int index)
......@@ -2236,7 +2267,7 @@ void CSVDialog::delimiterChanged()
disconnect(m_pageSeparator->ui->comboBox_fieldDelimiter, SIGNAL(currentIndexChanged(int)), this, SLOT(delimiterChanged()));
m_pageSeparator->ui->comboBox_fieldDelimiter->setCurrentIndex(m_possibleDelimiter);
m_lastDelimiterIndex = newIndex;
m_pageSeparator->delimiterActivated(m_fieldDelimiterIndex);
m_pageSeparator->delimiterActivated();
break;
}
m_importNow = false;
......@@ -2431,7 +2462,6 @@ void CSVDialog::slotNamesEdited()
}
// Replace detail with edited security name.
str = m_symbolTableDlg->m_widget->tableWidget->item(symTableRow, 2)->text();
ui->tableWidget->item(row, m_investProcessing->detailColumn())->setText(str);
m_investProcessing->m_map.insert(m_symbolTableDlg->m_widget->tableWidget->item(symTableRow, 0)->text(), m_symbolTableDlg->m_widget->tableWidget->item(symTableRow, 2)->text());
symTableRow ++;
......@@ -3142,7 +3172,7 @@ void SeparatorPage::initializePage()
}
}
void SeparatorPage::delimiterActivated(int /*index*/)
void SeparatorPage::delimiterActivated()
{
emit completeChanged();
if ((m_dlg->m_delimiterError) && (m_dlg->m_fileType == "Invest")) {
......@@ -3471,6 +3501,7 @@ void LinesDatePage::initializePage()
m_dlg->m_pageLinesDate->ui->spinBox_skipToLast->setMinimum(m_dlg->startLine());
} else if (m_dlg->m_fileType == "Invest") {
m_dlg->m_pageLinesDate->ui->spinBox_skipToLast->setMinimum(m_dlg->m_investProcessing->m_startLine);
m_dlg->m_pageLinesDate->ui->spinBox_skipToLast->setValue(m_dlg->m_investProcessing->m_endLine);
}
}
......@@ -3491,10 +3522,10 @@ bool LinesDatePage::validatePage()
if (m_dlg->m_fileType == "Banking") {
for (int row = m_dlg->startLine() - 1; row < m_dlg->lastLine(); row++) {
for (int col = 0; col < m_dlg->ui->tableWidget->columnCount(); col++) {
if ((m_dlg->columnType(col) == "amount") || (m_dlg->columnType(col) == "debit") || (m_dlg->columnType(col) == "credit")) {
if (m_dlg->ui->tableWidget->item(row, col) == 0) { // Does cell exist?
if (m_dlg->ui->tableWidget->item(row, col) == 0) { // Does cell exist?
break; // No.
}
if ((m_dlg->columnType(col) == "amount") || (m_dlg->columnType(col) == "debit") || (m_dlg->columnType(col) == "credit")) {
value = m_dlg->ui->tableWidget->item(row, col)->text().remove(QRegExp(pattern));
if (value.isEmpty()) { // An empty cell is OK, probably.
continue;
......
......@@ -431,6 +431,7 @@ private:
bool m_payeeSelected;
bool m_memoColCopied;
bool m_payeeColCopied;
bool m_payeeColAdded;
int m_amountColumn;
int m_creditColumn;
......@@ -664,7 +665,7 @@ public:
bool isComplete() const;
public slots:
void delimiterActivated(int /*index*/);
void delimiterActivated();
signals:
void completeChanged();
......
......@@ -52,9 +52,7 @@ QStringList Parse::parseLine(const QString& data)
QString txt1;
m_fieldDelimiterCharacter = m_fieldDelimiterCharList[m_fieldDelimiterIndex];
m_inBuffer = data;
if (m_inBuffer.endsWith(m_fieldDelimiterCharacter)) {
m_inBuffer.chop(1);
}
listIn = m_inBuffer.split(m_fieldDelimiterCharacter); // firstly, split on m_fieldDelimiterCharacter
QStringList::const_iterator constIterator;
......
......@@ -439,9 +439,9 @@ p, li { white-space: pre-wrap; }
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;If a descriptive column contains an activity type, select it here.&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;Except, see Filter text field.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;See also Filter text field.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
......@@ -479,10 +479,10 @@ p, li { white-space: pre-wrap; }
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;If the detail column has an activity type prefixed by a standard text,&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;enter the text here. For instance, if a field contains, say,&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;'type: dividend', enter 'type: '.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;If the Detail column has an activity type prefixed by a standard text,&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;enter the text here. For instance, if a field contains, say,&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;'type: dividend', enter 'type: '.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="trapEnterKeyEvent" stdset="0">
<bool>true</bool>
......
......@@ -198,6 +198,9 @@ void InvestProcessing::slotFileDialogClicked()
m_csvDialog->m_pageLinesDate->m_isColumnSelectionComplete = false;
m_firstPass = true;
m_firstRead = true;
m_memoColCopied = false;
m_typeColCopied = false;
m_detailColCopied = false;
m_csvDialog->m_pageInvestment->m_investPageInitialized = false;
m_csvDialog->m_columnsNotSet = true; // Don't check columns until they've been selected.
m_csvDialog->m_separatorPageVisible = false;
......@@ -334,6 +337,11 @@ void InvestProcessing::clearColumnsSelected()
clearSelectedFlags();
clearColumnNumbers();
clearComboBoxText();
m_memoColCopied = false;
m_typeColCopied = false;
m_detailColCopied = false;
m_memoColList.clear();
}
void InvestProcessing::clearSelectedFlags()
......@@ -449,9 +457,8 @@ int InvestProcessing::validateNewColumn(const int& col, const QString& type)
}
// selection was in range
// ...but does it clash?
if ((!m_columnTypeList[col].isEmpty()) && (m_columnTypeList[col] != type)) { // column is already in use
if ((!m_columnTypeList[col].isEmpty()) && (m_columnTypeList[col] != type) && (m_csvDialog->m_pageInvestment->m_investPageInitialized)) { // column is already in use
KMessageBox::information(0, i18n("The '<b>%1</b>' field already has this column selected. <center>Please reselect both entries as necessary.</center>", m_columnTypeList[col]));
m_previousColumn = -1;
resetComboBox(m_columnTypeList[col], col); // clash, so reset ..
resetComboBox(type, col); // ... both comboboxes
......@@ -559,9 +566,36 @@ void InvestProcessing::memoColumnSelected(int col)
return;
} else if (m_columnTypeList[col] == type) { // nothing changed
return;
} else {
}
if ((m_columnTypeList[col] == "type") || (m_columnTypeList[col] == "detail")) {
if (m_memoColList.contains(col)) {
m_memoColList.removeOne(col);
}
int rc = KMessageBox::Yes;
if (m_csvDialog->m_pageInvestment->isVisible()) {
rc = KMessageBox::questionYesNo(0, i18n("<center>The '<b>%1</b>' field already has this column selected.</center>"
"<center>If you wish to copy that data to the memo field, click 'Yes'.</center>",
m_columnTypeList[col]));
}
if (rc == KMessageBox::Yes) {
if (m_columnTypeList[col] == "type") {
m_typeColCopied = true;
} else if (m_columnTypeList[col] == "detail") {
m_detailColCopied = true;
}
m_csvDialog->m_pageInvestment->ui->comboBoxInv_memoCol->setItemText(col, QString().setNum(col + 1) + '*');
m_endColumn += 1;
m_memoColumn = m_endColumn - 1;
m_memoColList << col;
m_columnTypeList << "memo"; // need one extra for type/detail column copy
m_memoSelected = true;
return;
}
} else { // m_columnTypeList[col] != "type"or "detail"
// clashes with prior selection
m_memoSelected = false;// clear incorrect selection
m_typeColCopied = false;
m_detailColCopied = false;
KMessageBox::information(0, i18n("The '<b>%1</b>' field already has this column selected. <center>Please reselect both entries as necessary.</center>", m_columnTypeList[col]));
m_csvDialog->m_pageInvestment->ui->comboBoxInv_memoCol->setCurrentIndex(-1);
m_previousColumn = -1;
......@@ -762,7 +796,7 @@ void InvestProcessing::fieldDelimiterChanged()
disconnect(m_csvDialog->m_pageSeparator->ui->comboBox_fieldDelimiter, SIGNAL(currentIndexChanged(int)), this, SLOT(delimiterChanged()));
m_csvDialog->m_pageSeparator->ui->comboBox_fieldDelimiter->setCurrentIndex(m_csvDialog->m_possibleDelimiter);
m_csvDialog->m_lastDelimiterIndex = newIndex;
m_csvDialog->m_pageSeparator->delimiterActivated(m_fieldDelimiterIndex);
m_csvDialog->m_pageSeparator->delimiterActivated();
break;
}
m_csvDialog->m_importNow = false;
......@@ -835,24 +869,29 @@ void InvestProcessing::readFile(const QString& fname)
//
// Start parsing the buffer
//
m_columnCountList.clear();
m_lineList = m_parse->parseFile(m_buf, 1, 0); // Changed to display whole file.
// Check all lines to find maximum column count.
// Also disable column combobox connects till later
for (int i = 0; i < m_lineList.count(); i++) {
QString data = m_lineList[i];
if (m_firstRead) {
m_columnList = m_parse->parseLine(data);
}
columnCount = m_columnList.count();
if (columnCount > m_maxColumnCount) {
m_maxColumnCount = columnCount;
}
else {
columnCount = m_maxColumnCount;
}
}
m_csvDialog->ui->tableWidget->setColumnCount(m_maxColumnCount);
disconnect(m_csvDialog->m_pageLinesDate->ui->spinBox_skip, 0, 0, 0); // Avoid disruption from start/endline changes.
disconnect(m_csvDialog->m_pageLinesDate->ui->spinBox_skipToLast, 0, 0, 0); // Avoid disruption from start/endline changes.
if (m_firstRead) {
// Check all lines to find maximum column count.
// Also disable column combobox connects till later
for (int i = 0; i < m_lineList.count(); i++) {
QString data = m_lineList[i];
m_columnList = m_parse->parseLine(data);
columnCount = m_columnList.count();
if (columnCount > m_maxColumnCount)
m_maxColumnCount = columnCount;
else
columnCount = m_maxColumnCount;
}
m_csvDialog->ui->tableWidget->setColumnCount(m_maxColumnCount);
m_csvDialog->m_pageInvestment->ui->comboBoxInv_amountCol->clear(); // clear all existing items before adding new ones
m_csvDialog->m_pageInvestment->ui->comboBoxInv_dateCol->clear();
m_csvDialog->m_pageInvestment->ui->comboBoxInv_memoCol->clear();
......@@ -889,7 +928,6 @@ void InvestProcessing::readFile(const QString& fname)
m_csvDialog->m_pageInvestment->ui->comboBoxInv_symbolCol->addItem(t);
m_csvDialog->m_pageInvestment->ui->comboBoxInv_detailCol->addItem(t);
}
m_columnTypeList<<QString(); // need one extra for payee column copy
m_firstPass = false;
m_screenUpdated = false;
......@@ -905,9 +943,10 @@ void InvestProcessing::readFile(const QString& fname)
connect(m_csvDialog->m_pageInvestment->ui->comboBoxInv_detailCol, SIGNAL(currentIndexChanged(int)), this, SLOT(detailColumnSelected(int)));
// Display the buffer
int delimiterCount[4] = {0};
int totalDelimiterCount[4] = {0};
m_csvDialog->m_possibleDelimiter = 0;
m_symblRow = 0;
m_symbolRow = 0;
// Check all lines to find maximum column count.
// Also check field delimiter
......@@ -916,8 +955,9 @@ void InvestProcessing::readFile(const QString& fname)
QString data = m_lineList[i];
for (int count = 0; count < 4; count++) { // Four possible delimiters
// Count each delimiter to find most likely one to use .
delimiterCount[count] = data.count(m_parse->m_fieldDelimiterCharList[count]);
if (delimiterCount[count] > delimiterCount[m_csvDialog->m_possibleDelimiter]) {
// Changed to sum total file, not just individual lines.
totalDelimiterCount[count] += data.count(m_parse->m_fieldDelimiterCharList[count]);
if (totalDelimiterCount[count] > totalDelimiterCount[m_csvDialog->m_possibleDelimiter]) {
m_csvDialog->m_possibleDelimiter = count;
}
}
......@@ -957,12 +997,12 @@ void InvestProcessing::readFile(const QString& fname)
}
if (m_importNow) {
m_csvDialog->clearCellsBackground();
}
}
// user now ready to continue && line is in wanted range
//
if ((m_importNow) && (line >= m_startLine - 1) && (line <= m_csvDialog->m_pageLinesDate->ui->spinBox_skipToLast->value() - 1)) {
reloadUISettings(); // Need to reload column settings
int ret = processInvestLine(m_inBuffer, line); // parse input line
int ret = processInvestLine(m_inBuffer); // parse input line
if (ret == KMessageBox::Ok) {
if (m_brokerage) {
investCsvImport(stBrokerage); // add non-investment transaction to Brokerage statement
......@@ -1023,12 +1063,39 @@ void InvestProcessing::displayLine(const QString& data)
m_fieldDelimiterIndex = m_csvDialog->m_pageSeparator->ui->comboBox_fieldDelimiter->currentIndex();
m_parse->setFieldDelimiterIndex(m_fieldDelimiterIndex);
m_fieldDelimiterCharacter = m_parse->fieldDelimiterCharacter(m_fieldDelimiterIndex);
//
// split data into fields
//
m_columnList = m_parse->parseLine(data);