Skip to content

Commit

Permalink
Re #8774. Block attemts to add rows to a MantidTable.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Feb 25, 2014
1 parent 05fd06f commit 58e61e5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
25 changes: 20 additions & 5 deletions Code/Mantid/MantidPlot/src/Mantid/MantidTable.cpp
Expand Up @@ -31,6 +31,7 @@ m_ws(ws),
m_wsName(ws->getName()),
m_transposed(transpose)
{
d_table->blockResizing(true);
// if plot types is set in ws then update Table with that information
for ( size_t i = 0; i < ws->columnCount(); i++ )
{
Expand All @@ -54,6 +55,7 @@ m_transposed(transpose)

connect(this,SIGNAL(needToClose()),this,SLOT(closeTable()));
connect(this,SIGNAL(needToUpdate()),this,SLOT(updateTable()));
connect(d_table,SIGNAL(unwantedResize()),this,SLOT(dealWithUnwantedResize()));
observePreDelete();
observeAfterReplace();
}
Expand All @@ -67,16 +69,23 @@ void MantidTable::updateTable()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

// Delete old data
setNumRows(0);
setNumCols(0);

// Fill with the new data
fillTable();

QApplication::restoreOverrideCursor();
}

/**
* Respond to cellsAdded signal from d_table.
*/
void MantidTable::dealWithUnwantedResize()
{
if (static_cast<int>(m_ws->rowCount()) != d_table->numRows() || static_cast<int>(m_ws->columnCount()) != d_table->numCols())
{
updateTable();
}
}

/** Refresh the table by filling it */
void MantidTable::fillTable()
{
Expand All @@ -86,6 +95,9 @@ void MantidTable::fillTable()
return;
}

// temporarily allow resizing
d_table->blockResizing(false);

// Resize to fit the new workspace
setNumRows(static_cast<int>(m_ws->rowCount()));
setNumCols(static_cast<int>(m_ws->columnCount()));
Expand Down Expand Up @@ -139,6 +151,10 @@ void MantidTable::fillTable()
for(int j=0; j < static_cast<int>(m_ws->rowCount()); j++)
d_table->verticalHeader()->setLabel(j,QString::number(j));
}

// block resizing
d_table->blockResizing(true);

}

/**
Expand Down Expand Up @@ -265,7 +281,6 @@ void MantidTable::cellEdited(int row,int col)
d_table->setText(row, col, QString(s.str().c_str()));
}


//------------------------------------------------------------------------------------------------
/** Call an algorithm in order to delete table rows
*
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidTable.h
Expand Up @@ -32,6 +32,7 @@ protected slots:
void fillTable();
void fillTableTransposed();
void updateTable();
void dealWithUnwantedResize();

protected:
void preDeleteHandle(const std::string& wsName,const boost::shared_ptr<Mantid::API::Workspace> ws);
Expand Down
53 changes: 45 additions & 8 deletions Code/Mantid/MantidPlot/src/Table.cpp
Expand Up @@ -1085,28 +1085,47 @@ void Table::insertCol()
insertCols(selectedCol, 1);
}

/**
* Insert a row before the current row.
*/
void Table::insertRow()
{
int cr = d_table->currentRow();
if (d_table->isRowSelected (cr, true))
{
d_table->insertRows(cr, 1);
emit modifiedWindow(this);
insertRows(cr, 1);
}
}

/**
* Insert a row before a specified index.
* @param row :: Row number at which to insert.
*/
void Table::insertRow(int row)
{
if (row < numRows())
{
d_table->insertRows(row, 1);
emit modifiedWindow(this);
insertRows(row, 1);
}
}

void Table::addRows(int num)//Mantid
/**
* Add rows to the end of the table.
* @param num :: Number of rows to add.
*/
void Table::addRows(int num)
{
insertRows(numRows(), num);
}

/**
* Insert rows before a specified row.
* @param atRow :: Row number at which to insert.
* @param num :: Number of rows to insert.
*/
void Table::insertRows(int atRow, int num)
{
d_table->insertRows(numRows(), num);
d_table->insertRows(atRow, num);
emit modifiedWindow(this);
}

Expand Down Expand Up @@ -3315,11 +3334,11 @@ void Table::showAllColumns()
*****************************************************************************/

MyTable::MyTable(QWidget * parent, const char * name)
:Q3Table(parent, name)
:Q3Table(parent, name),m_blockResizing(false)
{}

MyTable::MyTable(int numRows, int numCols, QWidget * parent, const char * name)
:Q3Table(numRows, numCols, parent, name)
:Q3Table(numRows, numCols, parent, name),m_blockResizing(false)
{}

void MyTable::activateNextCell()
Expand All @@ -3335,3 +3354,21 @@ void MyTable::activateNextCell()
setCurrentCell (row + 1, col);
selectCells(row+1, col, row+1, col);
}

void MyTable::blockResizing(bool yes)
{
m_blockResizing = yes;
}

void MyTable::resizeData(int n)
{
if ( m_blockResizing )
{
emit unwantedResize();
}
else
{
Q3Table::resizeData(n);
}
}

7 changes: 7 additions & 0 deletions Code/Mantid/MantidPlot/src/Table.h
Expand Up @@ -44,12 +44,18 @@

class MyTable : public Q3Table
{
Q_OBJECT
public:
MyTable(QWidget * parent = 0, const char * name = 0);
MyTable(int numRows, int numCols, QWidget * parent = 0, const char * name = 0);
void blockResizing(bool yes);

signals:
void unwantedResize();
private:
void activateNextCell();
void resizeData(int n);
bool m_blockResizing; // a workaround to prevent unwanted resizes
};

/**\brief MDI window providing a spreadsheet table with column logic.
Expand Down Expand Up @@ -231,6 +237,7 @@ public slots:
void insertRow();
void insertRow(int row);//Mantid
void addRows(int num);//Mantid
virtual void insertRows(int atRow, int num);
//@}

//! Selection Operations
Expand Down

0 comments on commit 58e61e5

Please sign in to comment.