Modify the MDI manual test to allow multiple views of same document
- editing same document in different views is possible? yes - resizing one QTextEdit calls QTextDocument::setTextWidth(), which affects the width in the other view too. You can resize either one, but you can't have two views with different layouts, of course. Added a categorized log message in QTextDocument::setTextWidth() for a sanity check. Task-nunber: QTBUG-35688 Change-Id: I59c4d10143fda3a66b946237832274d67f9d9d45 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
parent
a0a29695ab
commit
83b592346b
@ -11,6 +11,7 @@
|
|||||||
#include "qtexttable.h"
|
#include "qtexttable.h"
|
||||||
#include "qtextlist.h"
|
#include "qtextlist.h"
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
|
#include <qloggingcategory.h>
|
||||||
#if QT_CONFIG(regularexpression)
|
#if QT_CONFIG(regularexpression)
|
||||||
#include <qregularexpression.h>
|
#include <qregularexpression.h>
|
||||||
#endif
|
#endif
|
||||||
@ -42,6 +43,8 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(lcLayout);
|
||||||
|
|
||||||
using namespace Qt::StringLiterals;
|
using namespace Qt::StringLiterals;
|
||||||
|
|
||||||
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n);
|
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n);
|
||||||
@ -727,6 +730,8 @@ void QTextDocument::setTextWidth(qreal width)
|
|||||||
{
|
{
|
||||||
Q_D(QTextDocument);
|
Q_D(QTextDocument);
|
||||||
QSizeF sz = d->pageSize;
|
QSizeF sz = d->pageSize;
|
||||||
|
|
||||||
|
qCDebug(lcLayout) << "page size" << sz << "-> width" << width;
|
||||||
sz.setWidth(width);
|
sz.setWidth(width);
|
||||||
sz.setHeight(-1);
|
sz.setHeight(-1);
|
||||||
setPageSize(sz);
|
setPageSize(sz);
|
||||||
|
@ -74,6 +74,12 @@ bool MainWindow::loadFile(const QString &fileName)
|
|||||||
return succeeded;
|
return succeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::newSubWindow()
|
||||||
|
{
|
||||||
|
MdiChild *child = createMdiChild(static_cast<MdiChild *>(mdiArea->activeSubWindow()->widget()));
|
||||||
|
child->show();
|
||||||
|
}
|
||||||
|
|
||||||
static inline QString recentFilesKey() { return QStringLiteral("recentFileList"); }
|
static inline QString recentFilesKey() { return QStringLiteral("recentFileList"); }
|
||||||
static inline QString fileKey() { return QStringLiteral("file"); }
|
static inline QString fileKey() { return QStringLiteral("file"); }
|
||||||
|
|
||||||
@ -201,6 +207,7 @@ void MainWindow::updateMenus()
|
|||||||
#ifndef QT_NO_CLIPBOARD
|
#ifndef QT_NO_CLIPBOARD
|
||||||
pasteAct->setEnabled(hasMdiChild);
|
pasteAct->setEnabled(hasMdiChild);
|
||||||
#endif
|
#endif
|
||||||
|
newWindowAct->setEnabled(hasMdiChild);
|
||||||
closeAct->setEnabled(hasMdiChild);
|
closeAct->setEnabled(hasMdiChild);
|
||||||
closeAllAct->setEnabled(hasMdiChild);
|
closeAllAct->setEnabled(hasMdiChild);
|
||||||
tileAct->setEnabled(hasMdiChild);
|
tileAct->setEnabled(hasMdiChild);
|
||||||
@ -220,6 +227,7 @@ void MainWindow::updateMenus()
|
|||||||
void MainWindow::updateWindowMenu()
|
void MainWindow::updateWindowMenu()
|
||||||
{
|
{
|
||||||
windowMenu->clear();
|
windowMenu->clear();
|
||||||
|
windowMenu->addAction(newWindowAct);
|
||||||
windowMenu->addAction(closeAct);
|
windowMenu->addAction(closeAct);
|
||||||
windowMenu->addAction(closeAllAct);
|
windowMenu->addAction(closeAllAct);
|
||||||
windowMenu->addSeparator();
|
windowMenu->addSeparator();
|
||||||
@ -253,9 +261,9 @@ void MainWindow::updateWindowMenu()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MdiChild *MainWindow::createMdiChild()
|
MdiChild *MainWindow::createMdiChild(MdiChild *other)
|
||||||
{
|
{
|
||||||
MdiChild *child = new MdiChild;
|
MdiChild *child = new MdiChild(other);
|
||||||
mdiArea->addSubWindow(child);
|
mdiArea->addSubWindow(child);
|
||||||
|
|
||||||
#ifndef QT_NO_CLIPBOARD
|
#ifndef QT_NO_CLIPBOARD
|
||||||
@ -365,6 +373,11 @@ void MainWindow::createActions()
|
|||||||
windowMenu = menuBar()->addMenu(tr("&Window"));
|
windowMenu = menuBar()->addMenu(tr("&Window"));
|
||||||
connect(windowMenu, &QMenu::aboutToShow, this, &MainWindow::updateWindowMenu);
|
connect(windowMenu, &QMenu::aboutToShow, this, &MainWindow::updateWindowMenu);
|
||||||
|
|
||||||
|
newWindowAct = new QAction(tr("&New view"), this);
|
||||||
|
newWindowAct->setStatusTip(tr("Make another window viewing the same document"));
|
||||||
|
connect(newWindowAct, &QAction::triggered,
|
||||||
|
this, &MainWindow::newSubWindow);
|
||||||
|
|
||||||
closeAct = new QAction(tr("Cl&ose"), this);
|
closeAct = new QAction(tr("Cl&ose"), this);
|
||||||
closeAct->setStatusTip(tr("Close the active window"));
|
closeAct->setStatusTip(tr("Close the active window"));
|
||||||
connect(closeAct, &QAction::triggered,
|
connect(closeAct, &QAction::triggered,
|
||||||
|
@ -12,6 +12,7 @@ class QAction;
|
|||||||
class QMenu;
|
class QMenu;
|
||||||
class QMdiArea;
|
class QMdiArea;
|
||||||
class QMdiSubWindow;
|
class QMdiSubWindow;
|
||||||
|
class QTextDocument;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
@ -41,8 +42,9 @@ private slots:
|
|||||||
void about();
|
void about();
|
||||||
void updateMenus();
|
void updateMenus();
|
||||||
void updateWindowMenu();
|
void updateWindowMenu();
|
||||||
MdiChild *createMdiChild();
|
MdiChild *createMdiChild(MdiChild *other = nullptr);
|
||||||
void switchLayoutDirection();
|
void switchLayoutDirection();
|
||||||
|
void newSubWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum { MaxRecentFiles = 5 };
|
enum { MaxRecentFiles = 5 };
|
||||||
@ -72,6 +74,7 @@ private:
|
|||||||
QAction *copyAct;
|
QAction *copyAct;
|
||||||
QAction *pasteAct;
|
QAction *pasteAct;
|
||||||
#endif
|
#endif
|
||||||
|
QAction *newWindowAct;
|
||||||
QAction *closeAct;
|
QAction *closeAct;
|
||||||
QAction *closeAllAct;
|
QAction *closeAllAct;
|
||||||
QAction *tileAct;
|
QAction *tileAct;
|
||||||
|
@ -5,10 +5,18 @@
|
|||||||
|
|
||||||
#include "mdichild.h"
|
#include "mdichild.h"
|
||||||
|
|
||||||
MdiChild::MdiChild()
|
MdiChild::MdiChild(MdiChild *other)
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
isUntitled = true;
|
if (other) {
|
||||||
|
auto *doc = other->document();
|
||||||
|
setDocument(doc);
|
||||||
|
setWindowModified(other->isWindowModified());
|
||||||
|
connect(doc, &QTextDocument::contentsChanged,
|
||||||
|
this, &MdiChild::documentWasModified);
|
||||||
|
curFile = other->curFile;
|
||||||
|
setWindowTitle(userFriendlyCurrentFile() + "[*]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MdiChild::newFile()
|
void MdiChild::newFile()
|
||||||
|
@ -11,7 +11,7 @@ class MdiChild : public QTextEdit
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MdiChild();
|
MdiChild(MdiChild *other = nullptr);
|
||||||
|
|
||||||
void newFile();
|
void newFile();
|
||||||
bool loadFile(const QString &fileName);
|
bool loadFile(const QString &fileName);
|
||||||
@ -33,7 +33,7 @@ private:
|
|||||||
QString strippedName(const QString &fullFileName);
|
QString strippedName(const QString &fullFileName);
|
||||||
|
|
||||||
QString curFile;
|
QString curFile;
|
||||||
bool isUntitled;
|
bool isUntitled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user