\begin{tikzpicture} \node[initial] (start) {}; \node[activity,below=0.35cm of start] (request) {\textbf{tkrMainWindow}\\closeEvent(): cancel preview, then check unsaved changes}; \node[choice,below=0.45cm of request] (dirty) {Dirty?}; \node[activity,below=0.45cm of dirty] (prompt) {\textbf{tkrMainWindow}\\Ask Save / Discard / Cancel}; \node[choice,below=0.45cm of prompt] (choice) {User choice?}; \node[activitySide] (keep) at ([xshift=-5.4cm]choice.center) {Ignore close event; keep document and window open}; \node[final,below=0.4cm of keep] (keepEnd) {}; \node[activity,below=0.45cm of choice] (save) {\textbf{tkrMainWindow / Controller}\\Attempt guarded saveDocument()}; \node[choice,below=0.45cm of save] (saved) {Save succeeded?}; \node[diamond,draw=tkrBlue,minimum size=3mm,inner sep=0pt,fill=white,below=0.55cm of saved] (merge) {}; \node[activity,below=0.45cm of merge] (accept) {\textbf{tkrMainWindow}\\Accept final-window close}; \node[activity,below=0.4cm of accept] (quit) {\textbf{QApplication / main()}\\Exit event loop; destroy stack window and its controller, document/history, then Qt-owned scene/widgets}; \node[final,below=0.35cm of quit] (finish) {}; \draw[flow] (start) -- (request); \draw[flow] (request) -- (dirty); \draw[flow] (dirty) -- node[guard,right]{[yes]} (prompt); \draw[flow] (dirty.east) -- node[guard,above]{[no]} ([xshift=5.4cm]dirty.center) |- (merge.east); \draw[flow] (prompt) -- (choice); \draw[flow] (choice) -- node[guard,above]{[Cancel]} (keep); \draw[flow] (keep) -- (keepEnd); \draw[flow] (choice.east) -- node[guard,above]{[Discard]} ([xshift=4.0cm]choice.center) |- (merge.east); \draw[flow] (choice) -- node[guard,right]{[Save]} (save); \draw[flow] (save) -- (saved); \draw[flow] (saved.west) -- node[guard,above]{[no]} ([xshift=-3.5cm]saved.center) |- (keep.east); \draw[flow] (saved) -- node[guard,right]{[yes]} (merge); \draw[flow] (merge) -- (accept); \draw[flow] (accept) -- (quit); \draw[flow] (quit) -- (finish); \end{tikzpicture}