X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fwidgets%2Fsweeptimingwidget.cpp;h=12f5969eb707c9997c212e1d39f838541c1f5588;hb=58cd5b584f5bcb19d7c9bd28391c53dd2488fc59;hp=ec404c36c96f4f251c9dcc9e5034720c907ff231;hpb=2ad82c2e40b6865481733913a2c32735602f63c4;p=pulseview.git
diff --git a/pv/widgets/sweeptimingwidget.cpp b/pv/widgets/sweeptimingwidget.cpp
index ec404c3..12f5969 100644
--- a/pv/widgets/sweeptimingwidget.cpp
+++ b/pv/widgets/sweeptimingwidget.cpp
@@ -14,18 +14,15 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see .
*/
#include "sweeptimingwidget.hpp"
+#include
#include
-
#include
-#include
-
#include
using std::abs;
@@ -50,6 +47,9 @@ SweepTimingWidget::SweepTimingWidget(const char *suffix,
connect(&list_, SIGNAL(currentIndexChanged(int)),
this, SIGNAL(value_changed()));
+ connect(&list_, SIGNAL(editTextChanged(const QString&)),
+ this, SIGNAL(value_changed()));
+
connect(&value_, SIGNAL(editingFinished()),
this, SIGNAL(value_changed()));
@@ -61,6 +61,11 @@ SweepTimingWidget::SweepTimingWidget(const char *suffix,
show_none();
}
+void SweepTimingWidget::allow_user_entered_values(bool value)
+{
+ list_.setEditable(value);
+}
+
void SweepTimingWidget::show_none()
{
value_type_ = None;
@@ -90,8 +95,7 @@ void SweepTimingWidget::show_list(const uint64_t *vals, size_t count)
list_.clear();
for (size_t i = 0; i < count; i++) {
char *const s = sr_si_string_u64(vals[i], suffix_);
- list_.addItem(QString::fromUtf8(s),
- qVariantFromValue(vals[i]));
+ list_.addItem(QString::fromUtf8(s), qVariantFromValue(vals[i]));
g_free(s);
}
@@ -141,23 +145,25 @@ void SweepTimingWidget::show_125_list(uint64_t min, uint64_t max)
uint64_t SweepTimingWidget::value() const
{
- switch(value_type_) {
+ switch (value_type_) {
case None:
return 0;
-
case MinMaxStep:
return (uint64_t)value_.value();
-
case List:
{
+ if (list_.isEditable()) {
+ uint64_t value;
+ sr_parse_sizestring(list_.currentText().toUtf8().data(), &value);
+ return value;
+ }
+
const int index = list_.currentIndex();
- return (index >= 0) ? list_.itemData(
- index).value() : 0;
+ return (index >= 0) ? list_.itemData(index).value() : 0;
}
-
default:
// Unexpected value type
- assert(0);
+ assert(false);
return 0;
}
}
@@ -166,20 +172,26 @@ void SweepTimingWidget::set_value(uint64_t value)
{
value_.setValue(value);
- int best_match = list_.count() - 1;
- int64_t best_variance = INT64_MAX;
-
- for (int i = 0; i < list_.count(); i++) {
- const int64_t this_variance = abs(
- (int64_t)value - list_.itemData(i).value());
- if (this_variance < best_variance) {
- best_variance = this_variance;
- best_match = i;
+ if (list_.isEditable()) {
+ char *const s = sr_si_string_u64(value, suffix_);
+ list_.lineEdit()->setText(QString::fromUtf8(s));
+ g_free(s);
+ } else {
+ int best_match = list_.count() - 1;
+ int64_t best_variance = INT64_MAX;
+
+ for (int i = 0; i < list_.count(); i++) {
+ const int64_t this_variance = abs(
+ (int64_t)value - list_.itemData(i).value());
+ if (this_variance < best_variance) {
+ best_variance = this_variance;
+ best_match = i;
+ }
}
- }
- list_.setCurrentIndex(best_match);
+ list_.setCurrentIndex(best_match);
+ }
}
-} // widgets
-} // pv
+} // namespace widgets
+} // namespace pv