File indexing completed on 2025-02-02 05:43:21

0001 /*
0002     This file is part of the Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2006, 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef KASTEN_ABSTRACTVIEWFACTORY_HPP
0010 #define KASTEN_ABSTRACTVIEWFACTORY_HPP
0011 
0012 // lib
0013 #include "abstractview.hpp"
0014 
0015 namespace Kasten {
0016 
0017 class KASTENGUI_EXPORT AbstractViewFactory
0018 {
0019 public:
0020     virtual ~AbstractViewFactory();
0021 
0022 public:
0023     // TODO: there can be views not only on documents
0024     virtual AbstractView* createViewFor(AbstractDocument* document) = 0;
0025     // TODO: is alignment best done here? needs view to be stable on creation of view copy
0026     // doesn't work if the new view is not next to the old, but are there usecases for this?
0027     /**
0028      * @param alignment on which side the new view is placed to show a continuous whole view
0029      */
0030     virtual AbstractView* createCopyOfView(AbstractView* view, Qt::Alignment alignment = {});
0031 };
0032 
0033 inline AbstractViewFactory::~AbstractViewFactory() = default;
0034 
0035 // TODO: is this default implementation useful? Like, if the base is not a document, but a subdocument/model?
0036 inline AbstractView* AbstractViewFactory::createCopyOfView(AbstractView* view, Qt::Alignment alignment)
0037 {
0038     Q_UNUSED(alignment)
0039 
0040     AbstractView * viewCopy = createViewFor(view->findBaseModel<AbstractDocument*>());
0041     if (viewCopy) {
0042         viewCopy->setReadOnly(view->isReadOnly());
0043     }
0044 
0045     return viewCopy;
0046 }
0047 
0048 }
0049 
0050 #endif