Skip to content

Commit

Permalink
https://github.com/StephaneCouturier/Katalog/issues/496
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneCouturier committed Apr 25, 2024
1 parent 575779b commit 873604c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 16 deletions.
33 changes: 18 additions & 15 deletions src/collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,14 +874,16 @@ void Collection::loadTagFileToTable()
//Clear all entries of the current table
queryDelete.exec();

while (true)
{
QString line = textStream.readLine();
if (line.isNull())
break;
else
if (line.left(4)!="name"){//test the validity of the file
//Split the string with tabulation into a list
//Skip headers
QString line = textStream.readLine();
if(line.left(2)=="ID"){
while (true)
{
line = textStream.readLine();
if (line.isNull())
break;
else
{ //Split the string with tabulation into a list
QStringList fieldList = line.split('\t');
QSqlQuery insertQuery;
QString insertQuerySQL = QLatin1String(R"(
Expand All @@ -899,15 +901,16 @@ void Collection::loadTagFileToTable()
:date_time)
)");
insertQuery.prepare(insertQuerySQL);
insertQuery.bindValue(":ID", fieldList[0]);
insertQuery.bindValue(":ID", fieldList[0].toInt());
insertQuery.bindValue(":name", fieldList[1]);
insertQuery.bindValue(":path", fieldList[2]);
insertQuery.bindValue(":type", fieldList[3]);
insertQuery.bindValue(":date_time", fieldList[4]);
insertQuery.exec();
}
}
tagFile.close();
}
tagFile.close();
}
}
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -1147,11 +1150,11 @@ void Collection::saveTagTableToFile()
QTextStream out(&tagFile);

//Prepare header line
out << "ID" << "\t"
<< "type" << "\t"
<< "type" << "\t"
<< "value1" << "\t"
<< "value2" << "\t"
out << "ID" << "\t"
<< "name" << "\t"
<< "path" << "\t"
<< "type" << "\t"
<< "date_time" << "\t"
<< '\n';

//Get data
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class MainWindow : public QMainWindow
void importVirtualAssignmentsToDevices();
void convertFoldersIdxFiles();
void importExcludeIntoParameter();
void convertTags();

//TAB: Statistics
QStringList typeOfData;
Expand Down
51 changes: 51 additions & 0 deletions src/mainwindow_tab_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3195,6 +3195,9 @@ void MainWindow::migrateCollection()
//Convert exclude.csv file into parameter.csv
importExcludeIntoParameter();

//Convert Tags
convertTags();

//Close procedure
//Add the current version
QSqlQuery insertQuery;
Expand Down Expand Up @@ -4107,6 +4110,54 @@ void MainWindow::importExcludeIntoParameter()
collection->saveParameterTableToFile();
}

void MainWindow::convertTags()
{//Convert Tags
QFile tagFile(collection->tagFilePath);

//Open file or return information
if(!tagFile.open(QIODevice::ReadOnly)) {
return;
}

QTextStream textStream(&tagFile);
while (true)
{
QString line = textStream.readLine();
if (line.isNull())
break;
else
{
//Split the string with tabulation into a list
QStringList fieldList = line.split('\t');
//qDebug()<<"fieldList"<<fieldList;
QSqlQuery insertQuery;
QString insertQuerySQL = QLatin1String(R"(
INSERT INTO tag(
ID,
name,
path,
type,
date_time)
VALUES(
NULL,
:name,
:path,
:type,
:date_time)
)");
insertQuery.prepare(insertQuerySQL);
insertQuery.bindValue(":name", fieldList[1]);
insertQuery.bindValue(":path", fieldList[0]);
insertQuery.bindValue(":type", "");
insertQuery.bindValue(":date_time", "");
insertQuery.exec();
}
}
tagFile.close();

collection->saveTagTableToFile();
}

//--------------------------------------------------------------------------
//--- DEV: metadata --------------------------------------------------------
//--------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/mainwindow_tab_tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
{
selectedTagListName = ui->Tags_listView_ExistingTags->model()->index(index.row(), 0, QModelIndex()).data().toString();
ui->Tags_lineEdit_TagName->setText(selectedTagListName);
//loadTagsTableToModel();
loadTagsTableToTagsAndFolderListModel();
}
//----------------------------------------------------------------------
Expand Down

0 comments on commit 873604c

Please sign in to comment.