mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-29 03:09:14 -05:00
Merge pull request #1697 from srcejon/fix_1692
Sampling Device Dialog. Only update widgets from UI thread.
This commit is contained in:
commit
fe56c1c11c
@ -31,15 +31,18 @@ SamplingDeviceDialog::SamplingDeviceDialog(int deviceType, QWidget* parent) :
|
|||||||
ui(new Ui::SamplingDeviceDialog),
|
ui(new Ui::SamplingDeviceDialog),
|
||||||
m_deviceType(deviceType),
|
m_deviceType(deviceType),
|
||||||
m_selectedDeviceIndex(-1),
|
m_selectedDeviceIndex(-1),
|
||||||
m_hasChanged(false)
|
m_hasChanged(false),
|
||||||
|
m_progressDialog(nullptr)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
// Don't automatically call on_refreshDevices_clicked(), some drivers can be slow to enumerate
|
// Don't automatically call on_refreshDevices_clicked(), some drivers can be slow to enumerate
|
||||||
displayDevices();
|
displayDevices();
|
||||||
|
connect(DeviceEnumerator::instance(), &DeviceEnumerator::enumeratingDevices, this, &SamplingDeviceDialog::enumeratingDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
SamplingDeviceDialog::~SamplingDeviceDialog()
|
SamplingDeviceDialog::~SamplingDeviceDialog()
|
||||||
{
|
{
|
||||||
|
disconnect(DeviceEnumerator::instance(), &DeviceEnumerator::enumeratingDevices, this, &SamplingDeviceDialog::enumeratingDevice);
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,18 +90,18 @@ void SamplingDeviceDialog::on_deviceSelect_currentIndexChanged(int index)
|
|||||||
|
|
||||||
void SamplingDeviceDialog::on_refreshDevices_clicked()
|
void SamplingDeviceDialog::on_refreshDevices_clicked()
|
||||||
{
|
{
|
||||||
QProgressDialog *progressDialog = new QProgressDialog("Enumerating devices", "", 0, 0, this);
|
m_progressDialog = new QProgressDialog("Enumerating devices", "", 0, 0, this);
|
||||||
progressDialog->setWindowModality(Qt::WindowModal);
|
m_progressDialog->setWindowModality(Qt::WindowModal);
|
||||||
progressDialog->setCancelButton(nullptr);
|
m_progressDialog->setCancelButton(nullptr);
|
||||||
progressDialog->setWindowFlag(Qt::WindowCloseButtonHint, false);
|
m_progressDialog->setWindowFlag(Qt::WindowCloseButtonHint, false);
|
||||||
progressDialog->show();
|
m_progressDialog->show();
|
||||||
SamplingDeviceDialogWorker *worker = new SamplingDeviceDialogWorker(m_deviceType, progressDialog);
|
SamplingDeviceDialogWorker *worker = new SamplingDeviceDialogWorker(m_deviceType);
|
||||||
QThread *thread = new QThread();
|
QThread *thread = new QThread();
|
||||||
worker->moveToThread(thread);
|
worker->moveToThread(thread);
|
||||||
connect(thread, &QThread::started, worker, &SamplingDeviceDialogWorker::enumerateDevices);
|
connect(thread, &QThread::started, worker, &SamplingDeviceDialogWorker::enumerateDevices);
|
||||||
connect(worker, &SamplingDeviceDialogWorker::finishedWork, thread, &QThread::quit);
|
connect(worker, &SamplingDeviceDialogWorker::finishedWork, thread, &QThread::quit);
|
||||||
connect(worker, &SamplingDeviceDialogWorker::finishedWork, progressDialog, &QProgressDialog::close);
|
connect(worker, &SamplingDeviceDialogWorker::finishedWork, m_progressDialog, &QProgressDialog::close);
|
||||||
connect(worker, &SamplingDeviceDialogWorker::finishedWork, progressDialog, &QProgressDialog::deleteLater);
|
connect(worker, &SamplingDeviceDialogWorker::finishedWork, m_progressDialog, &QProgressDialog::deleteLater);
|
||||||
connect(worker, &SamplingDeviceDialogWorker::finishedWork, this, &SamplingDeviceDialog::displayDevices);
|
connect(worker, &SamplingDeviceDialogWorker::finishedWork, this, &SamplingDeviceDialog::displayDevices);
|
||||||
connect(worker, &SamplingDeviceDialogWorker::finishedWork, worker, &SamplingDeviceDialog::deleteLater);
|
connect(worker, &SamplingDeviceDialogWorker::finishedWork, worker, &SamplingDeviceDialog::deleteLater);
|
||||||
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
||||||
@ -117,10 +120,16 @@ void SamplingDeviceDialog::reject()
|
|||||||
QDialog::reject();
|
QDialog::reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SamplingDeviceDialog::enumeratingDevice(const QString &deviceId)
|
||||||
|
{
|
||||||
|
if (m_progressDialog) {
|
||||||
|
m_progressDialog->setLabelText("Enumerating " + deviceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SamplingDeviceDialogWorker::enumerateDevices()
|
void SamplingDeviceDialogWorker::enumerateDevices()
|
||||||
{
|
{
|
||||||
PluginManager *pluginManager = MainCore::instance()->getPluginManager();
|
PluginManager *pluginManager = MainCore::instance()->getPluginManager();
|
||||||
connect(DeviceEnumerator::instance(), &DeviceEnumerator::enumeratingDevices, this, &SamplingDeviceDialogWorker::enumeratingDevices);
|
|
||||||
if (m_deviceType == 0) {
|
if (m_deviceType == 0) {
|
||||||
DeviceEnumerator::instance()->enumerateRxDevices(pluginManager);
|
DeviceEnumerator::instance()->enumerateRxDevices(pluginManager);
|
||||||
} else if (m_deviceType == 1) {
|
} else if (m_deviceType == 1) {
|
||||||
@ -130,9 +139,3 @@ void SamplingDeviceDialogWorker::enumerateDevices()
|
|||||||
}
|
}
|
||||||
emit finishedWork();
|
emit finishedWork();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SamplingDeviceDialogWorker::enumeratingDevices(const QString &deviceId)
|
|
||||||
{
|
|
||||||
m_progressDialog->setLabelText("Enumerating " + deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -37,9 +37,8 @@ class SDRGUI_API SamplingDeviceDialogWorker : public QObject {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SamplingDeviceDialogWorker(int deviceType, QProgressDialog *progressDialog) :
|
SamplingDeviceDialogWorker(int deviceType) :
|
||||||
m_deviceType(deviceType),
|
m_deviceType(deviceType)
|
||||||
m_progressDialog(progressDialog)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void enumerateDevices();
|
void enumerateDevices();
|
||||||
@ -48,11 +47,9 @@ signals:
|
|||||||
void finishedWork();
|
void finishedWork();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void enumeratingDevices(const QString &deviceId);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_deviceType;
|
int m_deviceType;
|
||||||
QProgressDialog *m_progressDialog;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SDRGUI_API SamplingDeviceDialog : public QDialog {
|
class SDRGUI_API SamplingDeviceDialog : public QDialog {
|
||||||
@ -73,6 +70,7 @@ private:
|
|||||||
int m_selectedDeviceIndex;
|
int m_selectedDeviceIndex;
|
||||||
std::vector<int> m_deviceIndexes;
|
std::vector<int> m_deviceIndexes;
|
||||||
bool m_hasChanged;
|
bool m_hasChanged;
|
||||||
|
QProgressDialog *m_progressDialog;
|
||||||
|
|
||||||
void displayDevices();
|
void displayDevices();
|
||||||
|
|
||||||
@ -81,6 +79,7 @@ private slots:
|
|||||||
void on_refreshDevices_clicked();
|
void on_refreshDevices_clicked();
|
||||||
void accept();
|
void accept();
|
||||||
void reject();
|
void reject();
|
||||||
|
void enumeratingDevice(const QString &deviceId);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SDRGUI_GUI_SAMPLINGDEVICEDIALOG_H_ */
|
#endif /* SDRGUI_GUI_SAMPLINGDEVICEDIALOG_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user