Browse Source

Configuration widget for serially connected scales.

Neal Wilson 11 years ago
parent
commit
a2f385446c
2 changed files with 130 additions and 1 deletions
  1. 129
    1
      src/scales.w
  2. 1
    0
      src/typica.w

+ 129
- 1
src/scales.w View File

@@ -324,4 +324,132 @@ QScriptValue constructSerialScale(QScriptContext *context, QScriptEngine *engine
324 324
 	return object;
325 325
 }
326 326
 
327
-@ While the |SerialScale| class will always 
327
+@ In order to allow configuration of scales from within \pn{}, a configuration
328
+widget must be provided.
329
+
330
+@<Class declarations@>=
331
+class SerialScaleConfWidget : public BasicDeviceConfigurationWidget
332
+{
333
+	Q_OBJECT
334
+	public:
335
+		Q_INVOKABLE SerialScaleConfWidget(DeviceTreeModel *model,
336
+		                                  const QModelIndex &index);
337
+	private slots:
338
+		void updatePort(const QString &newPort);
339
+		void updateBaudRate(const QString &newRate);
340
+		void updateParity(const QString &newParity);
341
+		void updateFlowControl(const QString &newFlow);
342
+		void updateStopBits(const QString &newStopBits);
343
+};
344
+
345
+@ This is very similar to other configuration widgets.
346
+
347
+@<SerialScaleConfWidget implementation@>=
348
+SerialScaleConfWidget::SerialScaleConfWidget(DeviceTreeModel *model,
349
+                                             const QModelIndex &index)
350
+: BasicDeviceConfigurationWidget(model, index)
351
+{
352
+	QFormLayout *layout = new QFormLayout;
353
+	PortSelector *port = new PortSelector;
354
+	layout->addRow(tr("Port:"), port);
355
+	connect(port, SIGNAL(currentIndexChanged(QString)),
356
+	        this, SLOT(updatePort(QString)));
357
+	connect(port, SIGNAL(editTextChanged(QString)),
358
+	        this, SLOT(updatePort(QString)));
359
+	BaudSelector *rate = new BaudSelector;
360
+	layout->addRow(tr("Baud:"), rate);
361
+	connect(rate, SIGNAL(currentIndexChanged(QString)),
362
+	        this, SLOT(updateBaudRate(QString)));
363
+	ParitySelector *parity = new ParitySelector;
364
+	layout->addRow(tr("Parity:"), parity);
365
+	connect(parity, SIGNAL(currentIndexChanged(QString)),
366
+	        this, SLOT(updateParity(QString)));
367
+	FlowSelector *flow = new FlowSelector;
368
+	layout->addRow(tr("Flow Control:"), flow);
369
+	connect(flow, SIGNAL(currentIndexChanged(QString)),
370
+	        this, SLOT(updateFlowControl(QString)));
371
+	StopSelector *stop = new StopSelector;
372
+	layout->addRow(tr("Stop Bits:"), stop);
373
+	connect(stop, SIGNAL(currentIndexChanged(QString)),
374
+	        this, SLOT(updateStopBits(QString)));
375
+	@<Get device configuration data for current node@>@;
376
+	for(int i = 0; i < configData.size(); i++)
377
+	{
378
+		node = configData.at(i).toElement();
379
+		if(node.attribute("name") == "port")
380
+		{
381
+			int j = port->findText(node.attribute("value"));
382
+			if(j >= 0)
383
+			{
384
+				port->setCurrentIndex(j);
385
+			}
386
+			else
387
+			{
388
+				port->insertItem(0, node.attribute("value"));
389
+				port->setCurrentIndex(0);
390
+			}
391
+		}
392
+		else if(node.attribute("name") == "baudrate")
393
+		{
394
+			rate->setCurrentIndex(rate->findText(node.attribute("value")));
395
+		}
396
+		else if(node.attribute("name") == "parity")
397
+		{
398
+			parity->setCurrentIndex(parity->findText(node.attribute("value")));
399
+		}
400
+		else if(node.attribute("name") == "flowcontrol")
401
+		{
402
+			flow->setCurrentIndex(flow->findText(node.attribute("value")));
403
+		}
404
+		else if(node.attribute("name") == "stopbits")
405
+		{
406
+			stop->setCurrentIndex(stop->findText(node.attribute("value")));
407
+		}
408
+	}
409
+	updatePort(port->currentText());
410
+	updateBaudRate(rate->currentText());
411
+	updateParity(parity->currentText());
412
+	updateFlowControl(flow->currentText());
413
+	updateStopBits(stop->currentText());
414
+	setLayout(layout);
415
+}
416
+
417
+@ Update methods are the same as were used in |ModbusRtuPortConfWidget|.
418
+
419
+@<SerialScaleConfWidget implementation@>=
420
+void SerialScaleConfWidget::updatePort(const QString &newPort)
421
+{
422
+	updateAttribute("port", newPort);
423
+}
424
+
425
+void SerialScaleConfWidget::updateBaudRate(const QString &newRate)
426
+{
427
+	updateAttribute("baudrate", newRate);
428
+}
429
+
430
+void SerialScaleConfWidget::updateParity(const QString &newParity)
431
+{
432
+	updateAttribute("parity", newParity);
433
+}
434
+
435
+void SerialScaleConfWidget::updateFlowControl(const QString &newFlow)
436
+{
437
+	updateAttribute("flowcontrol", newFlow);
438
+}
439
+
440
+void SerialScaleConfWidget::updateStopBits(const QString &newStopBits)
441
+{
442
+	updateAttribute("stopbits", newStopBits);
443
+}
444
+
445
+@ The configuration widget is registered with the configuration system.
446
+
447
+@<Register device configuration widgets@>=
448
+app.registerDeviceConfigurationWidget("scale", SerialScaleConfWidget::staticMetaObject);
449
+
450
+@ A |NodeInserter| is also added.
451
+
452
+@<Register top level device configuration nodes@>=
453
+inserter = new NodeInserter(tr("Serial Scale"), tr("Scale"), "scale", NULL);
454
+topLevelNodeInserters.append(inserter);
455
+

+ 1
- 0
src/typica.w View File

@@ -839,6 +839,7 @@ generated file empty.
839 839
 @<SettingsWindow implementation@>@/
840 840
 @<GraphSettingsWidget implementation@>@/
841 841
 @<DataqSdkDeviceConfWidget implementation@>@/
842
+@<SerialScaleConfWidget implementation@>@/
842 843
 
843 844
 @ A few headers are required for various parts of \pn{}. These allow the use of
844 845
 various Qt modules.

Loading…
Cancel
Save