예제 #1
0
void KImportDialog::assignColumn(QListViewItem *item)
{
    if(!item) return;

    //  kdDebug(5300) << "KImportDialog::assignColumn(): current Col: " << mTable->currentColumn()
    //            << endl;

    ColumnItem *colItem = (ColumnItem *)item;

    QTableSelection selection = mTable->selection(mTable->currentSelection());

    //  kdDebug(5300) << " l: " << selection.leftCol() << "  r: " << selection.rightCol() << endl;

    for(int i = selection.leftCol(); i <= selection.rightCol(); ++i)
    {
        if(i >= 0)
        {
            mTable->horizontalHeader()->setLabel(i, colItem->text(0));
            mColumnDict.replace(i, colItem->column());
            int format = mFormatCombo->currentItem() + 1;
            mFormats.replace(i, format);
            colItem->column()->addColId(i);
        }
    }

    readFile();
}
예제 #2
0
void TableEditor::slotContextMenuRequested( int row, int col, const QPoint & pos )
{
  m_row = row;
  m_col = col;
  m_popup->setItemEnabled(m_cellEditId, (row >=0 && col >=0));
  m_popup->setItemEnabled(m_rowEditId, (row >=0));
  m_popup->setItemEnabled(m_colEditId, (col >=0));
  m_popup->setItemVisible(m_mergeSeparatorId, false);
  m_popup->setItemVisible(m_mergeCellsId, false);
  m_popup->setItemVisible(m_unmergeCellsId, false);
  if  (row >=0 && col >=0) {
    TableNode tableNode = (*m_tableTags)[m_row][m_col];
    m_popup->setItemVisible(m_mergeSeparatorId, false);
    m_popup->setItemVisible(m_mergeCellsId, false);
     m_popup->setItemVisible(m_editChildId, false);
    if (tableNode.merged) {
      m_popup->setItemVisible(m_unmergeCellsId, true);
      m_popup->setItemVisible(m_mergeSeparatorId, true);
    }
    QTableSelection selection = m_dataTable->selection(m_dataTable->currentSelection());
    QRect rect(QPoint(selection.topRow(), selection.leftCol()) ,
               QPoint(selection.bottomRow(), selection.rightCol()));
    if (rect.isValid() && (rect.width() > 1 || rect.height() > 1) && rect.contains(m_row, m_col)) {
       m_popup->setItemVisible(m_mergeCellsId, true);
       m_popup->setItemVisible(m_mergeSeparatorId, true);
    }
    if (m_dataTable->item(m_row, m_col) && !m_dataTable->item(m_row, m_col)->pixmap().isNull()) {
       m_popup->setItemVisible(m_editChildId, true);
    }
  }
  m_popup->popup(pos);
}
예제 #3
0
void TableEditor::slotMergeCells()
{
  slotUnmergeCells(); //first unmerge all cells from the selection

  QTableSelection selection = m_dataTable->selection(m_dataTable->currentSelection());
  int tRow, bRow, lCol, rCol;
  tRow = selection.topRow();
  bRow = selection.bottomRow();
  lCol = selection.leftCol();
  rCol = selection.rightCol();
  TableNode *mainTableNode = &((*m_tableTags)[tRow][lCol]);
  if (rCol - lCol > 0)
    mainTableNode->node->tag->editAttribute("colspan", QString("%1").arg(rCol - lCol + 1));
  if (bRow - tRow > 0)
    mainTableNode->node->tag->editAttribute("rowspan", QString("%1").arg(bRow - tRow + 1));
  for (int i = 0; i < bRow - tRow + 1; i++)
    for (int j = 0; j < rCol - lCol + 1; j++) {
      if (i != 0 || j != 0) {
        setCellText(m_dataTable, tRow + i, lCol + j, i18n("Merged with (%1, %2).").arg(tRow + 1).arg(lCol + 1));
        m_dataTable->item(tRow + i, lCol + j)->setEnabled(false);
        TableNode *tableNode = &((*m_tableTags)[tRow + i][lCol + j]);
        Node::deleteNode(tableNode->node);
        tableNode->node = new Node(0L);
        newNum++;
        tableNode->node->tag = new Tag(*(mainTableNode->node->tag));
        tableNode->merged = true;
        tableNode->mergedRow = tRow;
        tableNode->mergedCol = lCol;
      }
    }
}
예제 #4
0
void setColValuesDialog::setTable(Table* w)
{
table=w;
QStringList colNames=w->colNames();
int cols = w->tableCols();
for (int i=0; i<cols; i++)
	boxColumn->insertItem("col(\""+colNames[i]+"\")",i); 

int s = w->table()->currentSelection();
if (s >= 0)
	{
	QTableSelection sel = w->table()->selection(s);
	w->setSelectedCol(sel.leftCol());

	start->setValue(sel.topRow() + 1);
	end->setValue(sel.bottomRow() + 1);
	}
else
	{
	start->setValue(1);
	end->setValue(w->tableRows());
	}

updateColumn(w->selectedColumn());
commandes->setContext(w);
}
예제 #5
0
void ScheduleDialog::swapRows(int index1, int index2)
{
    Q_ASSERT(index1 != index2);
    Q_ASSERT(index1 >= 0);
    Q_ASSERT(index1 < (int)blocks_.size());
    Q_ASSERT(index2 >= 0);
    Q_ASSERT(index2 < (int)blocks_.size());
    Q_ASSERT((int)blocks_.size() == timingTable->numRows());

    BlockNode *node = blocks_[index1];
    blocks_[index1] = blocks_[index2];
    blocks_[index2] = node;

    timingTable->swapRows(index1, index2);
    timingTable->clearSelection();

    timingTable->updateContents();

    // set row selection
    // doesnt work with qt 3.0.6:
    //    timingTable->selectRow(index2);
    // workaround:
    QTableSelection selection;
    selection.init(index2, 0);
    selection.expandTo(index2, timingTable->numCols() -1);
    timingTable->addSelection(selection);


    // redraw canvas
    clearCanvas();
    initCanvas();
    // sync selection
    updateHighlighter(index2, 0);
}
예제 #6
0
void DayView::dateChanged( int y, int m, int d )
{
    QDate date( y, m, d );
    if ( currDate == date )
        return;
    currDate.setYMD( y, m, d );
    reschedule();
    dayViewWidget()->clearSelection();
    QTableSelection ts;

    if (jumpToCurTime && this->date() == QDate::currentDate())
    {
        ts.init( QTime::currentTime().hour(), 0);
        ts.expandTo( QTime::currentTime().hour(), 0);
    } else {
        ts.init( startTime, 0 );
        ts.expandTo( startTime, 0 );
    }

    dayViewWidget()->addSelection( ts );
    selectedWidget = 0;
}
예제 #7
0
void KImportDialog::headerSelected(QListViewItem *item)
{
    KImportColumn *col = ((ColumnItem *)item)->column();

    if(!col) return;

    mFormatCombo->clear();

    QValueList<int> formats = col->formats();

    QValueList<int>::ConstIterator it = formats.begin();
    QValueList<int>::ConstIterator end = formats.end();
    while(it != end)
    {
        mFormatCombo->insertItem(col->formatName(*it), *it - 1);
        ++it;
    }

    QTableSelection selection = mTable->selection(mTable->currentSelection());

    updateFormatSelection(selection.leftCol());
}
예제 #8
0
void KVocTrainTable::activateNextCell()
{
  int currRow = currentRow();
  int currCol = currentColumn();

  QTableSelection currentSel = selection(0);

  int tr = currentSel.topRow();
  int br = currentSel.bottomRow();
  int lc = currentSel.leftCol();
  int rc = currentSel.rightCol();

  if (currCol == rc)
  {
    if (currRow < br)
      setCurrentCell(currRow + 1, lc);
    else
      setCurrentCell(tr, lc);
  }
  else
    setCurrentCell(currRow, currCol + 1);

}
예제 #9
0
void KImportDialog::removeColumn()
{
    QTableSelection selection = mTable->selection(mTable->currentSelection());

    //  kdDebug(5300) << " l: " << selection.leftCol() << "  r: " << selection.rightCol() << endl;

    for(int i = selection.leftCol(); i <= selection.rightCol(); ++i)
    {
        if(i >= 0)
        {
            mTable->horizontalHeader()->setLabel(i, QString::number(i + 1));
            KImportColumn *col = mColumnDict.find(i);
            if(col)
            {
                mColumnDict.remove(i);
                mFormats.remove(i);
                col->removeColId(i);
            }
        }
    }

    readFile();
}
예제 #10
0
void KImportDialog::tableSelected()
{
    QTableSelection selection = mTable->selection(mTable->currentSelection());

    QListViewItem *item = mHeaderList->firstChild();
    KImportColumn *col = mColumnDict.find(selection.leftCol());
    if(col)
    {
        while(item)
        {
            if(item->text(0) == col->header())
            {
                break;
            }
            item = item->nextSibling();
        }
    }
    if(item)
    {
        mHeaderList->setSelected(item, true);
    }

    updateFormatSelection(selection.leftCol());
}
예제 #11
0
void TableEditor::slotUnmergeCells()
{
  int tRow, bRow, lCol, rCol;
  int selectionNum = m_dataTable->currentSelection();
  if (selectionNum != -1) {
    QTableSelection selection = m_dataTable->selection(selectionNum);
    tRow = selection.topRow();
    bRow = selection.bottomRow();
    lCol = selection.leftCol();
    rCol = selection.rightCol();
  } else {
    tRow = m_row;
    bRow = m_row;
    lCol = m_col;
    rCol = m_col;
  }
  for (int row = tRow; row <= bRow; ++row)
    for (int col = lCol; col <= rCol; ++col) {
      TableNode tableNode = (*m_tableTags)[row][col];
      if (!tableNode.merged)
        continue;
      TableNode newTableNode;
      int i = 0;
      int j = 0;
      for (QValueList<QValueList<TableNode> >::Iterator it = m_tableTags->begin(); it != m_tableTags->end(); ++it) {
        j = 0;
        QValueList<TableNode>::Iterator it2 = (*it).begin();
        while (it2 != (*it).end()) {
          if ((*it2).merged &&
              tableNode.mergedRow == (*it2).mergedRow &&
              tableNode.mergedCol == (*it2).mergedCol) {

              Node::deleteNode((*it2).node);
              newNum--;
              it2 = (*it).erase(it2);
              newTableNode.merged = false;
              newTableNode.node = new Node(0L);
              newNum++;
              newTableNode.node->tag = new Tag();
              newTableNode.node->tag->setDtd(m_dtd);
              if (m_tableTags == m_tableHeaderTags) {
                newTableNode.node->tag->parse("<th>", m_write);
              } else {
                newTableNode.node->tag->parse("<td>", m_write);
              }
              (*it).insert(it2, newTableNode);
              setCellText(m_dataTable, i, j, tagContent(newTableNode.node));
              m_dataTable->item(i, j)->setEnabled(true);
          } else {
            ++it2;
          }
          j++;
        }
        i++;
      }
      newTableNode = (*m_tableTags)[tableNode.mergedRow][tableNode.mergedCol];
      newTableNode.node->tag->deleteAttribute("colspan");
      newTableNode.node->tag->deleteAttribute("rowspan");
      //change the main node
      TableNode tmpNode = newTableNode;
      newTableNode.node = new Node(0L);
      newNum++;
      newTableNode.node->tag = new Tag(*(tmpNode.node->tag));
      QValueList<QValueList<TableNode> >::Iterator iter1 = m_tableTags->at(tableNode.mergedRow);
      QValueList<TableNode>::Iterator iter2 = (*iter1).at(tableNode.mergedCol);
      iter2 = (*iter1).erase(iter2);
      (*iter1).insert(iter2, newTableNode);
      Node::deleteNode(tmpNode.node);
      newNum--;
    }
}
예제 #12
0
//     My own version of the table's actions
//    In principle it does the same as QTable, but
//       deletes selected cells
//      closes application on ESCAPE
bool MTable::eventFilter( QObject *o, QEvent *e )
{
    if ( !o || !e )
	return QScrollView::eventFilter( o, e );

    //QWidget *editorWidget = cellWidget( currentRow(), currentColumn() );

    switch ( e->type() ) {
    case QEvent::KeyPress:
	if ( !isEditing() ) {
                  QKeyEvent *ke = (QKeyEvent*)e;
	    if ( ke->key() == Key_Escape ) {
                           QApplication::sendEvent( parentWidget ( FALSE ) , e );
		return TRUE;
	    }

	    if ( ke->key() == Key_Return || ke->key() == Key_Enter ) {
		if ( currentRow() >= numRows() - 1 ){
		    setUpdatesEnabled( false );
		    setNumRows( numRows() + 10 );
		    setUpdatesEnabled( true );
		}
	        activateNextCell();
                ensureCellVisible ( currentRow(), currentColumn() );
		return TRUE;
	    }

	    if ( ke->key() == Key_Delete ) {
	            if (numSelections() > 0) {
		    QTableSelection ts = selection( currentSelection() );
		    for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){
			for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){
                                         clearCell( irow, icol );
		      }
		    }
		    setCurrentCell ( ts.anchorRow(), ts.anchorCol() );
		    clearSelection ( TRUE );
		}
	              else {
                                 clearCell( currentRow(), currentColumn() );
	              }
		return TRUE;
	    }
	    if ( ke->key() == Key_C && ( ke->state() & ControlButton ) == ControlButton ) {
	              QString cellText;
		 itemCopy.clear();
		if (numSelections() > 0) {
	                  QTableSelection ts;
		    ts = selection( currentSelection() );
		    for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){
		      for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){
		             cellText = text( irow, icol );
                                         if ( !cellText.isEmpty() )
                                              itemCopy.push_back( cellText.latin1() );
		             else
                                              itemCopy.push_back( "" );
		      }
		    }
		}
		else {
	                   cellText = text( currentRow(), currentColumn() );
                                 if ( !cellText.isEmpty() )
                                              itemCopy.push_back( cellText.latin1() );
                                 else      itemCopy.push_back( "" );
		}
		return TRUE;
	    }
	    if ( ke->key() == Key_V && ( ke->state() & ControlButton ) == ControlButton ) {
		if ( numSelections() > 0 && itemCopy.size() > 0 ) {
		    QTableSelection ts = selection( currentSelection() );
		    uint icount;
		    for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){
		       for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){
		             //icount = (icol - ts.leftCol())*(ts.bottomRow() - ts.topRow()+1) + irow-ts.topRow();
		             icount = (irow - ts.topRow())*(ts.rightCol() - ts.leftCol()+1) + icol-ts.leftCol();
                                         if ( icount < itemCopy.size() )
                                            setText( irow, icol, (itemCopy[icount]).c_str() );
		      }
		    }
		}
		else {
		    if ( itemCopy.size() > 0 ) // there was not selection, copy first item only
		         setText( currentRow(), currentColumn(), (itemCopy[0]).c_str() );
		}
		return TRUE;
	    }
	    if ( ke->key() == Key_X && ( ke->state() & ControlButton ) == ControlButton ) {
		QString cellText;
		if (numSelections() > 0) {
		    itemCopy.clear();
		   QTableSelection ts;
		    ts = selection( currentSelection() );
		    for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){
		      for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){
		             cellText = text( irow, icol );
                                         if ( !cellText.isEmpty() )
                                              itemCopy.push_back( cellText.latin1() );
		             else
                                              itemCopy.push_back( "" );
                                         clearCell( irow, icol );
		      }
		    }
		    setCurrentCell ( ts.anchorRow(), ts.anchorCol() );
		    clearSelection ( TRUE );
		}
		else {
	                   cellText = text( currentRow(), currentColumn() );
                                 if ( !cellText.isEmpty() )
                                              itemCopy.push_back( cellText.latin1() );
                                 else      itemCopy.push_back( "" );
                                clearCell( currentRow(), currentColumn() );
		}
		return TRUE;
	    }

	    if ( currentColumn() == 0 &&
	         ctype == ComboBox   &&
                       ke->key() != Key_Left  && ke->key() != Key_Right &&
                       ke->key() != Key_Up  && ke->key() != Key_Down &&
                       ke->key() != Key_Control && ke->key() != Key_Alt &&
                       ke->key() != Key_Shift ) {
		//QApplication::beep ();
		keyPressEvent( (QKeyEvent*)e );
		return true;
	    }
	}
        else{
            QKeyEvent *ke = (QKeyEvent*)e;
	    if ( ke->key() == Key_Return || ke->key() == Key_Enter ) {
                stopEditing();
		if ( currentRow() >= numRows() - 1 ){
		    setUpdatesEnabled( false );
		    setNumRows( numRows() + 10 );
		    setUpdatesEnabled( true );
		}
                //else {stopEditing();}
                activateNextCell();
		return true;
	    }
        }
        break;
    default:
	break;
    }

    return QTable::eventFilter( o, e ) ;
}
예제 #13
0
QString CQueryTable::copy_data(int row, int col)
{
#ifdef DEBUG
  qDebug("CQueryTable::copy_data(int, int)");
#endif

  if (!query())
    return QString::null;

  if (query()->isResultNull() || isBlocked())
    return QString::null;

  if (currentSelection() == -1 && !forceCopyAll())
    return copy_current_selection_func(row, col);
  else
  {
    QTableSelection sel;
    if (currentSelection() == -1 || forceCopyAll())
    {
      sel.init(0, 0);
      sel.expandTo(numRows() -1, numCols() - 1);
    }
    else
      sel = selection(currentSelection());

    if (sel.topRow() == sel.bottomRow() && sel.leftCol() == sel.rightCol() && !forceCopyAll())
      return copy_current_selection_func(row, col);

    setBlocked(true);
    QString cpy;
    QString separator = "+";
    int current_col;
    uint length;
    QMap<uint, ulong> max_length_map; 
    QString tmp;

    for (current_col = sel.leftCol(); current_col <= sel.rightCol(); current_col++)
    {
      if (horizontalHeader()->sectionSize(current_col) <= 0)
        continue;
      length = strlen(query()->fields(current_col).name);
      length = max(length, query()->fields(current_col).max_length);
      if (length < strlen(NULL_TEXT) && !IS_NOT_NULL(query()->fields(current_col).flags))
        length = strlen(NULL_TEXT);
      max_length_map.insert(current_col, length + 1);
      for (uint i = 0; i < min(max_length_map[current_col] - 1, MAX_COLUMN_LENGTH) + 2; i++)
        separator += "-";
      separator += "+";
    }

    separator += "\n";
    cpy = separator + "|";
    
    for (current_col = sel.leftCol(); current_col <= sel.rightCol(); current_col++)
    {
      if (horizontalHeader()->sectionSize(current_col) <= 0)
        continue;
      tmp.sprintf(" %-*s|",min((int) max_length_map[current_col], MAX_COLUMN_LENGTH), query()->fields(current_col).name);
      cpy += tmp;
    }
    cpy += "\n" + separator;

    copy_data_func(&cpy, query(), &sel, &max_length_map);

    setBlocked(false);
    return cpy + separator;
  }
}