initial commit
This commit is contained in:
@@ -16,5 +16,8 @@ bool cImportMouser::showSearch(QWidget* parent)
|
||||
{
|
||||
cSearchDialog* searchDialog = new cSearchDialog(parent);
|
||||
searchDialog->show();
|
||||
|
||||
// doSearchByKeyword("lm741");
|
||||
// doSearchByPartNumber("595-NE555P");
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,265 @@
|
||||
#include "csearchdialog.h"
|
||||
#include "ui_csearchdialog.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QUrl>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include <QEventLoop>
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
|
||||
cSearchDialog::cSearchDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::cSearchDialog)
|
||||
ui(new Ui::cSearchDialog),
|
||||
m_resultListItemModel(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_resultListItemModel = new QStandardItemModel(ui->m_resultList);
|
||||
ui->m_resultList->setModel(m_resultListItemModel);
|
||||
|
||||
connect(ui->m_search, &QPushButton::clicked, this, &cSearchDialog::searchClicked);
|
||||
}
|
||||
|
||||
cSearchDialog::~cSearchDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void cSearchDialog::searchClicked()
|
||||
{
|
||||
QString searchText = ui->m_searchText->text();
|
||||
bool keywordSearch = ui->m_searchByKeyword->isChecked();
|
||||
|
||||
if(searchText.isEmpty())
|
||||
return;
|
||||
|
||||
m_resultListItemModel->clear();
|
||||
|
||||
QStringList header;
|
||||
header << "MouserPartNumber" << "Manufacturer" << "ManufacturerPartNumber" << "description" << "Category";
|
||||
m_resultListItemModel->setHorizontalHeaderLabels(header);
|
||||
|
||||
if(keywordSearch)
|
||||
doSearchByKeyword(searchText);
|
||||
else
|
||||
doSearchByPartNumber(searchText);
|
||||
}
|
||||
|
||||
bool cSearchDialog::doSearchByKeyword(const QString& keyword)
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
QJsonObject keywordRequest;
|
||||
keywordRequest["keyword"] = keyword;
|
||||
keywordRequest["records"] = 0;
|
||||
keywordRequest["startingRecord"] = 0;
|
||||
keywordRequest["searchOptions"] = "string";
|
||||
keywordRequest["searchWithYourSignUpLanguage"] = "string";
|
||||
|
||||
QJsonObject obj;
|
||||
obj["SearchByKeywordRequest"] = keywordRequest;
|
||||
|
||||
QJsonDocument doc(obj);
|
||||
QByteArray data = doc.toJson(QJsonDocument::Compact);
|
||||
|
||||
if(!doSearch("/search/keyword", data))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool cSearchDialog::doSearchByPartNumber(const QString& partNumber)
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
QJsonObject keywordRequest;
|
||||
keywordRequest["mouserPartNumber"] = partNumber;
|
||||
keywordRequest["searchOptions"] = "string";
|
||||
|
||||
QJsonObject obj;
|
||||
obj["SearchByPartRequest"] = keywordRequest;
|
||||
|
||||
QJsonDocument doc(obj);
|
||||
QByteArray data = doc.toJson(QJsonDocument::Compact);
|
||||
|
||||
if(!doSearch("/search/partnumber", data))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool cSearchDialog::doSearch(const QString& function, const QByteArray& data)
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
QString requestUrl = QString(settings.value("plugins/importMouser/url", "").toString()) + "/v" + settings.value("plugins/importMouser/api_version", "").toString() + function + "?apiKey=" + settings.value("plugins/importMouser/api_key", "").toString();
|
||||
QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);
|
||||
const QUrl url(requestUrl);
|
||||
QNetworkRequest request(url);
|
||||
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
QNetworkReply* reply = networkAccessManager->post(request, data);
|
||||
QEventLoop loop;
|
||||
|
||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
|
||||
if(reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
QString strReply = (QString)reply->readAll();
|
||||
|
||||
QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
|
||||
QJsonObject jsonObj = jsonResponse.object();
|
||||
QJsonObject searchResults = jsonObj["SearchResults"].toObject();
|
||||
qint32 numberOfResults = searchResults["NumberOfResult"].toInt();
|
||||
|
||||
if(numberOfResults)
|
||||
{
|
||||
QJsonArray parts = searchResults["Parts"].toArray();
|
||||
|
||||
for(int z = 0;z < parts.count();z++)
|
||||
{
|
||||
QJsonObject part = parts[z].toObject();
|
||||
QString availability = part["availability"].toString();
|
||||
QString dataSheetUrl = part["DataSheetUrl"].toString();
|
||||
QString description = part["Description"].toString();
|
||||
QString factoryStock = part["FactoryStock"].toString();
|
||||
QString imagePath = part["ImagePath"].toString();
|
||||
QString category = part["Category"].toString();
|
||||
QString leadTime = part["LeadTime"].toString();
|
||||
QString lifecycleStatus = part["LifecycleStatus"].toString();
|
||||
QString manufacturer = part["Manufacturer"].toString();
|
||||
QString manufacturerPartNumber = part["ManufacturerPartNumber"].toString();
|
||||
QString min = part["Min"].toString();
|
||||
QString mult = part["Mult"].toString();
|
||||
QString mouserPartNumber = part["MouserPartNumber"].toString();
|
||||
QString productDetailUrl = part["ProductDetailUrl"].toString();
|
||||
QString reeling = part["Reeling"].toString();
|
||||
QString rohsStatus = part["ROHSStatus"].toString();
|
||||
QString suggestedReplacement = part["SuggestedReplacement"].toString();
|
||||
qint32 multiSimBlue = part["MultiSimBlue"].toInt();
|
||||
QString isDiscontinued = part["IsDiscontinued"].toString();
|
||||
QString rtm = part["RTM"].toString();
|
||||
QString mouserProductCategory = part["MouserProductCategory"].toString();
|
||||
QString ipcCode = part["IPCCode"].toString();
|
||||
QString sField = part["SField"].toString();
|
||||
QString vNum = part["VNum"].toString();
|
||||
QString actualMfrName = part["ActualMfrName"].toString();
|
||||
QString availableOnOrder = part["AvailableOnOrder"].toString();
|
||||
QString availabilityInStock = part["AvailabilityInStock"].toString();
|
||||
QString salesMaximumOrderQty = part["SalesMaximumOrderQty"].toString();
|
||||
QString restrictionMessage = part["RestrictionMessage"].toString();
|
||||
QString pid = part["PID"].toString();
|
||||
|
||||
QJsonArray ProductAttributes = part["ProductAttributes"].toArray();
|
||||
QHash<QString, QString> productAttributes;
|
||||
for(int x = 0;x < ProductAttributes.count();x++)
|
||||
{
|
||||
QJsonObject attribute = ProductAttributes[x].toObject();
|
||||
productAttributes.insert(attribute["AttributeName"].toString(), attribute["AttributeValue"].toString());
|
||||
}
|
||||
|
||||
QJsonArray AvailabilityOnOrder = part["AvailabilityOnOrder"].toArray();
|
||||
QHash<QString, qint32> availabilityOnOrder;
|
||||
for(int x = 0;x < AvailabilityOnOrder.count();x++)
|
||||
{
|
||||
QJsonObject availability = AvailabilityOnOrder[x].toObject();
|
||||
availabilityOnOrder.insert(availability["Date"].toString(), availability["Quantity"].toInt());
|
||||
}
|
||||
|
||||
QJsonArray ProductCompliance = part["ProductCompliance"].toArray();
|
||||
QHash<QString, QString> productCompliance;
|
||||
for(int x = 0;x < ProductCompliance.count();x++)
|
||||
{
|
||||
QJsonObject compliance = ProductCompliance[x].toObject();
|
||||
productCompliance.insert(compliance["ComplianceName"].toString(), compliance["ComplianceValue"].toString());
|
||||
}
|
||||
|
||||
/*
|
||||
"PriceBreaks": [
|
||||
{
|
||||
"Quantity": 0,
|
||||
"Price": "string",
|
||||
"Currency": "string"
|
||||
}
|
||||
],
|
||||
"AlternatePackagings": [
|
||||
{
|
||||
"APMfrPN": "string"
|
||||
}
|
||||
],
|
||||
"UnitWeightKg": {
|
||||
"UnitWeight": 0
|
||||
},
|
||||
"StandardCost": {
|
||||
"Standardcost": 0
|
||||
},
|
||||
"InfoMessages": [
|
||||
"string"
|
||||
],
|
||||
*/
|
||||
|
||||
QStandardItem* mouserPartNumberItem = new QStandardItem(mouserPartNumber);
|
||||
QStandardItem* manufacturerItem = new QStandardItem(manufacturer);
|
||||
QStandardItem* manufacturerPartNumberItem = new QStandardItem(manufacturerPartNumber);
|
||||
QStandardItem* descriptionItem = new QStandardItem(description);
|
||||
QStandardItem* categoryItem = new QStandardItem(category);
|
||||
QIcon icon = iconFromUrl(imagePath);
|
||||
|
||||
if(!icon.isNull())
|
||||
mouserPartNumberItem->setIcon(icon);
|
||||
|
||||
m_resultListItemModel->appendRow(QList<QStandardItem*>() << mouserPartNumberItem << manufacturerItem << manufacturerPartNumberItem << descriptionItem << categoryItem);
|
||||
}
|
||||
|
||||
for(int i = 0;i < m_resultListItemModel->columnCount();i++)
|
||||
ui->m_resultList->resizeColumnToContents(i);
|
||||
}
|
||||
|
||||
delete reply;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << reply->errorString();
|
||||
|
||||
delete reply;
|
||||
}
|
||||
|
||||
delete networkAccessManager;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
QIcon cSearchDialog::iconFromUrl(const QString& iconURL)
|
||||
{
|
||||
QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);
|
||||
const QUrl url(iconURL);
|
||||
QNetworkRequest request(url);
|
||||
|
||||
QNetworkReply* reply = networkAccessManager->get(request);
|
||||
QEventLoop loop;
|
||||
|
||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
|
||||
if(reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
QByteArray data = reply->readAll();
|
||||
QPixmap pixmap;
|
||||
pixmap.loadFromData(data);
|
||||
QIcon icon(pixmap);
|
||||
return(icon);
|
||||
}
|
||||
return(QIcon());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
#ifndef CSEARCHDIALOG_H
|
||||
#define CSEARCHDIALOG_H
|
||||
|
||||
|
||||
#include <QStandardItemModel>
|
||||
#include <QDialog>
|
||||
#include <QIcon>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class cSearchDialog;
|
||||
@@ -11,12 +15,22 @@ class cSearchDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit cSearchDialog(QWidget *parent = nullptr);
|
||||
public:
|
||||
explicit cSearchDialog(QWidget *parent = nullptr);
|
||||
~cSearchDialog();
|
||||
|
||||
bool doSearchByKeyword(const QString& keyword);
|
||||
bool doSearchByPartNumber(const QString& partNumber);
|
||||
|
||||
private:
|
||||
Ui::cSearchDialog *ui;
|
||||
Ui::cSearchDialog* ui;
|
||||
QStandardItemModel* m_resultListItemModel;
|
||||
|
||||
bool doSearch(const QString& function, const QByteArray& data);
|
||||
QIcon iconFromUrl(const QString& iconURL);
|
||||
|
||||
private slots:
|
||||
void searchClicked();
|
||||
};
|
||||
|
||||
#endif // CSEARCHDIALOG_H
|
||||
|
||||
+103
-36
@@ -6,52 +6,119 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>332</height>
|
||||
<width>509</width>
|
||||
<height>426</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>280</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>131</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="importMouser.qrc">:/logo/mouserSmall.jpg</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="importMouser.qrc">:/logo/mouserSmall.jpg</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="m_searchByKeyword">
|
||||
<property name="text">
|
||||
<string>search by keyword</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="m_searchByMouserID">
|
||||
<property name="text">
|
||||
<string>search by mouser id</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="m_searchText"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="m_search">
|
||||
<property name="text">
|
||||
<string>Search</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeView" name="m_resultList">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="m_buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="importMouser.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<sender>m_buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>cSearchDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
@@ -67,7 +134,7 @@
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<sender>m_buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>cSearchDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
TEMPLATE = lib
|
||||
CONFIG += plugin
|
||||
QT += widgets
|
||||
QT += widgets network
|
||||
INCLUDEPATH += ../inventryParts
|
||||
HEADERS = \
|
||||
cimportmouser.h \
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <QDir>
|
||||
#include <QPluginLoader>
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
@@ -13,6 +15,11 @@ cMainWindow::cMainWindow(QWidget *parent) :
|
||||
{
|
||||
createGUI();
|
||||
|
||||
QSettings settings;
|
||||
QString url = settings.value("plugins/importMouser/url", "").toString();
|
||||
QString apiVersion = settings.value("plugins/importMouser/api_version", "").toString();
|
||||
QString apiKey = settings.value("plugins/importMouser/api_key", "").toString();
|
||||
|
||||
if(!loadPlugin())
|
||||
{
|
||||
QMessageBox::information(this, "Error", "Could not load the plugin");
|
||||
@@ -33,7 +40,6 @@ bool cMainWindow::loadPlugin()
|
||||
{
|
||||
QDir pluginsDir(QCoreApplication::applicationDirPath());
|
||||
|
||||
qDebug() << pluginsDir.absolutePath();
|
||||
#if defined(Q_OS_WIN)
|
||||
if(pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
|
||||
{
|
||||
@@ -74,7 +80,6 @@ void cMainWindow::on_m_test_clicked()
|
||||
{
|
||||
for(int i = 0;i < m_importInterfaceList.count();i++)
|
||||
{
|
||||
qDebug() << m_importInterfaceList.at(i)->pluginName();
|
||||
if(!m_importInterfaceList.at(i)->pluginName().compare("Import Mouser", Qt::CaseSensitive))
|
||||
{
|
||||
m_importInterfaceList.at(i)->showSearch(this);
|
||||
|
||||
@@ -6,8 +6,13 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
cMainWindow w;
|
||||
QApplication a(argc, argv);
|
||||
|
||||
QCoreApplication::setOrganizationName("WIN-DESIGN");
|
||||
QCoreApplication::setOrganizationDomain("windesign.at");
|
||||
QCoreApplication::setApplicationName("inventryParts");
|
||||
|
||||
cMainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user