Example #1
0
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();
}
Example #2
0
void TrWidget::slotCopy()
{
#if 0
    QList<QTableWidgetSelectionRange> ranges = m_table->selectedRanges();
    QString str;
    qDebug() << "slotCopy:" << ranges.size();
    for(int i = 0; i < ranges.size(); i++)
    {
        if(i > 0) str += "\n";
        str += copySelectedRange(ranges.at(i));
    }

    qDebug() << str;
    QApplication::clipboard()->setText(str);
#endif
    QString str;
    QTableWidgetItem *item;
    QTableWidgetSelectionRange range = selectedRange();
    qDebug() << "rowCount:" << range.rowCount();
    qDebug() << "columnCount:" << range.columnCount();
    for(int row = 0; row < range.rowCount(); row++)
    {
        if(row > 0){
            str += "\n";
        }
        for(int col = 0; col < range.columnCount(); col++)
        {
            if(col > 0) str += "\t";
            item = m_table->item(range.topRow() + row, range.leftColumn() + col);
            if(item->text().contains('\n')){
                str += QString("\"%1\"").arg(item->text());
            }else{
                str += item->text();
            }
        }
    }
    qDebug() << str;
    QApplication::clipboard()->setText(str);
}
void OperationTable::copy()
{
	QTableWidgetSelectionRange range = selectedRange();
	QString str;

	for(int i = 0; i < range.rowCount(); i++)
	{
		for(int j = 0; j < range.columnCount(); j++)
		{
			if( isColumnHidden( range.leftColumn() + j ) )
				continue;

			str += this->text( range.topRow() + i, range.leftColumn() + j );
			if( j < range.columnCount()-1 )
				str += "\t";
		}
		if( i < range.rowCount() - 1 )
			str += "\n";
	}

	QApplication::clipboard()->setText(str);
}
void UISpreadsheet::paste()
{
    QTableWidgetSelectionRange range = selectedRange();
    QString str = QApplication::clipboard()->text();
    QStringList rows = str.split('\n');
    int numRows = rows.count();
    int numColumns = rows.first().count('\t') + 1;
    cout<<str.toStdString()<<" to paste "<<endl;

    if (range.rowCount() * range.columnCount() != 1
            && (range.rowCount() != numRows
                || range.columnCount() != numColumns)) {
        QMessageBox::information(this, tr("Spreadsheet"),
                tr("The information cannot be pasted because the copy "
                   "and paste areas aren't the same size."));
        return;
    }

    cout<<"hola-------------------------------"<<endl;
    
    for (int i = 0; i < numRows; ++i) {
        QStringList columns = rows[i].split('\t');
       // cout<<"---"<<columns[0].toStdString();
      //  cout<<" tmb "<<columns[1].toStdString()<<endl;
        cout<<numRows<<"filas to copy"<<endl;
        for (int j = 0; j < numColumns; ++j) {
            int row = range.topRow() + i;
            cout<<"row"<<row<<endl;
            int column = range.leftColumn() + j;
            if (row < RowCount && column < ColumnCount)
              setFormula(row, column, columns[j]);
            //somethingChanged();
            //cout<<columns[j].toStdString()<<"should paste "<<row<<" "<<column<<endl;
        }
    }
  // somethingChanged();
}
Example #5
0
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;
}
Example #6
0
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();
}