void FoBlockView::appendTextContent(TextContentDoc *pTextDoc) { int offsetOfUnProcessedText=0; while (offsetOfUnProcessedText<pTextDoc->size()) { //check free space in row if ( lastRow()->remainWidthOfRow() <= 0 ) //if we haven't free space in last row, create new row createAndAppendNewRow(); //try to add text from textcontentdoc and use start from (pTextDoc->size()-notAddedRemainOfText) offsetOfUnProcessedText=lastRow()->addTextToRow(pTextDoc,offsetOfUnProcessedText); } }
Q_SLOT void showHistory() { if (! m_view) initView(); if (m_view->isVisible()) return; m_model->setStringList(m_history); m_view->move(mapToGlobal(QPoint(0, height()))); QModelIndex lastRow(m_model->index(m_history.size()-1)); int bottomY = m_view->visualRect(lastRow).bottom(); int widthHint = m_view->sizeHint().width(); if (bottomY < m_view->sizeHint().height()) m_view->resize(widthHint, bottomY + 1); m_view->show(); }
void FoBlockView::appendFoExternalGraphic(FoExternalGraphicDoc *pGraphicDoc) { //create view for text and put it to the last row FoExternalGraphicView *pGraphicView = new FoExternalGraphicView(this,pGraphicDoc,m_pMainView); if (lastRow()->addGraphicToRow(pGraphicView)==false) { RowInBlockView *newRow=createAndAppendNewRow(); if (newRow->addGraphicToRow(pGraphicView)) { qFatal("Ugh, inserted picture is larger than width of FoBlockView"); } } }
size_t padDataset(SGPP::base::DataMatrix& dataset) { size_t vecWidth = (*parameters)["LOCAL_SIZE"].getUInt() * (*parameters)["KERNEL_DATA_BLOCK_SIZE"].getUInt(); // Assure that data has a even number of instances -> padding might be needed size_t remainder = dataset.getNrows() % vecWidth; size_t loopCount = vecWidth - remainder; if (loopCount != vecWidth) { SGPP::base::DataVector lastRow(dataset.getNcols()); size_t oldSize = dataset.getNrows(); dataset.getRow(dataset.getNrows() - 1, lastRow); dataset.resize(dataset.getNrows() + loopCount); for (size_t i = 0; i < loopCount; i++) { dataset.setRow(oldSize + i, lastRow); } } return dataset.getNrows(); }
//@time complexity: O(row^2) //@space complexity: O(row) //@2A vector<int> getRow(int rowIndex) { vector<int> kRow(rowIndex + 1); vector<int> lastRow(rowIndex); for (int i = 0; i <= rowIndex; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || j == i) { kRow[j] = 1; } else { kRow[j] = lastRow[j - 1] + lastRow[j]; } } if (i != rowIndex) { for (int j = 0; j <= i; j++) { lastRow[j] = kRow[j]; } } } return kRow; }
void Main::addMesh() { int x0 = 0; int y0 = 0; if ( !tb ) tb = new QBrush( Qt::red ); if ( !tp ) tp = new QPen( Qt::black ); int nodecount = 0; int w = int(canvas.width()); int h = int(canvas.height()); const int dist = 30; int rows = h / dist; int cols = w / dist; #ifndef QT_NO_PROGRESSDIALOG Q3ProgressDialog progress( "Creating mesh...", "Abort", rows, this, "progress", TRUE ); #endif canvas.update(); Q3MemArray<NodeItem*> lastRow(cols); for ( int j = 0; j < rows; j++ ) { int n = j%2 ? cols-1 : cols; NodeItem *prev = 0; for ( int i = 0; i < n; i++ ) { NodeItem *el = new NodeItem; canvas.addItem(el); nodecount++; int r = qrand(); int xrand = r %20; int yrand = (r/20) %20; el->setPos( xrand + x0 + i*dist + (j%2 ? dist/2 : 0 ), yrand + y0 + j*dist ); if ( j > 0 ) { if ( i < cols-1 ) canvas.addItem(new EdgeItem( lastRow[i], el)); if ( j%2 ) canvas.addItem(new EdgeItem( lastRow[i+1], el)); else if ( i > 0 ) canvas.addItem(new EdgeItem( lastRow[i-1], el)); } if ( prev ) { canvas.addItem(new EdgeItem( prev, el)); } if ( i > 0 ) lastRow[i-1] = prev; prev = el; } lastRow[n-1]=prev; #ifndef QT_NO_PROGRESSDIALOG progress.setProgress( j ); if ( progress.wasCancelled() ) break; #endif } #ifndef QT_NO_PROGRESSDIALOG progress.setProgress( rows ); #endif // qDebug( "%d nodes, %d edges", nodecount, EdgeItem::count() ); }
matrix<T> matrix<T>::copyCols(int j0, int j1) const { return copy(0, lastRow(), j0, j1); }
/** * Parser, main state machine decoding engine * * @param c input character * @return true = success, false = decoding failure/invalid file contents */ bool ParseHex(char c) { static enum hexstate state = SOL; static uint8_t bc; static uint8_t data_count; static uint32_t address; static uint32_t ext_address = 0; static uint8_t checksum; static uint8_t record_type; static uint8_t data_byte, data_index, data[16]; switch( state){ case SOL: if (c == '\r') break; if (c == '\n') break; if (c != ':') return false; state = BYTE_COUNT; bc = 0; address = 0; checksum = 0; break; case BYTE_COUNT: if ( isDigit( &c) == false) { state = SOL; return false; } bc++; if (bc == 1) data_count = c; if (bc == 2 ) { data_count = (data_count << 4) + c; checksum += data_count; bc = 0; if (data_count > 16) { state = SOL; return false; } state = ADDRESS; } break; case ADDRESS: if ( isDigit( &c) == false) { state = SOL; return false;} bc++; if (bc == 1) address = c; else { address = (address << 4) + (uint32_t)c; if (bc == 4) { checksum += (address>>8) + address; bc = 0; state = RECORD_TYPE; } } break; case RECORD_TYPE: if ( isDigit( &c) == false) { state = SOL; return false;} bc++; if (bc == 1) if (c != 0) { state = SOL; return false; } if (bc == 2) { record_type = c; checksum += c; bc = 0; state = DATA; // default data_index = 0; memset(data, 0xff, sizeof(data)); if (record_type == 0) break; // data record if (record_type == 1) { state = CHKSUM; break; } // EOF record if (record_type == 4) break; // extended address record state = SOL; return false; } break; case DATA: if ( isDigit( &c) == false) { state = SOL; return false;} bc++; if (bc == 1) data[data_index] = (c<<4); if (bc == 2) { bc = 0; data[data_index] += c; checksum += data[data_index]; data_index++; if (data_index == data_count) { state = CHKSUM; } } break; case CHKSUM: if ( isDigit( &c) == false) { state = SOL; return false;} bc++; if (bc == 1) checksum += (c<<4); if (bc == 2) { bc = 0; checksum += c; if (checksum != 0) { state = SOL; return false; } // chksum is good state = SOL; if (record_type == 0) APP_write( ext_address + address, data, data_count); else if (record_type == 4) ext_address = ((uint32_t)(data[0]) << 24) + ((uint32_t)(data[1]) << 16); else if (record_type == 1) { lastRow(); ext_address = 0; } else return false; } break; default: break; }