bool Matrix::isRowSelected(int row, bool full) { QList<QTableWidgetSelectionRange> sel = d_table->selectedRanges(); QListIterator<QTableWidgetSelectionRange> it(sel); QTableWidgetSelectionRange cur; if ( !full ) { if( it.hasNext() ) { cur = it.next(); if ( (row >= cur.topRow()) && (row <= cur.bottomRow() ) ) return true; } } else { if( it.hasNext() ) { cur = it.next(); if ( row >= cur.topRow() && row <= cur.bottomRow() && cur.leftColumn() == 0 && cur.rightColumn() == numCols() - 1 ) return true; } } return false; }
void QueryPathsDialog::tableSelectionChanged() { QList<QTableWidgetSelectionRange> selection = ui->tableWidget->selectedRanges(); int totalSelectedRows = 0; for (int i = 0; i < selection.size(); ++i) totalSelectedRows += selection[i].rowCount(); g_memory->queryPaths.clear(); QList<int> selectedRows; for (int i = 0; i < selection.size(); ++i) { QTableWidgetSelectionRange * selectionRange = &(selection[i]); int top = selectionRange->topRow(); int bottom = selectionRange->bottomRow(); for (int row = top; row <= bottom; ++row) { if (!selectedRows.contains(row)) selectedRows.push_back(row); } } for (int i = 0; i < selectedRows.size(); ++i) { int row = selectedRows[i]; QString pathString = ui->tableWidget->item(row, 0)->text(); QString pathStringFailure; g_memory->queryPaths.push_back(Path::makeFromString(pathString, false, &pathStringFailure)); } emit selectionChanged(); }
QList<double> Calculator::extractData(const QStringList &stringArgs, const QList<double> &doubleArgs) { QList<double> returnList; for (int i = 0; i < stringArgs.size(); i++) { int iterator = 0; if (isRange(stringArgs[i] + QChar(QChar::Null), iterator)) { if (iterator == stringArgs[i].size()) //if there is only a range in the argument { QTableWidgetSelectionRange range; Table::decodeRange(stringArgs[i], range); for (int row=range.topRow(); row<=range.bottomRow(); row++) { for (int column=range.leftColumn(); column<=range.rightColumn(); column++) { returnList.append(table -> getItemText(row, column).toDouble()); } } continue; } } returnList.append(doubleArgs[i]); } return returnList; }
void Matrix::copySelection() { QString the_text; QList<QTableWidgetSelectionRange> sel = d_table->selectedRanges(); if (sel.isEmpty()) the_text = text(d_table->currentRow(),d_table->currentColumn()); else { QListIterator<QTableWidgetSelectionRange> it(sel); QTableWidgetSelectionRange cur; if(!it.hasNext())return; cur = it.next(); int top = cur.topRow(); int bottom = cur.bottomRow(); int left = cur.leftColumn(); int right = cur.rightColumn(); for(int i=top; i<=bottom; i++) { for(int j=left; j<right; j++) the_text += text(i,j)+"\t"; the_text += text(i,right)+"\n"; } } // Copy text into the clipboard QApplication::clipboard()->setText(the_text); }
void ViewTableListWidget::showRightMenu( const QPoint & pos) { //显示右键菜单 qDebug()<<tr("视图菜单")<<pos.x()<<" "<<pos.y(); QTableWidgetItem *curItem = this->itemAt(pos); if(curItem != NULL) { curindex = currentRow(); viewfilenames.clear(); QList<QTableWidgetSelectionRange> rangelist = this->selectedRanges(); QList<QTableWidgetSelectionRange>::iterator iter = rangelist.begin(); while(iter != rangelist.end()) { QTableWidgetSelectionRange range = *iter; for(int i =range.topRow(); i<=range.bottomRow(); i++ ) viewfilenames<<item(i,0)->text(); ++iter; } } qDebug()<<viewfilenames; this->createRightMenu((int *)curItem); }
void TableWidget::copy() { // Get a list of all selected ranges: QList<QTableWidgetSelectionRange> selectedRanges = this->selectedRanges(); if(selectedRanges.isEmpty()) return; // Establish the outer boundary of all selections: int leftColumn = this->columnCount() - 1; int rightColumn = 0; int topRow = this->rowCount() - 1; int bottomRow = 0; for(int i = 0; i < selectedRanges.size(); i++) { QTableWidgetSelectionRange range = selectedRanges.at(i); if(range.leftColumn() < leftColumn) leftColumn = range.leftColumn(); if(range.rightColumn() > rightColumn) rightColumn = range.rightColumn(); if(range.topRow() < topRow) topRow = range.topRow(); if(range.bottomRow() > bottomRow) bottomRow = range.bottomRow(); } if(bottomRow < topRow or rightColumn < leftColumn) return; // Loop through selection range and extract data: QString outputText; for(int i = topRow; i <= bottomRow; i++) { for(int j = leftColumn; j <= rightColumn; j++) { if(this->item(i, j)->isSelected()) { outputText += this->item(i, j)->text(); } if (j < rightColumn) outputText += "\t"; else outputText += "\n"; } } // Copy data to clipboard: QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(outputText); return; }
//----------------------------------------------------------------------------- void DatPanel::copy() { QTableWidgetSelectionRange ts = tab->selectedRanges().first(); register long i,j; QString res, s; for(j=ts.topRow();j<=ts.bottomRow();j++) { for(i=ts.leftColumn();i<=ts.rightColumn();i++) { res = res + tab->item(j,i)->text(); if(i<ts.rightColumn()) res = res + "\t"; } res = res + "\n"; } QApplication::clipboard()->setText(res, QClipboard::Clipboard); }
bool Matrix::rowsSelected() { QList<QTableWidgetSelectionRange> sel = d_table->selectedRanges(); QListIterator<QTableWidgetSelectionRange> it(sel); QTableWidgetSelectionRange cur; if( it.hasNext() ) { cur = it.next(); for(int i=cur.topRow(); i<=cur.bottomRow(); i++) { if (!isRowSelected (i, true)) return false; } } return true; }
void PMeshViewer::deleteMesh() { QList<QTableWidgetSelectionRange> list = meshTable->selectedRanges(); if (list.isEmpty()) return; QTableWidgetSelectionRange range = list[0]; // Only 1 range. for (int i = range.bottomRow(); i >= range.topRow(); --i) { meshTable->removeRow(i); renderer->RemoveActor(meshList[i].actor); meshList[i].normals->Delete(); meshList[i].mapper->Delete(); meshList[i].actor->Delete(); meshList.removeAt(i); } renderWindow->Render(); }
void Matrix::clearSelection() { allow_modification_signals = false; QList<QTableWidgetSelectionRange> sel = d_table->selectedRanges(); QListIterator<QTableWidgetSelectionRange> it(sel); QTableWidgetSelectionRange cur; if( it.hasNext() ) { cur = it.next(); for(int i = cur.topRow(); i <= cur.bottomRow(); i++) for(int j = cur.leftColumn(); j<= cur.rightColumn();j++) setText(i, j, ""); } allow_modification_signals = true; emit modifiedWindow(this); }
void TableWidget::checkRows(){ QAction *action = qobject_cast<QAction*>(sender()); bool checked = action->data().toBool(); QList<QTableWidgetSelectionRange> ranges = selectedRanges(); if(ranges.size()==0){ return; } QTableWidgetSelectionRange range = ranges[0]; for(int i=range.topRow(); i<=range.bottomRow(); ++i) { if(!item(i,0)){ continue; } if(checked){ item(i,0)->setCheckState(Qt::Checked); }else{ item(i,0)->setCheckState(Qt::Unchecked); } } }
void PhotoTexturingWidget::calculateTextures(){ bool calcZBuffer =ui.checkBoxzBuffer->isChecked(); bool selectedCamOnly = ui.selectedCameraOnlyCheckBox->isChecked(); if (!selectedCamOnly){ photoTexturer->calculateMeshTextureForAllCameras(mesh,calcZBuffer); }else{ QList<QTableWidgetSelectionRange> ranges = ui.cameraTableWidget->selectedRanges(); for (int i=0;i<ranges.size();i++){ QTableWidgetSelectionRange range = ranges.at(i); for(int j=range.topRow();j<=range.bottomRow();j++){ Camera *cam = photoTexturer->cameras.at(j); photoTexturer->calculateMeshTextureForCamera(mesh,cam,calcZBuffer); } } } glarea->update(); update(); updateGLAreaTextures(); updateMainWindowMenus(); }
bool TableEventHandler::eventFilter(QObject *o, QEvent *e) { if( !o ) qWarning("TableEventHandler::eventFilter called with 0 object?"); if( QString(o->metaObject()->className()) != tr("QTableWidget") ) { #ifdef EI_DEBUG qDebug("Only QTableWidget objects accepted! Returning!"); #endif return false; } QTableWidget *to = (QTableWidget *)o; if( e->type() == QEvent::KeyPress ) { QKeyEvent *ke = (QKeyEvent*)e; if(ke->matches(QKeySequence::Copy) ){ QString cellText; itemCopy.clear(); copyRange.clear(); QList<QTableWidgetSelectionRange> ts = to->selectedRanges(); if(!ts.isEmpty()) { for ( int irow = ts.first().topRow(); irow <= ts.first().bottomRow(); irow++){ for ( int icol = ts.first().leftColumn(); icol <= ts.first().rightColumn(); icol++){ QTableWidgetItem *w = to->item(irow,icol); if(w) cellText = w->text(); if ( !cellText.isEmpty() ){ itemCopy << cellText; } else itemCopy << " "; } } copyRange = ts; //cout << itemCopy.join(", ").toLatin1().data() << endl; } else { QTableWidgetItem *w = to->item(to->currentRow(), to->currentColumn()); if (w) cellText = w->text(); if ( !cellText.isEmpty() ) itemCopy << cellText; else itemCopy << ""; } return true; } else if(ke->matches(QKeySequence::Paste) && !itemCopy.isEmpty() && !copyRange.isEmpty()){ QList<QTableWidgetSelectionRange> cs = to->selectedRanges(); int top = cs.first().topRow(), left = cs.first().leftColumn(), icount = 0; QTableWidgetSelectionRange ts = QTableWidgetSelectionRange( top , left, top + copyRange.first().rowCount()-1, left + copyRange.first().columnCount()-1); for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){ for ( int icol = ts.leftColumn(); icol <= ts.rightColumn(); icol++){ if ( ++icount <= itemCopy.size() ) to->setItem(irow, icol, new QTableWidgetItem(itemCopy[icount-1])); } } return true; } else if(ke->matches(QKeySequence::Cut) ){ QString cellText; itemCopy.clear(); copyRange.clear(); QList<QTableWidgetSelectionRange> ts = to->selectedRanges(); if(!ts.isEmpty()) { for (int irow = ts.first().topRow(); irow <= ts.first().bottomRow(); irow++) { for(int icol = ts.first().leftColumn(); icol <= ts.first().rightColumn(); icol++) { QTableWidgetItem *w = to->item(irow,icol); if(w) cellText = w->text(); if ( !cellText.isEmpty() ){ itemCopy << cellText; } else itemCopy << ""; to->setItem(irow,icol,0); } } copyRange = ts; //cout << itemCopy.join(", ").toLatin1().data() << endl; } return true; } else if(ke->matches(QKeySequence::Delete) ){ QList<QTableWidgetSelectionRange> ts = to->selectedRanges(); if(!ts.isEmpty()) { for (int irow = ts.first().topRow(); irow <= ts.first().bottomRow(); irow++) { for(int icol = ts.first().leftColumn(); icol <= ts.first().rightColumn(); icol++) { to->setItem(irow,icol,0); } } } return true; } else to->eventFilter(o, e); } return false; }
void Matrix::pasteSelection() { QString the_text = QApplication::clipboard()->text(); if (the_text.isEmpty()) return; allow_modification_signals = false; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QTextStream ts( &the_text, QIODevice::ReadOnly ); QString s = ts.readLine(); QStringList cellTexts = s.split("\t"); int cols = cellTexts.count(); int rows = 1; while(!ts.atEnd()) { rows++; s = ts.readLine(); } ts.reset(); int i, j, top, bottom, right, left, firstCol; QList<QTableWidgetSelectionRange> sel = d_table->selectedRanges(); QListIterator<QTableWidgetSelectionRange> it(sel); QTableWidgetSelectionRange cur; if (!sel.isEmpty()) { cur = it.next(); top = cur.topRow(); bottom = cur.bottomRow(); left = cur.leftColumn(); right = cur.rightColumn(); } else { top = 0; bottom = numRows() - 1; left = 0; right = numCols() - 1; firstCol = firstSelectedColumn(); if (firstCol >= 0) { // columns are selected left = firstCol; int selectedColsNumber = 0; for(i=0; i<numCols(); i++) { if (isColumnSelected(i, true)) selectedColsNumber++; } right = firstCol + selectedColsNumber - 1; } } QTextStream ts2( &the_text, QIODevice::ReadOnly ); int r = bottom-top+1; int c = right-left+1; QApplication::restoreOverrideCursor(); if (rows>r || cols>c) { // TODO: I find the insert cells option awkward // I would prefer the behavior of OpenOffice Calc // here - thzs switch( QMessageBox::information(0,"QtiPlot", tr("The text in the clipboard is larger than your current selection!\ \nDo you want to insert cells?"), tr("Yes"), tr("No"), tr("Cancel"), 0, 0) ) { case 0: if(cols > c ) for(int i=0; i<(cols-c); i++) d_table->insertColumn(left); if(rows > r) { if (firstCol >= 0) for(int i=0; i<(rows-r); i++) d_table->insertRow(top); else for(int i=0; i<(rows-r+1); i++) d_table->insertRow(top); } break; case 1: rows = r; cols = c; break; case 2: allow_modification_signals = true; return; break; } } QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); bool numeric; double value; QLocale system_locale = QLocale::system(); for(i=top; i<top+rows; i++) { s = ts2.readLine(); cellTexts=s.split("\t"); for(j=left; j<left+cols; j++) { value = system_locale.toDouble(cellTexts[j-left], &numeric); if (numeric) setText(i, j, QLocale().toString(value, txt_format.toAscii(), num_precision)); else setText(i, j, cellTexts[j-left]); } } allow_modification_signals = true; emit modifiedWindow(this); QApplication::restoreOverrideCursor(); }