- beautify dark theme

- feature: toggle breakpoint
 - feature: clear all breakpoint
 - feature: breakpoint condition
This commit is contained in:
royqh1979@gmail.com 2021-09-03 10:30:08 +08:00
parent 56ff4a6c35
commit 9cf43026ba
14 changed files with 202 additions and 47 deletions

0
NEWS.md Normal file
View File

View File

@ -193,6 +193,24 @@ void Debugger::removeBreakpoint(int index)
mBreakpointModel->removeBreakpoint(index);
}
PBreakpoint Debugger::breakpointAt(int line, const QString& filename, int &index)
{
const QList<PBreakpoint>& breakpoints=mBreakpointModel->breakpoints();
for (index=0;index<breakpoints.count();index++){
PBreakpoint breakpoint = breakpoints[index];
if (breakpoint->line == line
&& breakpoint->filename == filename)
return breakpoint;
}
index=-1;
return PBreakpoint();
}
PBreakpoint Debugger::breakpointAt(int line, const Editor *editor, int &index)
{
return breakpointAt(line,editor->filename(),index);
}
void Debugger::setBreakPointCondition(int index, const QString &condition)
{
PBreakpoint breakpoint=mBreakpointModel->setBreakPointCondition(index,condition);
@ -1441,6 +1459,21 @@ QVariant BreakpointModel::data(const QModelIndex &index, int role) const
return QVariant();
switch (role) {
case Qt::DisplayRole:
switch (index.column()) {
case 0: {
return baseFileName(breakpoint->filename);
}
case 1:
if (breakpoint->line>0)
return breakpoint->line;
else
return "";
case 2:
return breakpoint->condition;
default:
return QVariant();
}
case Qt::ToolTipRole:
switch (index.column()) {
case 0:
return breakpoint->filename;

View File

@ -183,6 +183,8 @@ public:
void removeBreakpoint(int line, const Editor* editor);
void removeBreakpoint(int line, const QString& filename);
void removeBreakpoint(int index);
PBreakpoint breakpointAt(int line, const QString& filename, int &index);
PBreakpoint breakpointAt(int line, const Editor* editor, int &index);
void setBreakPointCondition(int index, const QString& condition);
void sendAllBreakpointsToDebugger();

View File

@ -23,6 +23,7 @@
#include <QPainter>
#include <QToolTip>
#include <QApplication>
#include <QInputDialog>
#include "iconsmanager.h"
#include "debugger.h"
#include "editorlist.h"
@ -2550,6 +2551,13 @@ void Editor::toggleBreakpoint(int line)
invalidateLine(line);
}
void Editor::clearBreakpoints()
{
pMainWindow->debugger()->deleteBreakpoints(this);
mBreakpointLines.clear();
invalidate();
}
bool Editor::hasBreakpoint(int line)
{
return mBreakpointLines.contains(line);
@ -2565,6 +2573,23 @@ void Editor::removeBreakpointFocus()
}
}
void Editor::modifyBreakpointProperty(int line)
{
int index;
PBreakpoint breakpoint = pMainWindow->debugger()->breakpointAt(line,this,index);
if (!breakpoint)
return;
bool isOk;
QString s=QInputDialog::getText(this,
tr("Break point condition"),
tr("Enter the condition of the breakpoint:"),
QLineEdit::Normal,
breakpoint->condition,&isOk);
if (isOk) {
pMainWindow->debugger()->setBreakPointCondition(index,s);
}
}
void Editor::setActiveBreakpointFocus(int Line, bool setFocus)
{
if (Line != mActiveBreakpointLine) {

View File

@ -132,8 +132,10 @@ public:
PSyntaxIssue getSyntaxIssueAtPosition(const BufferCoord& pos);
int gutterClickedLine() const;
void toggleBreakpoint(int line);
void clearBreakpoints();
bool hasBreakpoint(int line);
void removeBreakpointFocus();
void modifyBreakpointProperty(int line);
void setActiveBreakpointFocus(int Line, bool setFocus=true);
QString getWordAtPosition(const BufferCoord& p,
BufferCoord& pWordBegin,

View File

@ -1144,14 +1144,23 @@ void MainWindow::onEditorContextMenu(const QPoint &pos)
if (!editor)
return;
QMenu menu(this);
BufferCoord p;
mContextMenuPos = pos;
if (editor->GetPositionOfMouse(p)) {
//mouse on editing area
menu.addAction(ui->actionCompile_Run);
menu.addAction(ui->actionDebug);
int line = editor->caretY();
if (editor->hasBreakpoint(line)) {
//todo: breakpoint property
menu.addSeparator();
} else {
//mouse on gutter
int line;
if (!editor->GetLineOfMouse(line))
line=-1;
menu.addAction(ui->actionToggle_Breakpoint);
menu.addAction(ui->actionBreakpoint_property);
menu.addAction(ui->actionClear_all_breakpoints);
ui->actionBreakpoint_property->setEnabled(editor->hasBreakpoint(line));
}
//todo: goto declaretion
//todo: goto definition
menu.exec(editor->viewport()->mapToGlobal(pos));
}
@ -2138,3 +2147,39 @@ void MainWindow::on_actionPrevious_Editor_triggered()
mEditorList->selectPreviousPage();
}
void MainWindow::on_actionToggle_Breakpoint_triggered()
{
Editor * editor = mEditorList->getEditor();
int line;
if (editor && editor->PointToLine(mContextMenuPos,line))
editor->toggleBreakpoint(line);
}
void MainWindow::on_actionClear_all_breakpoints_triggered()
{
Editor *e=mEditorList->getEditor();
if (!e)
return;
if (QMessageBox::question(this,
tr("Clear all breakpoints"),
tr("Do you really want to clear all breakpoints in this file?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No) == QMessageBox::Yes) {
e->clearBreakpoints();
}
}
void MainWindow::on_actionBreakpoint_property_triggered()
{
Editor * editor = mEditorList->getEditor();
int line;
if (editor && editor->PointToLine(mContextMenuPos,line)) {
if (editor->hasBreakpoint(line))
editor->modifyBreakpointProperty(line);
}
}

View File

@ -264,6 +264,12 @@ private slots:
void on_actionPrevious_Editor_triggered();
void on_actionToggle_Breakpoint_triggered();
void on_actionClear_all_breakpoints_triggered();
void on_actionBreakpoint_property_triggered();
private:
Ui::MainWindow *ui;
EditorList *mEditorList;
@ -307,6 +313,7 @@ private:
bool mClosing;
bool mSystemTurnedOff;
QPoint mContextMenuPos;
// QWidget interface

View File

@ -255,7 +255,7 @@
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>4</number>
<number>0</number>
</property>
<widget class="QWidget" name="tabIssues">
<attribute name="icon">
@ -302,6 +302,9 @@
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
</widget>
</item>
</layout>
@ -464,7 +467,7 @@
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="tabDebugConsole">
<attribute name="title">
@ -517,6 +520,9 @@
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
</widget>
</item>
</layout>
@ -543,6 +549,9 @@
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
</widget>
</item>
</layout>
@ -1505,6 +1514,29 @@
<string>Ctrl+Shift+Tab</string>
</property>
</action>
<action name="actionToggle_Breakpoint">
<property name="icon">
<iconset>
<normalon>:/icons/images/editor/breakpoint.png</normalon>
</iconset>
</property>
<property name="text">
<string>Toggle breakpoint</string>
</property>
<property name="shortcut">
<string>Ctrl+F4</string>
</property>
</action>
<action name="actionClear_all_breakpoints">
<property name="text">
<string>Clear all breakpoints</string>
</property>
</action>
<action name="actionBreakpoint_property">
<property name="text">
<string>Breakpoint property...</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -401,7 +401,7 @@ QMenu::separator {
QMenu::item {
background-color: #37414F;
padding: 4px 24px 4px 28px;
padding: 4px 8px 4px 8px;
/* Reserve space for selection border */
border: 1px transparent #455364;
}
@ -1574,7 +1574,7 @@ QTabBar::tab:right:!selected, QDockWidget QTabBar::tab:right:!selected {
QTabBar::tab:top, QDockWidget QTabBar::tab:top {
background-color: #455364;
margin-left: 2px;
padding: 0.1em 0.5em 0.1em 0.5em;
padding: 4px 10px 4px 10px;
min-width: 5px;
border-bottom: 3px solid #455364;
border-top-left-radius: 4px;
@ -1600,7 +1600,7 @@ QTabBar::tab:bottom, QDockWidget QTabBar::tab:bottom {
border-top: 3px solid #455364;
background-color: #455364;
margin-left: 2px;
padding: 0.1em 0.5em 0.1em 0.5em;
padding: 4px 10px 4px 10px;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
min-width: 5px;
@ -1624,7 +1624,7 @@ QTabBar::tab:bottom:!selected:hover, QDockWidget QTabBar::tab:bottom:!selected:h
QTabBar::tab:left, QDockWidget QTabBar::tab:left {
background-color: #455364;
margin-top: 2px;
padding: 0.5em 0.1em 0.5em 0.1em;
padding: 10px 4px 10px 4px;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
min-height: 5px;
@ -1646,7 +1646,7 @@ QTabBar::tab:left:!selected:hover, QDockWidget QTabBar::tab:left:!selected:hover
QTabBar::tab:right, QDockWidget QTabBar::tab:right {
background-color: #455364;
margin-top: 2px;
padding: 0.5em 0.1em 0.5em 0.1em;
padding: 10px 4px 10px 4px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
min-height: 5px;
@ -1949,7 +1949,7 @@ QHeaderView::section {
color: #E0E1E3;
border-radius: 0;
text-align: left;
font-size: 13px;
/* font-size: 13px; */
}
QHeaderView::section::horizontal {

View File

@ -1575,10 +1575,7 @@ QTabBar::tab:right:!selected, QDockWidget QTabBar::tab:right:!selected {
QTabBar::tab:top, QDockWidget QTabBar::tab:top {
background-color: #C9CDD0;
margin-left: 2px;
padding-left: 4px;
padding-right: 4px;
padding-top: 2px;
padding-bottom: 2px;
padding: 4px 10px 4px 10px;
min-width: 5px;
border-bottom: 3px solid #C9CDD0;
border-top-left-radius: 4px;
@ -1596,18 +1593,15 @@ QTabBar::tab:top:!selected:hover, QDockWidget QTabBar::tab:top:!selected:hover {
border: 1px solid #73C7FF;
border-bottom: 3px solid #73C7FF;
/* Fixes spyder-ide/spyder#9766 and #243 */
padding-left: 3px;
padding-right: 3px;
/*padding-left: 3px*/;
/*padding-right: 3px*/;
}
QTabBar::tab:bottom, QDockWidget QTabBar::tab:bottom {
border-top: 3px solid #C9CDD0;
background-color: #C9CDD0;
margin-left: 2px;
padding-left: 4px;
padding-right: 4px;
padding-top: 2px;
padding-bottom: 2px;
padding: 4px 10px 4px 10px;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
min-width: 5px;
@ -1631,10 +1625,7 @@ QTabBar::tab:bottom:!selected:hover, QDockWidget QTabBar::tab:bottom:!selected:h
QTabBar::tab:left, QDockWidget QTabBar::tab:left {
background-color: #C9CDD0;
margin-top: 2px;
padding-left: 2px;
padding-right: 2px;
padding-top: 4px;
padding-bottom: 4px;
padding: 10px 4px 10px 4px;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
min-height: 5px;
@ -1656,10 +1647,7 @@ QTabBar::tab:left:!selected:hover, QDockWidget QTabBar::tab:left:!selected:hover
QTabBar::tab:right, QDockWidget QTabBar::tab:right {
background-color: #C9CDD0;
margin-top: 2px;
padding-left: 2px;
padding-right: 2px;
padding-top: 4px;
padding-bottom: 4px;
padding: 10px 4px 10px 4px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
min-height: 5px;
@ -1962,7 +1950,7 @@ QHeaderView::section {
color: #19232D;
border-radius: 0;
text-align: left;
font-size: 13px;
/* font-size: 13px; */
}
QHeaderView::section::horizontal {

View File

@ -603,3 +603,9 @@ void logToFile(const QString &s, const QString &filename, bool append)
ts<<s<<Qt::endl;
}
}
QString baseFileName(const QString &fileName)
{
QFileInfo fileInfo(fileName);
return fileInfo.fileName();
}

View File

@ -158,6 +158,8 @@ bool findComplement(const QString& s,
int increment);
void logToFile(const QString& s, const QString& filename, bool append=true);
QString baseFileName(const QString& fileName);
class CppParser;
void resetCppParser(std::shared_ptr<CppParser> parser);

View File

@ -162,6 +162,9 @@
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
</widget>
</widget>
</item>

View File

@ -1,5 +1,7 @@
#include "issuestable.h"
#include "../utils.h"
#include <QHeaderView>
#include "../settings.h"
IssuesTable::IssuesTable(QWidget *parent):
@ -7,7 +9,6 @@ IssuesTable::IssuesTable(QWidget *parent):
{
mModel = new IssuesModel(this);
this->setModel(mModel);
this->horizontalHeader()->setSectionResizeMode(3,QHeaderView::Stretch);
this->setColumnWidth(0,200);
this->setColumnWidth(1,45);
this->setColumnWidth(2,45);
@ -120,9 +121,14 @@ QVariant IssuesModel::data(const QModelIndex &index, int role) const
return QVariant();
switch (role) {
case Qt::DisplayRole:
case Qt::ToolTipRole:
switch (index.column()) {
case 0:
case 0: {
if (role == Qt::DisplayRole)
return baseFileName(issue->filename);
else
return issue->filename;
}
case 1:
if (issue->line>0)
return issue->line;
@ -168,7 +174,9 @@ QVariant IssuesModel::data(const QModelIndex &index, int role) const
QVariant IssuesModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal ) {
switch(role) {
case Qt::DisplayRole:
switch(section) {
case 0:
return tr("Filename");
@ -179,6 +187,8 @@ QVariant IssuesModel::headerData(int section, Qt::Orientation orientation, int r
case 3:
return tr("Description");
}
break;
}
}
return QVariant();
}