bool SpreadSheet::runInputDialog(const QString &title, const QString &c1Text, const QString &c2Text, const QString &opText, const QString &outText, QString *cell1, QString *cell2, QString *outCell) { QStringList rows, cols; for (int c = 0; c < table->columnCount(); ++c) cols << QChar('A' + c); for (int r = 0; r < table->rowCount(); ++r) rows << QString::number(1 + r); QDialog addDialog(this); addDialog.setWindowTitle(title); QGroupBox group(title, &addDialog); group.setMinimumSize(250, 100); QLabel cell1Label(c1Text, &group); QComboBox cell1RowInput(&group); int c1Row, c1Col; decode_pos(*cell1, &c1Row, &c1Col); cell1RowInput.addItems(rows); cell1RowInput.setCurrentIndex(c1Row); QComboBox cell1ColInput(&group); cell1ColInput.addItems(cols); cell1ColInput.setCurrentIndex(c1Col); QLabel operatorLabel(opText, &group); operatorLabel.setAlignment(Qt::AlignHCenter); QLabel cell2Label(c2Text, &group); QComboBox cell2RowInput(&group); int c2Row, c2Col; decode_pos(*cell2, &c2Row, &c2Col); cell2RowInput.addItems(rows); cell2RowInput.setCurrentIndex(c2Row); QComboBox cell2ColInput(&group); cell2ColInput.addItems(cols); cell2ColInput.setCurrentIndex(c2Col); QLabel equalsLabel("=", &group); equalsLabel.setAlignment(Qt::AlignHCenter); QLabel outLabel(outText, &group); QComboBox outRowInput(&group); int outRow, outCol; decode_pos(*outCell, &outRow, &outCol); outRowInput.addItems(rows); outRowInput.setCurrentIndex(outRow); QComboBox outColInput(&group); outColInput.addItems(cols); outColInput.setCurrentIndex(outCol); QPushButton cancelButton(tr("Cancel"), &addDialog); connect(&cancelButton, SIGNAL(clicked()), &addDialog, SLOT(reject())); QPushButton okButton(tr("OK"), &addDialog); okButton.setDefault(true); connect(&okButton, SIGNAL(clicked()), &addDialog, SLOT(accept())); QHBoxLayout *buttonsLayout = new QHBoxLayout; buttonsLayout->addStretch(1); buttonsLayout->addWidget(&okButton); buttonsLayout->addSpacing(10); buttonsLayout->addWidget(&cancelButton); QVBoxLayout *dialogLayout = new QVBoxLayout(&addDialog); dialogLayout->addWidget(&group); dialogLayout->addStretch(1); dialogLayout->addItem(buttonsLayout); QHBoxLayout *cell1Layout = new QHBoxLayout; cell1Layout->addWidget(&cell1Label); cell1Layout->addSpacing(10); cell1Layout->addWidget(&cell1ColInput); cell1Layout->addSpacing(10); cell1Layout->addWidget(&cell1RowInput); QHBoxLayout *cell2Layout = new QHBoxLayout; cell2Layout->addWidget(&cell2Label); cell2Layout->addSpacing(10); cell2Layout->addWidget(&cell2ColInput); cell2Layout->addSpacing(10); cell2Layout->addWidget(&cell2RowInput); QHBoxLayout *outLayout = new QHBoxLayout; outLayout->addWidget(&outLabel); outLayout->addSpacing(10); outLayout->addWidget(&outColInput); outLayout->addSpacing(10); outLayout->addWidget(&outRowInput); QVBoxLayout *vLayout = new QVBoxLayout(&group); vLayout->addItem(cell1Layout); vLayout->addWidget(&operatorLabel); vLayout->addItem(cell2Layout); vLayout->addWidget(&equalsLabel); vLayout->addStretch(1); vLayout->addItem(outLayout); if (addDialog.exec()) { *cell1 = cell1ColInput.currentText() + cell1RowInput.currentText(); *cell2 = cell2ColInput.currentText() + cell2RowInput.currentText(); *outCell = outColInput.currentText() + outRowInput.currentText(); return true; } return false; }
void work(void) { auto inputPort = this->input(0); auto outputPort = this->output(0); size_t consumed = 0; //get input buffer auto inBuff = inputPort->buffer(); if (inBuff.length == 0) return; //label propagation offset incremented as preambles are posted size_t labelIndexOffset = 0; //track the index of the last found frame start label int lastFoundIndex = -1; for (auto &label : inputPort->labels()) { // Skip any label that doesn't yet appear in the data buffer if (label.index >= inputPort->elements()) continue; Pothos::Label outLabel(label); //modified and posted below //increment the offset as soon as we are past the last found index if (lastFoundIndex != -1 and size_t(lastFoundIndex) != label.index) { lastFoundIndex = -1; labelIndexOffset += _preambleBuff.elements(); } if (label.id == _frameStartId) { //post everything before this label Pothos::BufferChunk headBuff = inBuff; size_t headElems = label.index - consumed; headBuff.length = headElems*sizeof(Type); if (headBuff.length != 0) outputPort->postBuffer(headBuff); //fill the preamble buffer Pothos::BufferChunk newPreambleBuff(typeid(Type), _preambleBuff.elements()); std::memcpy(newPreambleBuff.as<void *>(), _preambleBuff.as<const void *>(), _preambleBuff.length); auto p = newPreambleBuff.as<Type *>() + _syncWordWidth; //encode the header field into bits char headerBits[NUM_HEADER_BITS]; FrameHeaderFields headerFields; headerFields.id = _headerId; headerFields.length = 0; if (label.data.canConvert(typeid(size_t))) { headerFields.length = label.data.template convert<size_t>()*label.width; } headerFields.chksum = headerFields.doChecksum(); encodeHeaderWord(headerBits, headerFields); //encode header fields as BPSK into the preamble buffer const auto sym = _preamble.back(); for (size_t i = 0; i < NUM_HEADER_BITS; i++) { *p++ = (headerBits[i] != 0)?+sym:-sym; } //post the preamble buffer outputPort->postBuffer(newPreambleBuff); //remove header from the remaining buffer inBuff.length -= headBuff.length; inBuff.address += headBuff.length; consumed += headBuff.elements(); //mark for increment on next label index lastFoundIndex = label.index; } else if (label.id == _frameEndId) { //post everything before this label Pothos::BufferChunk headBuff = inBuff; size_t headElems = label.index + label.width - consumed; //place at end of width headBuff.length = headElems*sizeof(Type); headBuff.length = std::min(headBuff.length, inBuff.length); //bounds check if (headBuff.length != 0) outputPort->postBuffer(headBuff); //post the buffer outputPort->postBuffer(_paddingBuff); //remove header from the remaining buffer inBuff.length -= headBuff.length; inBuff.address += headBuff.length; consumed += headBuff.elements(); //increment index for insertion of padding labelIndexOffset += _paddingBuff.elements(); } //propagate labels here with the offset outLabel.index += labelIndexOffset; outputPort->postLabel(outLabel); } //post the remaining bytes if (inBuff.length != 0) outputPort->postBuffer(inBuff); //consume the entire buffer inputPort->consume(inputPort->elements()); }