Fix material list reading, selection and article fields

Follow-up to #1088, covering its review comments and one behaviour
change found while testing the feature:

- MaterialList::load() names the columns from the machine key line when
  the file has one, instead of from the translated label line above it.
  A catalogue written in another language fills the element fields
  again, and saving no longer replaces the key line with labels.
- The entry picked after "New entry" is found by comparing the columns
  one by one instead of comparing the two maps as a whole: the entry
  form leaves the empty columns out, so the record never matched the
  line that had just been written and the search was cleared for
  nothing. The search is now only given up when it really hides the new
  line.
- Applying a catalogue entry pushes an undo command only when the live
  edit is on. In the properties window, where there is none, the fields
  wait for "Apply", so "Cancel" gives the element its own values back
  instead of leaving the picked part in place.
- Cells a file holds past the header are kept in MaterialRecord::extra
  and written back, so appending an article never shortens a line.
- An empty cell of a column describing the article itself (MaterialList::
  isArticleBound: description, designation, manufacturer, order number,
  supplier, model, ratings, dimensions, auxiliary block) clears the
  field, so an element never keeps the manufacturer of the part picked
  before. An empty cell of any other column (function, comment, notes,
  plant, location, quantity, unity), and any column the file does not
  hold at all, leaves the field alone.
- Comments left where the review asked for them: the corner button
  lookup, the ';' separator fallback, the search filter cost.
This commit is contained in:
Kellermorph
2026-09-28 22:38:41 +02:00
parent 9cbf26dcc9
commit 8b54ea400b
4 changed files with 148 additions and 9 deletions
+29 -5
View File
@@ -438,9 +438,14 @@ void ElementInfoWidget::materialFromFile(int block)
Write a catalogue entry into the fields of one block.
Only the fields of that block are touched: applied to an auxiliary
article, the entry never reaches the main article. And a cell which is
empty in the file leaves the current value alone, so picking an entry
describing only the order reference never wipes a comment.
article, the entry never reaches the main article.
An empty cell of a column describing the article (MaterialList::
isArticleBound) clears the field: keeping the manufacturer of the
article picked before would describe a part which does not exist.
An empty cell of any other column, and any column the file does not
hold at all, leaves the field alone, so picking an entry describing
only the order reference never wipes a comment.
@param record the entry taken from the material file
@param block 0 for the main article, 1 to 4 for an auxiliary article
*/
@@ -459,8 +464,19 @@ void ElementInfoWidget::applyMaterialRecord(const MaterialRecord &record, int bl
for (const QString &column : MaterialList::columnsForBlock(block))
{
//A column the file does not hold says nothing about the
//article: the field of the element stays as it is.
if (!record.values.contains(column)) {
continue;
}
const QString value = record.value(column);
if (value.isEmpty()) {
//An empty cell only matters for the columns describing the
//article itself, where the previous value belongs to another
//part. For the others (function, comment, quantity...) an
//empty cell means the file has nothing to say about them.
if (value.isEmpty() && !MaterialList::isArticleBound(column)) {
continue;
}
@@ -478,7 +494,15 @@ void ElementInfoWidget::applyMaterialRecord(const MaterialRecord &record, int bl
enableLiveEdit();
}
apply();
//Outside of the live edit the fields only carry the article: it
//is the properties window which applies them when the user presses
//"Apply" (ElementPropertiesWidget::apply() takes the undo command
//from these very fields). Applying right away would push the change
//on the undo stack before he has decided anything, and "Cancel"
//would give the fields back but never the element.
if (live_edit) {
apply();
}
}
/**