QTableWidgetSelectionRange Spreadsheet::selectedRange() const { QList<QTableWidgetSelectionRange> ranges = selectedRanges(); if(ranges.empty()) return QTableWidgetSelectionRange(); return ranges.first(); }
void TableWidget::copyCells(){ QList<QTableWidgetSelectionRange> ranges = selectedRanges(); if(ranges.size()==0){ return; } QTableWidgetSelectionRange range = ranges[0]; QString str; for(int i=0; i<range.rowCount(); ++i) { if(i>0){ str += "\n"; } for(int j=0; j< range.columnCount(); ++j) { if(j>0){ str += "\t"; } if(!item(i,j)){ str += ""; }else{ str += item(range.topRow() +i, range.leftColumn()+j)->text(); qDebug()<<"adding to clipbard: "<<item(range.topRow() +i, range.leftColumn()+j)->text(); } } } QApplication::clipboard()->setText(str); }
void tableTemplateWidget::insColumn(void) { int lc, cc; int i, j; selectionRange = selectedRanges(); for (i = 0; i < selectionRange.count(); i++) { lc = selectionRange[i].leftColumn(); cc = selectionRange[i].columnCount(); for (j = 0; j < cc; j++) insertColumn(lc); } for (i = 0; i < numRow; i++) { for (j = 0; j < cc; j++) newCell(i, lc+j, 0); } numCol = columnCount(); isDirty = true; }
void tableTemplateWidget::insRow(void) { int tr, rc; int i, j; selectionRange = selectedRanges(); for (i = 0; i < selectionRange.count(); i++) { tr = selectionRange[i].topRow(); rc = selectionRange[i].rowCount(); for (j = 0; j < rc; j++) insertRow(tr); } for (i = 0; i < rc; i++) { for (j = 0; j < numCol; j++) newCell(tr+i, j, 0); } numRow = rowCount(); isDirty = true; }
QTableWidgetSelectionRange OperationTable::selectedRange() const { QList<QTableWidgetSelectionRange> ranges = selectedRanges(); if( ranges.isEmpty() ) return QTableWidgetSelectionRange(); return ranges.first(); }
/** * @brief ChordTableWidget::is_row_selected * @return Vrai si et seulement si une ligne entière est sélectionnée. * * Indique si une ligne de la grille d'accords est actuellement sélectionnée. */ bool ChordTableWidget::isRowSelected() { QList<QTableWidgetSelectionRange> ranges = selectedRanges(); if (ranges.isEmpty()) return false; for (QList<QTableWidgetSelectionRange>::Iterator it = ranges.begin() ; it != ranges.end() ; it ++) if ((*it).leftColumn() != 0 || (*it).rightColumn() != this->columnCount() - 1) return false; return true; }
/** * @brief ChordTableWidget::rows_selected * @return La liste des lignes sélectionnées. * * Donne la liste des lignes actuellement sélectionnées dans la grille. */ QList<QList<int>*> ChordTableWidget::rowsSelected() { QList<QList<int>*> range_rows; QList<QTableWidgetSelectionRange> ranges = selectedRanges(); for (QList<QTableWidgetSelectionRange>::Iterator it = ranges.begin() ; it != ranges.end() ; it ++) { if ((*it).leftColumn() == 0 && (*it).rightColumn() == this->columnCount() - 1) { QList<int>* rows = new QList<int>(); for (int r = (*it).topRow() ; r <= (*it).bottomRow() ; r ++) rows->push_back(r); range_rows.push_back(rows); } } return range_rows; }
void tableTemplateWidget::rmRow(void) { int tr, rc; selectionRange = selectedRanges(); for (int i = 0; i < selectionRange.count(); i++) { tr = selectionRange[i].topRow(); rc = selectionRange[i].rowCount(); for (int j = 0; j < rc; j++) removeRow(tr); } numRow = rowCount(); isDirty = true; }
void tableTemplateWidget::rmColumn(void) { int lc, cc; selectionRange = selectedRanges(); for (int i = 0; i < selectionRange.count(); i++) { lc = selectionRange[i].leftColumn(); cc = selectionRange[i].columnCount(); for (int j = 0; j < cc; j++) removeColumn(lc); } numCol = columnCount(); isDirty = true; }
void TableWidget::paste(){ QList<QTableWidgetSelectionRange> ranges = selectedRanges(); if(ranges.size()==0){ return; } QTableWidgetSelectionRange range = ranges[0]; if(range.leftColumn()<TITLE || range.rightColumn()<TITLE){ QMessageBox::information(this, tr("Discogs dialog"), tr("Pasting in the three first columns is not allowed") ); return; } QString str = QApplication::clipboard()->text(); qDebug()<<"clipboard: "; qDebug()<<str; QStringList rows = str.split('\n'); int numRows = rows.count(); int numColumns = rows.first().count('\t') + 1; if( range.rowCount() * range.columnCount() != 1 && (range.rowCount() != numRows || range.columnCount() != numColumns)) { QMessageBox::information(this, tr("Discogs dialog"), tr("The information cannot be pasted because the copy " "and paste areas aren't the same size.")); return; } bool enabled = isSortingEnabled(); setSortingEnabled(false); for(int i=0; i<numRows; ++i) { QStringList columns = rows[i].split('\t'); for(int j=0; j<numColumns; ++j) { int row = range.topRow() +i; int column = range.leftColumn() +j; if(row < rowCount() && column < columnCount()){ if(!item(row,column)){ TableWidgetItem *item = new TableWidgetItem; setItem(row,column,item); } item(row,column)->setText(columns[j]); } } } setSortingEnabled(enabled); }
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 QgsGraduatedSymbolRendererWidget::keyPressEvent( QKeyEvent *event ) { if ( !event ) { return; } if ( event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier ) { mCopyBuffer.clear(); mCopyBuffer = selectedRanges(); } else if ( event->key() == Qt::Key_V && event->modifiers() == Qt::ControlModifier ) { QgsRangeList::const_iterator rIt = mCopyBuffer.constBegin(); for ( ; rIt != mCopyBuffer.constEnd(); ++rIt ) { mModel->addClass( *rIt ); } emit widgetChanged(); } }
void tableTemplateWidget::contextMenuEvent(QContextMenuEvent *e) { QList<QTableWidgetSelectionRange> listRanges = selectedRanges(); if (listRanges[0].columnCount() == 1) { actionRmRow->setDisabled(true); actionInsRow->setDisabled(true); } if (listRanges[0].rowCount() == 1) { actionRmColumn->setDisabled(true); actionInsColumn->setDisabled(true); } menu->exec(e->globalPos()); actionRmRow->setDisabled(false); actionInsRow->setDisabled(false); actionRmColumn->setDisabled(false); actionInsColumn->setDisabled(false); }