Tell the fields of a target apart by line breaks only

A target typed in by hand was split into its fields on " / ", which
broke as soon as a field itself contained a slash: an installation
named "ASP/01" gave the box two lines with half a name in each, and
nothing to tell a separator apart from the name. Only a line break now
breaks the text into fields (RealTerminal::cableTarget()), and the
Target cell shows the fields the very same way, one line each
(modelRealTerminalData::targetText()), so the cell and the box under
the cable always read the same text.

The Target cell is edited line by line to go with that: it takes a
multi line editor where Return writes a new line, Ctrl+Return hands
the cell back to the table and Escape throws the text away
(TerminalStripModelDelegate), and the rows of the table are as tall as
the lines their cell shows, so the fields below the first one are never
cut off -- a cell without a target keeps the row it has always had.

The text copied to the clipboard keeps one line per row, the fields of
such a cell joined with " / " again, or a spreadsheet would take them
for several rows.

tst_terminalcableauto reads the three fields of a target of the
drawing back one line each, checks a "/" typed inside a field stays
part of it -- one line holding it, slashes and all -- checks the
editor of the cell is the multi line one, hands its text back
untouched, gives the cell back on Ctrl+Return while Return keeps
writing a new line, and checks the rows grow with the lines the cell
holds and shrink back afterwards. tst_cabletarget paints a strip whose
cable ends on a field containing a slash: the box is no deeper than
with one plain field.
This commit is contained in:
Kellermorph
2026-10-20 19:08:16 +02:00
parent 5baf5bec60
commit 36b1cb08ff
7 changed files with 342 additions and 46 deletions
@@ -253,6 +253,14 @@ void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_)
//the width of its own text, never a cut off Installation
ui->m_table_widget->horizontalHeader()->setSectionResizeMode(
TerminalStripModel::CableTarget, QHeaderView::ResizeToContents);
//That column holds one line by field: its rows must be tall
//enough for as many lines as a cell shows, while a cell of
//one line keeps the height the rows have always had
auto v_header_ = ui->m_table_widget->verticalHeader();
v_header_->setMinimumSectionSize(qMax(
v_header_->defaultSectionSize(),
ui->m_table_widget->rowHeight(0)));
v_header_->setSectionResizeMode(QHeaderView::ResizeToContents);
m_model->buildBridgePixmap(setUpBridgeCellWidth());
connect(ui->m_table_widget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TerminalStripEditor::selectionChanged);
}
@@ -880,8 +888,15 @@ void TerminalStripEditor::copySelectionToClipboard()
for (auto row = top ; row <= bottom ; ++row)
{
QStringList cells;
for (auto column = left ; column <= right ; ++column) {
cells << texts.value((qint64(row) << 32) | qint64(column));
for (auto column = left ; column <= right ; ++column)
{
//A cell may hold several lines (the Target cell holds one
//line by field): the text of the clipboard keeps one line by
//row, the fields of that cell are joined back the way a
//spreadsheet reads them
QString cell_{texts.value((qint64(row) << 32) | qint64(column))};
cell_.replace(QLatin1Char('\n'), QStringLiteral(" / "));
cells << cell_;
}
lines << cells.join(QLatin1Char('\t'));
}