Add iterations per cycle & optional sqrt optimization
This commit is contained in:
parent
e0178e27d2
commit
37234a44c9
3 changed files with 185 additions and 64 deletions
146
qml/Main.qml
146
qml/Main.qml
|
@ -15,55 +15,85 @@ ApplicationWindow {
|
|||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
spacing: 10
|
||||
spacing: 15
|
||||
|
||||
Text {
|
||||
text: "Enter a number to factorize:"
|
||||
font.pixelSize: 16
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: numberInput
|
||||
placeholderText: "Enter number"
|
||||
// NOTE: We can't use the IntValidator here, since it doesn't support 64-bit values (long long)
|
||||
GroupBox {
|
||||
title: "Input"
|
||||
Layout.fillWidth: true
|
||||
onTextChanged: {
|
||||
// If the number changes, reset
|
||||
factorizationController.reset();
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: 10
|
||||
ColumnLayout {
|
||||
spacing: 10
|
||||
|
||||
Button {
|
||||
text: {
|
||||
if (factorizationController.isPaused) {
|
||||
return "Resume";
|
||||
} else if (factorizationController.isRunning) {
|
||||
return "...";
|
||||
} else {
|
||||
return "Start";
|
||||
}
|
||||
TextField {
|
||||
id: numberInput
|
||||
placeholderText: "Enter a number"
|
||||
// NOTE: We can't use the IntValidator here, since it doesn't support 64-bit values (long long)
|
||||
Layout.fillWidth: true
|
||||
font.pixelSize: 16
|
||||
onTextChanged: factorizationController.reset()
|
||||
}
|
||||
Layout.fillWidth: true
|
||||
enabled: !factorizationController.isRunning
|
||||
onClicked: {
|
||||
if (factorizationController.isPaused) {
|
||||
factorizationController.resume();
|
||||
} else {
|
||||
factorizationController.start(parseInt(numberInput.text, 10));
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
Button {
|
||||
text: factorizationController.isPaused ? "Resume" : factorizationController.isRunning ? "..." : "Start"
|
||||
Layout.fillWidth: true
|
||||
enabled: !factorizationController.isRunning
|
||||
onClicked: {
|
||||
if (factorizationController.isPaused) {
|
||||
factorizationController.resume();
|
||||
} else {
|
||||
factorizationController.start(parseInt(numberInput.text, 10));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Pause"
|
||||
Layout.fillWidth: true
|
||||
enabled: factorizationController.isRunning
|
||||
onClicked: factorizationController.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Pause"
|
||||
Layout.fillWidth: true
|
||||
enabled: factorizationController.isRunning
|
||||
onClicked: factorizationController.stop()
|
||||
GroupBox {
|
||||
title: "Settings"
|
||||
Layout.fillWidth: true
|
||||
ColumnLayout {
|
||||
spacing: 10
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
Text {
|
||||
text: "Iterations per cycle:"
|
||||
Layout.alignment: Qt.AlignLeft
|
||||
}
|
||||
|
||||
Slider {
|
||||
id: iterationSlider
|
||||
Layout.fillWidth: true
|
||||
from: 1
|
||||
to: 100000
|
||||
stepSize: 1
|
||||
value: 1
|
||||
onValueChanged: factorizationController.iterationsPerCycle = value
|
||||
}
|
||||
|
||||
Text {
|
||||
text: iterationSlider.value.toFixed(0)
|
||||
font.bold: true
|
||||
Layout.alignment: Qt.AlignRight
|
||||
}
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
text: "Stop at sqrt(n)"
|
||||
checked: true
|
||||
onCheckedChanged: factorizationController.useSqrtOptimization = checked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,32 +104,34 @@ ApplicationWindow {
|
|||
value: factorizationController.progress
|
||||
}
|
||||
|
||||
Text {
|
||||
text: "Current Factor: " + factorizationController.currentFactor
|
||||
font.pixelSize: 14
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
GroupBox {
|
||||
title: "Current Status"
|
||||
Layout.fillWidth: true
|
||||
ColumnLayout {
|
||||
spacing: 5
|
||||
|
||||
Text {
|
||||
text: "Current Factor: " + factorizationController.currentFactor
|
||||
font.pixelSize: 14
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
text: "Factors Found:"
|
||||
font.pixelSize: 14
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
|
||||
ListView {
|
||||
GroupBox {
|
||||
title: "Factors Found"
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
model: factorizationController.factors
|
||||
delegate: Text {
|
||||
text: modelData
|
||||
|
||||
Text {
|
||||
text: factorizationController.factors.join(", ")
|
||||
font.pixelSize: 14
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
width: parent.width
|
||||
color: "black"
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
text: "Warning: This only shows factors below sqrt(num)"
|
||||
text: factorizationController.useSqrtOptimization ? "Note: Only factors up to sqrt(n) are shown." : "Note: Finding all factors (slower)."
|
||||
font.pixelSize: 12
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue