1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
/* TRANSLATOR BALL::QSAR
Necessary for lupdate.
*/
#include <inputDataDialog.h>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QFileDialog>
#include <QtGui/QLabel>
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include <QtCore/QFile>
#include <QtCore/QTextStream>
#include <QtGui/QScrollArea>
#include <QtGui/QTableWidget>
#include <QtGui/QHeaderView>
namespace BALL
{
namespace VIEW
{
InputDataDialog::InputDataDialog(InputDataItem* item)
{
///return if there's no parent
if (item == NULL)
{
return;
}
file_name_ = item->name();
if (item->data())
{
compound_names_ = item->data()->getSubstanceNames();
}
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok,Qt::Horizontal, this);
QPushButton* print_button = new QPushButton(tr("Save to File"), buttons);
QVBoxLayout* mainLayout = new QVBoxLayout();
QVBoxLayout* resultGroupLayout = new QVBoxLayout();
QGroupBox* resultGroup = new QGroupBox(tr("Compounds"),this);
if (compound_names_->size() > 0)
{
QStringList labels;
labels << "Compound";
QTableWidget* table = new QTableWidget(compound_names_->size(), 1, this);
table->verticalHeader()->hide();
table->setHorizontalHeaderLabels (labels);
table->setAlternatingRowColors(true);
table->setDragDropMode(QAbstractItemView::NoDragDrop);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
for (unsigned int i=0; i< compound_names_->size(); i++)
{
QTableWidgetItem* name = new QTableWidgetItem(QString(compound_names_->at(i).c_str()));
table->setItem(i, 0, name);
}
QScrollArea* scrollArea = new QScrollArea(this);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea->setFrameShape(QFrame::NoFrame);
scrollArea->setWidget(table);
scrollArea->setWidgetResizable(true);
resultGroupLayout->addWidget(scrollArea);
resultGroup->setLayout(resultGroupLayout);
}
else
{
QLabel* label = new QLabel(tr("No data available, please execute pipeline first."));
resultGroupLayout->addWidget(label);
resultGroup->setLayout(resultGroupLayout);
}
mainLayout->addWidget(resultGroup);
mainLayout->addWidget(buttons);
mainLayout->addStretch(1);
setLayout(mainLayout);
setWindowTitle(tr("Descriptors in ") + item->name());
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
connect(print_button, SIGNAL(clicked()), this, SLOT(saveToFile()));
}
InputDataDialog::~InputDataDialog()
{
}
void InputDataDialog::saveToFile()
{
QString filename = QFileDialog::getSaveFileName(this, tr("Save File as"),
file_name_ + tr("_compounds") + ".txt",
tr("text") + " (*.txt)");
if (filename.isEmpty())
{
return;
}
QFile file(filename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
{
return;
}
QTextStream out(&file);
for (unsigned int i=0; i< compound_names_->size(); i++)
{
out << QString(compound_names_->at(i).c_str()) << "\n";
}
}
}
}
|