文本编辑器中替换对话框的设计与实现
发布日期:2021-07-01 04:26:14
浏览次数:2
分类:技术文章
本文共 2463 字,大约阅读时间需要 8 分钟。
文章目录
1 文本编辑器中替换对话框的设计与实现
替换对话框需求分析:
- 可复用软件部分。
- 查找文本框中的指定字符串。
- 替换单个指定字符串。
- 替换所有指定字符串。
附加需求:
- 点击关闭按钮后隐藏。
替换对话框的设计与实现:
替换对话框的界面布局: 替换算法流程图: Main Window与ReplaceDialog之间的关系图: ReplaceDialog.h:#ifndef _REPLACEDIALOG_H_#define _REPLACEDIALOG_H_#include "FindDialog.h"class ReplaceDialog : public FindDialog{ Q_OBJECTprotected: QLabel m_replaceLbl; QLineEdit m_replaceEdit; QPushButton m_replaceBtn; QPushButton m_replaceAllBtn; void initControl(); void connectSlot();protected slots: void onReplaceClicked(); void onReplaceAllClicked();public: explicit ReplaceDialog(QWidget *parent = 0, QPlainTextEdit* pText = 0);};#endif // _REPLACEDIALOG_H_
ReplaceDialog.cpp:
#include "ReplaceDialog.h"ReplaceDialog::ReplaceDialog(QWidget *parent, QPlainTextEdit* pText) : FindDialog(parent, pText){ initControl(); connectSlot(); setWindowTitle("Replace");}void ReplaceDialog::initControl(){ m_replaceLbl.setText("Replace To:"); m_replaceBtn.setText("Replace"); m_replaceAllBtn.setText("Replace All"); m_layout.removeWidget(&m_matchChkBx); m_layout.removeWidget(&m_radioGrpBx); m_layout.removeWidget(&m_closeBtn); m_layout.addWidget(&m_replaceLbl, 1, 0); m_layout.addWidget(&m_replaceEdit, 1, 1); m_layout.addWidget(&m_replaceBtn, 1, 2); m_layout.addWidget(&m_matchChkBx, 2, 0); m_layout.addWidget(&m_radioGrpBx, 2, 1); m_layout.addWidget(&m_replaceAllBtn, 2, 2); m_layout.addWidget(&m_closeBtn, 3, 2);}void ReplaceDialog::connectSlot(){ connect(&m_replaceBtn, SIGNAL(clicked()), this, SLOT(onReplaceClicked())); connect(&m_replaceAllBtn, SIGNAL(clicked()), this, SLOT(onReplaceAllClicked()));}void ReplaceDialog::onReplaceClicked(){ QString target = m_findEdit.text(); QString to = m_replaceEdit.text(); if( (m_pText != NULL) && (target != "") && (to != "") ) { QString selText = m_pText->textCursor().selectedText(); if( selText == target ) { m_pText->insertPlainText(to); } onFindClicked(); }}void ReplaceDialog::onReplaceAllClicked(){ QString target = m_findEdit.text(); QString to = m_replaceEdit.text(); if( (m_pText != NULL) && (target != "") && (to != "") ) { QString text = m_pText->toPlainText(); text.replace(target, to, m_matchChkBx.isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive); m_pText->clear(); m_pText->insertPlainText(text); }}
参考资料:
转载地址:https://muzimin.blog.csdn.net/article/details/105070654 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年04月10日 11时15分28秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
ECharts is not Loaded解决方案
2019-05-01
echarts切换tab时,第一个图表显示,第二个图表不显示的解决办法
2019-05-01
记一次Hive 行转列 引起的GC overhead limit exceeded
2019-05-01
OpenGL ES八 - 交叉存取顶点数据
2019-05-01
crontab定时任务写法
2019-05-01
nginx: [emerg] unknown directive "if($remote_addr" in /usr/local/tools/nginx/conf/nginx.conf:57
2019-05-01
module pip has no attribute main问题解决
2019-05-01
LeetCode 134.Gas Station (加油站)
2019-05-01
Python之命名元组 (namedtuple)
2019-05-01
使用libpcap过滤arp
2019-05-01
在VC环境中调试跟踪变量
2019-05-01
[转帖]Robots.txt指南
2019-05-01
Eclipse + MyEclipse下配置J2EE工程(英文界面)
2019-05-01
Eclipse及其插件下载网址大全
2019-05-01
正则表达式简介(微软)--6.优先权顺序
2019-05-01
多用户与多租户的区别
2019-05-01
Python自动化运维 - day14 - JavaScript基础
2019-05-02
oracle保存小数点前为"0"的问题
2019-05-02
linux sar 命令详解
2019-05-02