Commit 63f5d25770c1e03dbd748fcbf09c51ce22bccdfd

Authored by Charles Otto
1 parent f58c9b50

In dbGallery, store the value of the second column using its field name

This, rather than always storing it as label. The name of the column can be
set in the SQL query, so there is no particular need to change it in dbGallery
Showing 1 changed file with 10 additions and 2 deletions
openbr/plugins/gallery.cpp
... ... @@ -701,11 +701,16 @@ class dbGallery : public Gallery
701 701 query = query.mid(1, query.size()-2);
702 702 if (!q.exec(query))
703 703 qFatal("%s.", qPrintable(q.lastError().text()));
  704 +
704 705 if ((q.record().count() == 0) || (q.record().count() > 3))
705 706 qFatal("Query record expected one to three fields, got %d.", q.record().count());
706 707 const bool hasMetadata = (q.record().count() >= 2);
707 708 const bool hasFilter = (q.record().count() >= 3);
708 709  
  710 + QString labelName = "Label";
  711 + if (q.record().count() >= 2)
  712 + labelName = q.record().fieldName(1);
  713 +
709 714 // subset = seed:subjectMaxSize:numSubjects:subjectMinSize or
710 715 // subset = seed:{Metadata,...,Metadata}:numSubjects
711 716 int seed = 0, subjectMaxSize = std::numeric_limits<int>::max(), numSubjects = std::numeric_limits<int>::max(), subjectMinSize = 0;
... ... @@ -731,6 +736,7 @@ class dbGallery : public Gallery
731 736 QHash<QString, QList<Entry> > entries; // QHash<Label, QList<Entry> >
732 737 while (q.next()) {
733 738 if (hasFilter && (seed >= 0) && (qHash(q.value(2).toString()) % 2 != (uint)seed % 2)) continue; // Ensures training and testing filters don't overlap
  739 +
734 740 if (metadataFields.isEmpty())
735 741 entries[hasMetadata ? q.value(1).toString() : ""].append(QPair<QString,QString>(q.value(0).toString(), hasFilter ? q.value(2).toString() : ""));
736 742 else
... ... @@ -765,8 +771,10 @@ class dbGallery : public Gallery
765 771  
766 772 if (entryList.size() > subjectMaxSize)
767 773 std::random_shuffle(entryList.begin(), entryList.end());
768   - foreach (const Entry &entry, entryList.mid(0, subjectMaxSize))
769   - templates.append(File(entry.first, label));
  774 + foreach (const Entry &entry, entryList.mid(0, subjectMaxSize)) {
  775 + templates.append(File(entry.first));
  776 + templates.last().file.set(labelName, label);
  777 + }
770 778 numSubjects--;
771 779 }
772 780 }
... ...