Debian Codegraph @

avogadro/qtplugins/importpqr/pqrwidget.cpp

raw
1 #include "pqrwidget.h"
2 #include "importpqr.h"
3 #include "pqrrequest.h"
4 #include "ui_pqrwidget.h"
5
6 namespace Avogadro::QtPlugins {
7
8 PQRWidget::PQRWidget(QWidget* parent, ImportPQR* p)
9 : QDialog(parent), ui(new Ui::PQRWidget)
10 {
11 plugin = p;
12 ui->setupUi(this);
13
14 ui->tableWidget->setColumnCount(3);
15 ui->tableWidget->setHorizontalHeaderLabels(QStringList() << "Name"
16 << "Formula"
17 << "Mass (g/mol)");
18 ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
19 ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
20 ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
21 ui->tableWidget->setSortingEnabled(true);
22 connect(ui->searchButton, SIGNAL(clicked(bool)), this, SLOT(searchAction()));
23 connect(ui->downloadButton, SIGNAL(clicked(bool)), this, SLOT(downloadMol()));
24 connect(ui->tableWidget, SIGNAL(cellClicked(int, int)), this,
25 SLOT(molSelected(int, int)));
26
27 request = new PQRRequest(ui->tableWidget, ui->pngPreview, ui->nameDisplay,
28 ui->formulaDisplay, this);
29 }
30
31 PQRWidget::~PQRWidget()
32 {
33 delete request;
34 delete ui;
35 }
36
37 /**
38 * @brief Called when the search button is clicked to send a query to PQR
39 */
40 void PQRWidget::searchAction()
41 {
42 ui->downloadButton->setEnabled(false);
43 QString url = "https://pqr.pitt.edu/api/browse/" + ui->molName->text() + "/" +
44 ui->searchTypeBox->currentText();
45 request->sendRequest(url);
46 }
47
48 /**
49 * @brief Called when a table result is double clicked to display preview
50 * information about the result before downloading.
51 * @param row The row of the result selected.
52 * @param col The column of the result selected.
53 */
54 void PQRWidget::molSelected(int row, int)
55 {
56 currentlySelectedMol = request->molSelected(row);
57 if (currentlySelectedMol == "N/A")
58 return;
59
60 ui->downloadButton->setEnabled(true);
61 }
62
63 /**
64 * @brief Called when PNG data is ready to be loaded
65 */
66 void PQRWidget::loadPNG(QByteArray& pngData)
67 {
68 QPixmap pixmap;
69 pixmap.loadFromData(pngData, "PNG");
70 pixmap = pixmap.scaled(300, 300);
71 ui->pngPreview->setPixmap(pixmap);
72 ui->pngPreview->show();
73 }
74
75 /**
76 * @brief Called when the download button is clicked to send a request to
77 * download molecule information from PQR.
78 */
79 void PQRWidget::downloadMol()
80 {
81 QString mol2url = currentlySelectedMol;
82 if (mol2url != "N/A" && mol2url != "") {
83 mol2url.remove(0, 3); // remove first 3 characters to map to PQR's url
84 QString url = "https://pqr.pitt.edu/api/mol/" + mol2url;
85 request->sendRequest(url, mol2url);
86 }
87 }
88
89 void PQRWidget::loadMolecule(QByteArray& molData, QString name)
90 {
91 plugin->setMoleculeData(molData, name);
92 }
93
94 } // namespace Avogadro::QtPlugins