url as combobox with completion

This commit is contained in:
Marc Wäckerlin
2017-01-27 15:57:21 +00:00
parent f6518ea767
commit 62fefb3183
2 changed files with 49 additions and 28 deletions

View File

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

View File

@@ -33,15 +33,21 @@
<property name="text">
<string>URL:</string>
</property>
<property name="buddy">
<cstring>_url</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="_url">
<property name="text">
<string>https://</string>
<widget class="QComboBox" name="_url">
<property name="sizePolicy">
<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>
</widget>
</item>
@@ -752,7 +758,7 @@ this.dispatchEvent(evObj);</string>
<string>Revert to saved</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
<string>Ctrl+Shift+R</string>
</property>
</action>
<action name="_actionOpenSetupScript">
@@ -774,28 +780,11 @@ this.dispatchEvent(evObj);</string>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>_url</tabstop>
<tabstop>_load</tabstop>
<tabstop>_web</tabstop>
</tabstops>
<resources/>
<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>
<sender>_selector</sender>
<signal>returnPressed()</signal>
@@ -1084,5 +1073,21 @@ this.dispatchEvent(evObj);</string>
</hint>
</hints>
</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>
</ui>