- enhancement: edit problem properties

- enhancement: show problem description in the problem name lable's tooltip
This commit is contained in:
royqh1979@gmail.com 2021-11-04 09:07:06 +08:00
parent fcb8151493
commit c64c4916ac
12 changed files with 531 additions and 244 deletions

View File

@ -17,6 +17,8 @@ Version 0.7.8
- enhancement: can set the color for the current line's number in the gutter - enhancement: can set the color for the current line's number in the gutter
- all predefined color schemes updated. - all predefined color schemes updated.
- enhancement: check syntax/parse symbols when modifed and cursor's line changed. - enhancement: check syntax/parse symbols when modifed and cursor's line changed.
- enhancement: edit problem properties
- enhancement: show problem description in the problem name lable's tooltip
Version 0.7.7 Version 0.7.7
- enhancement: Problem Set - enhancement: Problem Set

View File

@ -126,6 +126,7 @@ SOURCES += \
widgets/labelwithmenu.cpp \ widgets/labelwithmenu.cpp \
widgets/macroinfomodel.cpp \ widgets/macroinfomodel.cpp \
widgets/newprojectdialog.cpp \ widgets/newprojectdialog.cpp \
widgets/ojproblempropertywidget.cpp \
widgets/ojproblemsetmodel.cpp \ widgets/ojproblemsetmodel.cpp \
widgets/qconsole.cpp \ widgets/qconsole.cpp \
widgets/qpatchedcombobox.cpp \ widgets/qpatchedcombobox.cpp \
@ -247,6 +248,7 @@ HEADERS += \
widgets/labelwithmenu.h \ widgets/labelwithmenu.h \
widgets/macroinfomodel.h \ widgets/macroinfomodel.h \
widgets/newprojectdialog.h \ widgets/newprojectdialog.h \
widgets/ojproblempropertywidget.h \
widgets/ojproblemsetmodel.h \ widgets/ojproblemsetmodel.h \
widgets/qconsole.h \ widgets/qconsole.h \
widgets/qpatchedcombobox.h \ widgets/qpatchedcombobox.h \
@ -294,6 +296,7 @@ FORMS += \
widgets/custommakefileinfodialog.ui \ widgets/custommakefileinfodialog.ui \
widgets/filepropertiesdialog.ui \ widgets/filepropertiesdialog.ui \
widgets/newprojectdialog.ui \ widgets/newprojectdialog.ui \
widgets/ojproblempropertywidget.ui \
widgets/searchdialog.ui widgets/searchdialog.ui
TRANSLATIONS += \ TRANSLATIONS += \

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,7 @@
#include "thememanager.h" #include "thememanager.h"
#include "widgets/darkfusionstyle.h" #include "widgets/darkfusionstyle.h"
#include "problems/problemcasevalidator.h" #include "problems/problemcasevalidator.h"
#include "widgets/ojproblempropertywidget.h"
#include <QCloseEvent> #include <QCloseEvent>
#include <QComboBox> #include <QComboBox>
@ -569,13 +570,13 @@ void MainWindow::applySettings()
if (pSettings->executor().enableProblemSet()) { if (pSettings->executor().enableProblemSet()) {
if (pSettings->executor().enableCompetitiveCompanion()) { if (pSettings->executor().enableCompetitiveCompanion()) {
if (!mTcpServer.listen(QHostAddress::LocalHost,pSettings->executor().competivieCompanionPort())) { if (!mTcpServer.listen(QHostAddress::LocalHost,pSettings->executor().competivieCompanionPort())) {
QMessageBox::critical(nullptr, // QMessageBox::critical(nullptr,
tr("Listen failed"), // tr("Listen failed"),
tr("Can't listen to port %1 form Competitve Companion.").arg(10045) // tr("Can't listen to port %1 form Competitve Companion.").arg(10045)
+ "<BR/>" // + "<BR/>"
+tr("You can turn off competitive companion support in the Problem Set options.") // +tr("You can turn off competitive companion support in the Problem Set options.")
+ "<BR/>" // + "<BR/>"
+tr("Or You can choose a different port number and try again.")); // +tr("Or You can choose a different port number and try again."));
} }
} }
if (idxProblem<0) if (idxProblem<0)
@ -1799,6 +1800,35 @@ void MainWindow::newEditor()
void MainWindow::buildContextMenus() void MainWindow::buildContextMenus()
{ {
//context menu signal for the problem list view
ui->lstProblemSet->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->lstProblemSet, &QWidget::customContextMenuRequested,
this, &MainWindow::onLstProblemSetContextMenu);
mProblem_Properties = createActionFor(
tr("Properties..."),
ui->lstProblemSet
);
connect(mProblem_Properties, &QAction::triggered,
[this]() {
QModelIndex idx = ui->lstProblemSet->currentIndex();
if (!idx.isValid())
return;
POJProblem problem=mOJProblemSetModel.problem(idx.row());
if (!problem)
return;
OJProblemPropertyWidget dialog;
dialog.setName(problem->name);
dialog.setUrl(problem->url);
dialog.setDescription(problem->description);
if (dialog.exec() == QDialog::Accepted) {
problem->url = dialog.url();
problem->description = dialog.description();
if (problem == mOJProblemModel.problem()) {
ui->lblProblem->setText(mOJProblemModel.getTitle());
ui->lblProblem->setToolTip(mOJProblemModel.getTooltip());
}
}
});
//context menu signal for the watch view //context menu signal for the watch view
ui->watchView->setContextMenuPolicy(Qt::CustomContextMenu); ui->watchView->setContextMenuPolicy(Qt::CustomContextMenu);
@ -2586,6 +2616,15 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos)
menu.exec(ui->treeFiles->mapToGlobal(pos)); menu.exec(ui->treeFiles->mapToGlobal(pos));
} }
void MainWindow::onLstProblemSetContextMenu(const QPoint &pos)
{
QMenu menu(this);
menu.addAction(mProblem_Properties);
QModelIndex idx =ui->lstProblemCases->currentIndex();
mProblem_Properties->setEnabled(idx.isValid());
menu.exec(ui->lstProblemSet->mapToGlobal(pos));
}
void MainWindow::onProblemSetIndexChanged(const QModelIndex &current, const QModelIndex &/* previous */) void MainWindow::onProblemSetIndexChanged(const QModelIndex &current, const QModelIndex &/* previous */)
{ {
QModelIndex idx = current; QModelIndex idx = current;
@ -2597,11 +2636,13 @@ void MainWindow::onProblemSetIndexChanged(const QModelIndex &current, const QMod
ui->txtProblemCaseOutput->clear(); ui->txtProblemCaseOutput->clear();
ui->tabProblem->setEnabled(false); ui->tabProblem->setEnabled(false);
ui->lblProblem->clear(); ui->lblProblem->clear();
ui->lblProblem->setToolTip("");
} else { } else {
ui->btnRemoveProblem->setEnabled(true); ui->btnRemoveProblem->setEnabled(true);
POJProblem problem = mOJProblemSetModel.problem(idx.row()); POJProblem problem = mOJProblemSetModel.problem(idx.row());
mOJProblemModel.setProblem(problem); mOJProblemModel.setProblem(problem);
ui->lblProblem->setText(mOJProblemModel.getTitle()); ui->lblProblem->setText(mOJProblemModel.getTitle());
ui->lblProblem->setToolTip(mOJProblemModel.getTooltip());
ui->lstProblemCases->setCurrentIndex(mOJProblemModel.index(0,0)); ui->lstProblemCases->setCurrentIndex(mOJProblemModel.index(0,0));
openCloseBottomPanel(true); openCloseBottomPanel(true);
ui->tabMessages->setCurrentWidget(ui->tabProblem); ui->tabMessages->setCurrentWidget(ui->tabProblem);
@ -2643,6 +2684,7 @@ void MainWindow::onProblemNameChanged(int index)
if (idx.isValid() && index == idx.row()) { if (idx.isValid() && index == idx.row()) {
POJProblem problem = mOJProblemSetModel.problem(idx.row()); POJProblem problem = mOJProblemSetModel.problem(idx.row());
ui->lblProblem->setText(mOJProblemModel.getTitle()); ui->lblProblem->setText(mOJProblemModel.getTitle());
ui->lblProblem->setToolTip(mOJProblemModel.getTooltip());
} }
} }
@ -3498,7 +3540,7 @@ void MainWindow::onOJProblemCaseFinished(const QString &id, int current, int tot
} }
ui->pbProblemCases->setMaximum(total); ui->pbProblemCases->setMaximum(total);
ui->pbProblemCases->setValue(current); ui->pbProblemCases->setValue(current);
ui->lblProblem->setText(mOJProblemModel.getTitle()); // ui->lblProblem->setText(mOJProblemModel.getProblemTitle());
} }
void MainWindow::cleanUpCPUDialog() void MainWindow::cleanUpCPUDialog()

View File

@ -227,6 +227,7 @@ private slots:
void onDebugConsoleContextMenu(const QPoint& pos); void onDebugConsoleContextMenu(const QPoint& pos);
void onFileEncodingContextMenu(const QPoint& pos); void onFileEncodingContextMenu(const QPoint& pos);
void onFilesViewContextMenu(const QPoint& pos); void onFilesViewContextMenu(const QPoint& pos);
void onLstProblemSetContextMenu(const QPoint& pos);
void onProblemSetIndexChanged(const QModelIndex &current, const QModelIndex &previous); void onProblemSetIndexChanged(const QModelIndex &current, const QModelIndex &previous);
void onProblemCaseIndexChanged(const QModelIndex &current, const QModelIndex &previous); void onProblemCaseIndexChanged(const QModelIndex &current, const QModelIndex &previous);
void onProblemNameChanged(int index); void onProblemNameChanged(int index);
@ -582,6 +583,9 @@ private:
QAction * mBookmark_RemoveAll; QAction * mBookmark_RemoveAll;
QAction * mBookmark_Modify; QAction * mBookmark_Modify;
//action for problem set
QAction * mProblem_Properties;
// QWidget interface // QWidget interface
protected: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;

View File

@ -31,6 +31,7 @@ using POJProblemCase = std::shared_ptr<OJProblemCase>;
struct OJProblem { struct OJProblem {
QString name; QString name;
QString url; QString url;
QString description;
QVector<POJProblemCase> cases; QVector<POJProblemCase> cases;
}; };

View File

@ -3,7 +3,7 @@
#include <QStringList> #include <QStringList>
#define DEVCPP_VERSION "0.7.9" #define DEVCPP_VERSION "0.7.8"
#define APP_SETTSINGS_FILENAME "redpandacpp.ini" #define APP_SETTSINGS_FILENAME "redpandacpp.ini"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN

View File

@ -0,0 +1,60 @@
#include "ojproblempropertywidget.h"
#include "ui_ojproblempropertywidget.h"
OJProblemPropertyWidget::OJProblemPropertyWidget(QWidget *parent) :
QDialog(parent),
ui(new Ui::OJProblemPropertyWidget)
{
ui->setupUi(this);
}
OJProblemPropertyWidget::~OJProblemPropertyWidget()
{
delete ui;
}
void OJProblemPropertyWidget::setName(const QString &name)
{
QFont f = ui->lbName->font();
f.setPointSize(f.pointSize()+2);
f.setBold(true);
ui->lbName->setFont(f);
ui->lbName->setText(name);
}
void OJProblemPropertyWidget::setUrl(const QString &url)
{
ui->txtURL->setText(url);
}
void OJProblemPropertyWidget::setDescription(const QString &description)
{
ui->txtDescription->setHtml(description);
}
QString OJProblemPropertyWidget::name()
{
return ui->lbName->text();
}
QString OJProblemPropertyWidget::url()
{
return ui->txtURL->text();
}
QString OJProblemPropertyWidget::description()
{
return ui->txtDescription->toHtml();
}
void OJProblemPropertyWidget::on_btnOk_clicked()
{
this->accept();
}
void OJProblemPropertyWidget::on_btnCancel_clicked()
{
this->reject();
}

View File

@ -0,0 +1,33 @@
#ifndef OJPROBLEMPROPERTYWIDGET_H
#define OJPROBLEMPROPERTYWIDGET_H
#include <QDialog>
namespace Ui {
class OJProblemPropertyWidget;
}
class OJProblemPropertyWidget : public QDialog
{
Q_OBJECT
public:
explicit OJProblemPropertyWidget(QWidget *parent = nullptr);
~OJProblemPropertyWidget();
void setName(const QString& name);
void setUrl(const QString& url);
void setDescription(const QString& description);
QString name();
QString url();
QString description();
private slots:
void on_btnOk_clicked();
void on_btnCancel_clicked();
private:
Ui::OJProblemPropertyWidget *ui;
};
#endif // OJPROBLEMPROPERTYWIDGET_H

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OJProblemPropertyWidget</class>
<widget class="QWidget" name="OJProblemPropertyWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>URL</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="lbName">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="txtURL"/>
</item>
<item row="2" column="0" colspan="3">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnOk">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QTextEdit" name="txtDescription"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -87,6 +87,7 @@ void OJProblemSetModel::saveToFile(const QString &fileName)
QJsonObject problemObj; QJsonObject problemObj;
problemObj["name"]=problem->name; problemObj["name"]=problem->name;
problemObj["url"]=problem->url; problemObj["url"]=problem->url;
problemObj["description"]=problem->description;
QJsonArray cases; QJsonArray cases;
foreach (const POJProblemCase& problemCase, problem->cases) { foreach (const POJProblemCase& problemCase, problem->cases) {
QJsonObject caseObj; QJsonObject caseObj;
@ -131,6 +132,7 @@ void OJProblemSetModel::loadFromFile(const QString &fileName)
POJProblem problem = std::make_shared<OJProblem>(); POJProblem problem = std::make_shared<OJProblem>();
problem->name = problemObj["name"].toString(); problem->name = problemObj["name"].toString();
problem->url = problemObj["url"].toString(); problem->url = problemObj["url"].toString();
problem->description = problemObj["description"].toString();
QJsonArray casesArray = problemObj["cases"].toArray(); QJsonArray casesArray = problemObj["cases"].toArray();
foreach (const QJsonValue& caseVal, casesArray) { foreach (const QJsonValue& caseVal, casesArray) {
QJsonObject caseObj = caseVal.toObject(); QJsonObject caseObj = caseVal.toObject();
@ -292,6 +294,18 @@ QString OJProblemModel::getTitle()
return title; return title;
} }
QString OJProblemModel::getTooltip()
{
if (!mProblem)
return "";
QString s;
s=QString("<h3>%1</h3>").arg(mProblem->name);
if (!mProblem->description.isEmpty())
s+=QString("<p>%1</p>")
.arg(mProblem->description);
return s;
}
int OJProblemModel::rowCount(const QModelIndex &) const int OJProblemModel::rowCount(const QModelIndex &) const
{ {
if (mProblem==nullptr) if (mProblem==nullptr)

View File

@ -20,6 +20,7 @@ public:
int count(); int count();
void update(int row); void update(int row);
QString getTitle(); QString getTitle();
QString getTooltip();
private: private:
POJProblem mProblem; POJProblem mProblem;