Example #1
0
bool Matrix::isColumnSelected(int col, bool full)
{
	QList<QTableWidgetSelectionRange> sel = d_table->selectedRanges();
	QListIterator<QTableWidgetSelectionRange> it(sel);
	QTableWidgetSelectionRange cur;

	if ( !full )
	{
		if( it.hasNext() )
		{
			cur = it.next();
			if ( (col >= cur.leftColumn()) && (col <= cur.rightColumn() ) )
				return true;
		}
	}
	else
	{
		if( it.hasNext() )
		{
			cur = it.next();
			if ( col >= cur.leftColumn() &&
					col <= cur.rightColumn() &&
					cur.topRow() == 0 &&
					cur.bottomRow() == numRows() - 1 )
				return true;
		}
	}
	return false;
}
Example #2
0
void PreFlightCheckListPage::slotEdit()
{
  QTableWidgetItem* item = m_list->currentItem();

  if( item == static_cast<QTableWidgetItem *>(0) )
    {
      // Item can be a Null pointer!
      return;
    }

  QList<QTableWidgetSelectionRange> selRangeList = m_list->selectedRanges();

  if( selRangeList.size() == 0 )
    {
      // Nothing seems to be selected
      return;
    }

  QTableWidgetSelectionRange sr = selRangeList.at(0);

  if( sr.rowCount() > 1 )
    {
      // More than one row are selected
      return;
    }

  if( sr.rightColumn() == 1 )
    {
	  slotEditCell( m_list->currentRow(), 1 );
    }
}
Example #3
0
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;
}
Example #4
0
//-----------------------------------------------------------------------------
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);
}
Example #5
0
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);
}
Example #6
0
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;
}
Example #7
0
void MainWindow::on_actionSort_triggered()
{
    SortDialog dialog(this);
    QTableWidgetSelectionRange range = spreadsheet->selectedRange();
    dialog.setColumnRange('A' + range.leftColumn(), 'A' + range.rightColumn());

    if(dialog.exec()){
        spreadsheet->sort(Compare(dialog));
    }
}
Example #8
0
void MainWindow::sort()
{
	SortDialog  dialog(this);
	QTableWidgetSelectionRange range = spreadsheet->selectedRange();
	dialog.setColumnRange('A' + range.leftColumn(),'A'+range.rightColumn());
	if(dialog.exec())
	{
		SpreadsheetCompare compare;
		compare.keys[0]=dialog.primarycolumncombo->currentIndex();
		compare.keys[1]=dialog.sencondarycolumncombo->currentIndex() - 1;
		compare.keys[2]=dialog.tertiarycolumncombo->currentIndex() - 1;
		compare.ascending[0] = (dialog.primaryordercombo->currentIndex() ==0);
		compare.ascending[1] = (dialog.secondaryordercombo->currentIndex() == 0);
		compare.ascending[2] = (dialog.tertiaryordercombo->currentIndex() == 0);
		spreadsheet->sort(compare);
	}
}
Example #9
0
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);
}
Example #10
0
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);
}
Example #11
0
void TreeSubWindow::duplicateDownSelection(unsigned int rep)
{
  QList<QTableWidgetSelectionRange> selection = nodeEditor_->selectedRanges();
  if (selection.size() == 0) {
    QMessageBox::critical(phyview_, QString("Oups..."), QString("No selection."));
    return;
  }
  //Perform some checking:
  int row = -1;
  for (int i = 0; i < selection.size(); ++i) {
    QTableWidgetSelectionRange range = selection[i];
    if (range.rowCount() != 1) {
      QMessageBox::critical(phyview_, QString("Oups..."), QString("Only one row can be selected."));
      return;
    }
    if (i == 0) {
      row = range.topRow();
    } else {
      if (range.topRow() != row) {
        QMessageBox::critical(phyview_, QString("Oups..."), QString("Only one row can be selected."));
        return;
      }
    }
  }
  //Ok, if we reach this stage, then everything is ok...
  int j;
  for (j = row + 1; j < nodeEditor_->rowCount() && j - row <= static_cast<int>(rep); ++j) {
    for (int i = 0; i < selection.size(); ++i) {
      QTableWidgetSelectionRange range = selection[i];
      for (int k = range.leftColumn(); k <= range.rightColumn(); ++k) {
        nodeEditor_->setItem(j, k, nodeEditor_->item(row, k)->clone());
      }
    }
  }
  //Shift selection:
  for (int i = 0; i < selection.size(); ++i) {
    QTableWidgetSelectionRange range = selection[i];
    nodeEditor_->setRangeSelected(range, false);
    nodeEditor_->setRangeSelected(QTableWidgetSelectionRange(j - 1, range.leftColumn(), j - 1, range.rightColumn()), true);
  }
}
Example #12
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 #13
0
void PreFlightCheckListPage::slotDeleteRows()
{
  if( m_list->rowCount() == 0 || m_list->columnCount() != 2 )
    {
      return;
    }

  QList<QTableWidgetItem *> items = m_list->selectedItems();

  if( items.size() == 0 )
    {
      // no selection is active
      return;
    }

  QList<QTableWidgetSelectionRange> selRangeList = m_list->selectedRanges();

  if( selRangeList.size() == 0 )
    {
      // Nothing seems to be selected
      return;
    }

  QTableWidgetSelectionRange sr = selRangeList.at(0);

  if( sr.rightColumn() != 1 )
    {
      return;
    }

  QMessageBox mb( QMessageBox::Question,
                  tr( "Delete?" ),
                  tr( "Delete selected entries?" ),
                  QMessageBox::Yes | QMessageBox::No,
                  this );

  mb.setDefaultButton( QMessageBox::No );

#ifdef ANDROID

  mb.show();
  QPoint pos = mapToGlobal(QPoint( width()/2 - mb.width()/2, height()/2 - mb.height()/2 ));
  mb.move( pos );

#endif

  if( mb.exec() == QMessageBox::No )
    {
      return;
    }

  QList<int> rows2Remove;

  for( int i = 0; i < items.size(); i++ )
    {
      QTableWidgetItem *item = items.at(i);

      int row = m_list->row( item );
      int col = m_list->column( item );

      delete m_list->takeItem( row, col );

      if( rows2Remove.contains( row ) )
        {
          continue;
        }

      rows2Remove.append( row );
    }

  std::sort( rows2Remove.begin(), rows2Remove.end() );

  for( int i = rows2Remove.size()-1; i >= 0; i-- )
    {
      m_list->removeRow( rows2Remove.at(i) );
    }

  m_list->resizeColumnToContents( 0 );

  m_ok->show();

  if( m_list->rowCount() == 0 )
    {
      m_editButton->setEnabled( false );
      m_deleteButton->setEnabled( false );
    }
}
Example #14
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();
}