url as combobox with completion

master
Marc Wäckerlin 7 years ago
parent f6518ea767
commit 62fefb3183
  1. 24
      src/testgui.hxx
  2. 53
      src/testgui.ui

@ -17,6 +17,7 @@
#include <QScrollBar> #include <QScrollBar>
#include <QFile> #include <QFile>
#include <QMessageBox> #include <QMessageBox>
#include <QCompleter>
#include <ui_testgui.hxx> #include <ui_testgui.hxx>
#include <stdexcept> #include <stdexcept>
#include <QNetworkReply> #include <QNetworkReply>
@ -49,8 +50,11 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
QSettings settings("mrw", "webtester"); QSettings settings("mrw", "webtester");
restoreGeometry(settings.value("geometry").toByteArray()); restoreGeometry(settings.value("geometry").toByteArray());
restoreState(settings.value("windowstate").toByteArray()); restoreState(settings.value("windowstate").toByteArray());
_url->completer()->setFilterMode(Qt::MatchContains);
_url->completer()->setCaseSensitivity(Qt::CaseInsensitive);
_url->completer()->setCompletionMode(QCompleter::PopupCompletion);
if (!url.isEmpty()) { if (!url.isEmpty()) {
_url->setText(url); storeUrl(url);
} }
TestWebPage* page(new TestWebPage(_web)); TestWebPage* page(new TestWebPage(_web));
_web->setPage(page); _web->setPage(page);
@ -70,8 +74,10 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
void on__load_clicked() { void on__load_clicked() {
enterText(true); enterText(true);
if (_record->isChecked()) if (_record->isChecked())
appendCommand("load "+map(_url->text())); appendCommand("load "+map(_url->currentText()));
_web->load(_url->text()); storeUrl(_url->currentText());
_webprogress->setFormat(_url->currentText());
_web->load(_url->currentText());
} }
void on__abort_clicked() { void on__abort_clicked() {
enterText(true); enterText(true);
@ -156,6 +162,9 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
_status->setCurrentIndex(STATUS_SUCCESS); _status->setCurrentIndex(STATUS_SUCCESS);
} catch (std::exception &x) { } catch (std::exception &x) {
_status->setCurrentIndex(STATUS_ERROR); _status->setCurrentIndex(STATUS_ERROR);
QMessageBox::critical(this, tr("Test Failed"), tr("Error [%1]: %2")
.arg(demangle(typeid(x).name()))
.arg(x.what()));
} }
_run->setEnabled(true); _run->setEnabled(true);
_record->setEnabled(true); _record->setEnabled(true);
@ -202,7 +211,8 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
//std::cout<<"titleChanged: "<<title.toStdString()<<std::endl; //std::cout<<"titleChanged: "<<title.toStdString()<<std::endl;
} }
void on__web_urlChanged(const QUrl& url) { void on__web_urlChanged(const QUrl& url) {
_url->setText(url.url()); _webprogress->setFormat(url.url());
storeUrl(url);
enterText(true); enterText(true);
if (_record->isChecked()) if (_record->isChecked())
appendCommand("expect "+map("urlChanged "+url.url())); appendCommand("expect "+map("urlChanged "+url.url()));
@ -415,6 +425,12 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
return false; return false;
} }
private: private:
void storeUrl(QUrl u) {
if (!_url->findText(u.url())) {
_url->addItem(u.url());
_url->setCurrentText(u.url());
}
}
void loadFile(QString name) { void loadFile(QString name) {
QFile file(name); QFile file(name);
try { try {

@ -33,15 +33,21 @@
<property name="text"> <property name="text">
<string>URL:</string> <string>URL:</string>
</property> </property>
<property name="buddy">
<cstring>_url</cstring>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="_url"> <widget class="QComboBox" name="_url">
<property name="text"> <property name="sizePolicy">
<string>https://</string> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertAtTop</enum>
</property> </property>
</widget> </widget>
</item> </item>
@ -752,7 +758,7 @@ this.dispatchEvent(evObj);</string>
<string>Revert to saved</string> <string>Revert to saved</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+R</string> <string>Ctrl+Shift+R</string>
</property> </property>
</action> </action>
<action name="_actionOpenSetupScript"> <action name="_actionOpenSetupScript">
@ -774,28 +780,11 @@ this.dispatchEvent(evObj);</string>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>_url</tabstop>
<tabstop>_load</tabstop> <tabstop>_load</tabstop>
<tabstop>_web</tabstop> <tabstop>_web</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections> <connections>
<connection>
<sender>_url</sender>
<signal>returnPressed()</signal>
<receiver>_load</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>493</x>
<y>343</y>
</hint>
<hint type="destinationlabel">
<x>580</x>
<y>344</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>_selector</sender> <sender>_selector</sender>
<signal>returnPressed()</signal> <signal>returnPressed()</signal>
@ -1084,5 +1073,21 @@ this.dispatchEvent(evObj);</string>
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>_url</sender>
<signal>activated(int)</signal>
<receiver>_load</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>277</x>
<y>315</y>
</hint>
<hint type="destinationlabel">
<x>549</x>
<y>315</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>

Loading…
Cancel
Save