Skip to content

Commit

Permalink
Re #10576. Copy values to the clipboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Apr 8, 2015
1 parent c2f3da6 commit b3a66c0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
Expand Up @@ -249,6 +249,7 @@ private slots:
void setAllValues(double);
void fixParameter(int,bool);
void setAllFixed(bool);
void copy();
void paste();
private:
bool eventFilter(QObject * obj, QEvent * ev);
Expand Down
51 changes: 35 additions & 16 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MultiDatasetFit.cpp
Expand Up @@ -53,6 +53,8 @@ namespace{
// colours of the fitting range selector
QColor rangeSelectorDisabledColor(Qt::darkGray);
QColor rangeSelectorEnabledColor(Qt::blue);

QString makeNumber(double d) {return QString::number(d,'g',16);}
}

namespace MantidQt
Expand Down Expand Up @@ -811,7 +813,7 @@ EditLocalParameterDialog::EditLocalParameterDialog(MultiDatasetFit *multifit, co
m_uiForm.tableWidget->insertRow(i);
auto cell = new QTableWidgetItem( QString("f%1.").arg(i) + parName );
m_uiForm.tableWidget->setItem( i, 0, cell );
cell = new QTableWidgetItem( QString::number(value) );
cell = new QTableWidgetItem( makeNumber(value) );
m_uiForm.tableWidget->setItem( i, 1, cell );
}
auto deleg = new LocalParameterItemDelegate(this);
Expand Down Expand Up @@ -840,7 +842,7 @@ void EditLocalParameterDialog::valueChanged(int row, int col)
catch(std::exception&)
{
// restore old value
m_uiForm.tableWidget->item(row,col)->setText( QString::number(m_values[row]) );
m_uiForm.tableWidget->item(row,col)->setText( makeNumber(m_values[row]) );
}
}
}
Expand All @@ -851,7 +853,7 @@ void EditLocalParameterDialog::setAllValues(double value)
for(int i = 0; i < n; ++i)
{
m_values[i] = value;
m_uiForm.tableWidget->item(i,1)->setText( QString::number(value) );
m_uiForm.tableWidget->item(i,1)->setText( makeNumber(value) );
}
}

Expand All @@ -877,7 +879,7 @@ void EditLocalParameterDialog::setAllFixed(bool value)
{
m_fixes[i] = value;
// it's the only way I am able to make the table to repaint itself
auto text = QString::number(m_values[i]);
auto text = makeNumber(m_values[i]);
m_uiForm.tableWidget->item(i,1)->setText( text + " " );
m_uiForm.tableWidget->item(i,1)->setText( text );
}
Expand Down Expand Up @@ -905,19 +907,36 @@ void EditLocalParameterDialog::showContextMenu()

if ( !hasSelection ) return;

auto text = QApplication::clipboard()->text();
bool canPaste = !text.isEmpty();

QMenu *menu = new QMenu(this);
QAction *action = new QAction("Paste",this);
action->setToolTip("Paste data from clipboard.");
connect(action,SIGNAL(activated()),this,SLOT(paste()));
action->setEnabled(canPaste);
menu->addAction(action);
{
QAction *action = new QAction("Copy",this);
action->setToolTip("Copy data to clipboard.");
connect(action,SIGNAL(activated()),this,SLOT(copy()));
menu->addAction(action);
}
{
QAction *action = new QAction("Paste",this);
action->setToolTip("Paste data from clipboard.");
connect(action,SIGNAL(activated()),this,SLOT(paste()));
auto text = QApplication::clipboard()->text();
action->setEnabled(!text.isEmpty());
menu->addAction(action);
}

menu->exec(QCursor::pos());
}

void EditLocalParameterDialog::copy()
{
QStringList text;
auto n = m_values.size();
for(int i = 0; i < n; ++i)
{
text << makeNumber(m_values[i]);
}
QApplication::clipboard()->setText( text.join("\n") );
}

void EditLocalParameterDialog::paste()
{
auto text = QApplication::clipboard()->text();
Expand Down Expand Up @@ -1415,11 +1434,11 @@ void DataController::addWorkspaceSpectrum(const QString &wsName, int wsIndex, co
cell->setFlags(flags);

const double startX = ws.readX(wsIndex).front();
cell = new QTableWidgetItem( QString::number(startX) );
cell = new QTableWidgetItem( makeNumber(startX) );
m_dataTable->setItem( row, startXColumn, cell );

const double endX = ws.readX(wsIndex).back();
cell = new QTableWidgetItem( QString::number(endX) );
cell = new QTableWidgetItem( makeNumber(endX) );
m_dataTable->setItem( row, endXColumn, cell );
}

Expand Down Expand Up @@ -1542,8 +1561,8 @@ void DataController::setFittingRangeGlobal(bool on)
void DataController::setFittingRange(int i, double startX, double endX)
{
if ( i < 0 || i >= m_dataTable->rowCount() ) return;
auto start = QString::number(startX);
auto end = QString::number(endX);
auto start = makeNumber(startX);
auto end = makeNumber(endX);
if ( m_isFittingRangeGlobal )
{
for(int k = 0; k < getNumberOfSpectra(); ++k)
Expand Down

0 comments on commit b3a66c0

Please sign in to comment.