Skip to content

Commit

Permalink
add other demo
Browse files Browse the repository at this point in the history
  • Loading branch information
litz-a committed Oct 18, 2017
1 parent 74d9c2b commit 3ef46ce
Show file tree
Hide file tree
Showing 8,435 changed files with 559,612 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
54 changes: 54 additions & 0 deletions Cshnick_Qt_dynamicList/Cshnick_Qt_dynamicList.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
!isEmpty(CSHNICK_QT_DYNAMICLIST_PRI):error("Cshnick_Qt_dynamicList.pri must be included only once")
CSHNICK_QT_DYNAMICLIST_PRI = 1

defineReplace(libraryDependency) {
return(-l$$1)
}

TOP_LEVEL_SRC_DIR = $$PWD
#message(PWD $$PWD)
#message(OUT_PWD $$OUT_PWD)
isEmpty(TOP_LEVEL_BUILD_DIR) {
relativeDir = $$_PRO_FILE_PWD_
relativeDir ~= s,^$$re_escape($$PWD),,
TOP_LEVEL_BUILD_DIR = $$OUT_PWD
TOP_LEVEL_BUILD_DIR ~= s,$$re_escape($$relativeDir)$,,
TOP_LEVEL_BUILD_DIR = $$TOP_LEVEL_BUILD_DIR/build
# message(TOP_LEVEL_BUILD_DIR $$TOP_LEVEL_BUILD_DIR)
}

APP_DIR = $$TOP_LEVEL_BUILD_DIR/bin
!macx {
APP_TARGET = "docManager"
LIB_PATH = $$TOP_LEVEL_BUILD_DIR/lib
PLUGIN_PATH = $$TOP_LEVEL_BUILD_DIR/Plugins
EXEC_PATH = $$APP_DIR
# message(APP_TARGET $$APP_TARGET)
# message(LIB_PATH $$LIB_PATH)
# message(PLUGIN_PATH $$PLUGIN_PATH)
# message(EXEC_PATH $$EXEC_PATH)

} else { #macx
APP_TARGET = "bin"
PLUGIN_PATH = $$APP_DIR/$${APP_TARGET}.app/Contents/PlugIns
LIB_PATH = $$PLUGIN_PATH
EXEC_PATH = $$APP_DIR/$${APP_TARGET}.app/Contents/MacOS
}

CONFIG += depend_includepath

LIBS *= -L$$LIB_PATH

SERVICE_DIR = $${OUT_PWD}/.service
CONFIG(debug, debug|release) {
DEBUG_POSTFIX = debug
OBJECTS_DIR = $$SERVICE_DIR/$$DEBUG_POSTFIX
MOC_DIR = $$SERVICE_DIR/$$DEBUG_POSTFIX
}
CONFIG(release, debug|release) {
RELEASE_POSTFIX = release
OBJECTS_DIR = $$SERVICE_DIR/$$RELEASE_POSTFIX
MOC_DIR = $$SERVICE_DIR/$$RELEASE_POSTFIX
}


9 changes: 9 additions & 0 deletions Cshnick_Qt_dynamicList/Cshnick_Qt_dynamicList.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TEMPLATE = subdirs
CONFIG += ordered

SUBDIRS += \
PluginManager \
Documents \
Plugins \
bin

211 changes: 211 additions & 0 deletions Cshnick_Qt_dynamicList/Documents/DocumentManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
#include "DocumentManager.h"

#include <QPushButton>
#include <QSplitter>
#include <QVBoxLayout>
#include <QMenu>
#include <QAction>
#include <QDebug>

#include "PluginManager.h"
#include "PInfoHandler.h"
#include "Node.h"
#include "ThumbnailManager.h"
#include "ExplorerModel.h"
#include "ExplorerView.h"
#include "IDocumentGenerator.h"
#include "ICommonInterface.h"

static const QString expectedGeneratorName = "TstGenerator";

namespace Docs {

class DocumentManagerPrivate
{
public:
DocumentManagerPrivate(DocumentManager *pq)
: q(pq)
, mExplorerModel(0)
, mExplorerView(0)
, mTopWidget(0)
, mPluginBox(0)
, mPluginsMenu(0)
, mThumbsManager(0)
{
mExplorerModel = new ExplorerModel();
mExplorerView = new ExplorerView();
mExplorerView->setModel(mExplorerModel);
mThumbsManager = new DynPicturesManager();
setupUi();

QObject::connect(mExplorerView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex))
, q, SLOT(selectionChanged_slot(QModelIndex,QModelIndex)));
QObject::connect(Plugins::PluginManager::instance(), SIGNAL(pluginDynamiclyLoaded(QPluginLoader*))
, q, SLOT(onPluginDynamiclyLoaded(QPluginLoader*)));

QList<IDocumentGenerator*> availGenerators = Plugins::PluginManager::getObjects<IDocumentGenerator*>();
foreach (IDocumentGenerator *nextGenerator, availGenerators) {
nextGenerator->createNodeTree();
registerGenerator(nextGenerator);
}

}

~DocumentManagerPrivate()
{
if (mTopWidget) {
delete mTopWidget;
}
if (mExplorerModel) {
delete mExplorerModel;
}

}
void registerGenerator(IDocumentGenerator *pGenerator) {
if (mRegisteredGenerators.contains(pGenerator) && !pGenerator) {
return;
}
mRegisteredGenerators.append(pGenerator);
mExplorerModel->registerGenerator(pGenerator);
if (mRegisteredGenerators.count() < 2 && false) {
mExplorerView->setRootIndex(mExplorerModel->index(0, 0, QModelIndex()));
} else {
mExplorerView->setRootIndex(QModelIndex());
}
mExplorerView->expandAll();
}

void setupUi()
{
mTopWidget = new QSplitter();

QWidget *explorerContainer = new QWidget;

QVBoxLayout *mainLayout = new QVBoxLayout;
mPluginsMenu = new QMenu("Plugins", 0);
Plugins::PluginManager::PInfoList allInfos = Plugins::PluginManager::pluginMetas();
foreach (Plugins::PInfoHandler nextMeta, allInfos) {
if (!nextMeta) {
continue;
}
QAction *pluginAction = new QAction(nextMeta.displayName(), mPluginsMenu);
pluginAction->setCheckable(true);
pluginAction->setChecked(nextMeta.isEnabled());
pluginAction->setData(QVariant::fromValue(nextMeta));
QObject::connect(pluginAction, SIGNAL(toggled(bool)), q, SLOT(actionMenuChecked(bool)));
mPluginsMenu->addAction(pluginAction);

}

QPushButton *mPluginBox = new QPushButton("Plugins");
mPluginBox->setMenu(mPluginsMenu);
mainLayout->addWidget(mPluginBox);
mainLayout->addWidget(mExplorerView);
mainLayout->setContentsMargins(0, 0, 0, 0);

explorerContainer->setLayout(mainLayout);

QSplitter *splitterTop = static_cast<QSplitter*>(mTopWidget);
splitterTop->addWidget(explorerContainer);
splitterTop->addWidget(mThumbsManager->widget());
splitterTop->setStretchFactor(0, 0);
splitterTop->setStretchFactor(1, 1);
mThumbsManager->widget()->setVisible(true);
splitterTop->setGeometry(0, 0, 1066, 600);
}

void selectionChanged_slot(const QModelIndex &pNew, const QModelIndex &pOld) {
Node *oldNode = mExplorerModel->nodeFromIndex(pOld);
Node *newNode = mExplorerModel->nodeFromIndex(pNew);

if (oldNode->getGeneratorNode() != newNode->getGeneratorNode()) {
mThumbsManager->installPageGenerator(newNode->getGeneratorNode()->docGenerator()->thumbServicer());
}

newNode->getGeneratorNode()->docGenerator()->onNodeChanged(newNode, oldNode);
mThumbsManager->reload();
emit q->nodeChanged(newNode, oldNode);
}

void onPluginDynamiclyLoaded(QPluginLoader *newLoader) {
IDocumentGenerator *generatorCandidate = qobject_cast<IDocumentGenerator*>(newLoader->instance());
generatorCandidate->createNodeTree();
registerGenerator(generatorCandidate);
}

private:
DocumentManager *q;

QList<IDocumentGenerator *> mRegisteredGenerators;
ExplorerModel *mExplorerModel;
ExplorerView *mExplorerView;
QWidget *mTopWidget;
QPushButton *mPluginBox;
QMenu *mPluginsMenu;
DynPicturesManager *mThumbsManager;

friend class DocumentManager;
};


DocumentManager::DocumentManager(QObject *parent)
: QObject(parent)
, d(new DocumentManagerPrivate(this))
{
}

DocumentManager::~DocumentManager()
{
if (d) {
delete d;
}
}

void DocumentManager::registerGenerator(IDocumentGenerator *pGenerator)
{
d->registerGenerator(pGenerator);
}

void DocumentManager::print()
{
qDebug() << "DocumentmManager print";
}

void DocumentManager::setVisible (bool pVisible)
{
if (d->mTopWidget) {
d->mTopWidget->setVisible(pVisible);
}
}

QWidget *DocumentManager::topWidget() const
{
return d->mTopWidget;
}

void DocumentManager::actionMenuChecked(bool checked)
{
QAction *senderAction = qobject_cast<QAction*>(sender());
if (senderAction) {
Plugins::PInfoHandler hl = senderAction->data().value<Plugins::PInfoHandler>();
hl.setEnabled(checked);
hl.save();
if (checked && !Plugins::PluginManager::loadPlugin(hl)) {
qDebug() << "Plugin is not being loaded";
}

}
}

void DocumentManager::selectionChanged_slot(const QModelIndex &pNew, const QModelIndex &pOld)
{
d->selectionChanged_slot(pNew, pOld);
}

void DocumentManager::onPluginDynamiclyLoaded(QPluginLoader *newLoader)
{
d->onPluginDynamiclyLoaded(newLoader);
}

} //namespace Docs

60 changes: 60 additions & 0 deletions Cshnick_Qt_dynamicList/Documents/DocumentManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef DOCUMENTMANAGER_H
#define DOCUMENTMANAGER_H

#include "DocumentManager_global.h"

#include <QObject>
#include <QIcon>
#include <QtPlugin>
#include <QAction>
#include <QModelIndex>
#include "globals.h"
QT_BEGIN_NAMESPACE
class QPluginLoader;
QT_END_NAMESPACE

namespace Docs {

enum Role {
internalNameRole = 0
, displayNameRole
, displayIconRole
, CustomRole = 100
};

class IDocumentGenerator;
class CatalogNode;
class GeneratorNode;
class Node;

class DocumentManagerPrivate;
class DOCUMENTSSHARED_EXPORT DocumentManager : public QObject
{
Q_OBJECT

public:
DocumentManager(QObject *parent = 0);
~DocumentManager();

void registerGenerator(IDocumentGenerator *pGenerator);
void print();
void setVisible(bool pVisible);
QWidget *topWidget() const;

signals:
void nodeChanged(Node *pCurrent, Node *pPrevious);

private slots:
void actionMenuChecked(bool checked);
void selectionChanged_slot(const QModelIndex &pNew, const QModelIndex &pOld);
void onPluginDynamiclyLoaded(QPluginLoader *newLoader);

private:

DocumentManagerPrivate* d;

friend class DocumentManagerPrivate;
};

} //namespace Docs
#endif // DOCUMENTMANAGER_H
12 changes: 12 additions & 0 deletions Cshnick_Qt_dynamicList/Documents/DocumentManager_global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef DOCUMENTMANAGER_GLOBAL_H
#define DOCUMENTMANAGER_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(DOCUMENTS_LIBRARY)
# define DOCUMENTSSHARED_EXPORT Q_DECL_EXPORT
#else
# define DOCUMENTSSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // DOCUMENTMANAGER_GLOBAL_H
30 changes: 30 additions & 0 deletions Cshnick_Qt_dynamicList/Documents/Documents.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
TARGET = Documents
TEMPLATE = lib

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets core-private widgets-private

DEFINES += DOCUMENTS_LIBRARY

include($$PWD/../ThumbnailManager/ThumbnailManager.pri)
include($$PWD/../Globals/shared_lib.pri)

SOURCES += DocumentManager.cpp \
ExplorerModel.cpp \
Node.cpp \
ExplorerView.cpp \
IDocumentGenerator.cpp

HEADERS += DocumentManager.h\
DocumentManager_global.h \
ExplorerModel.h \
Node.h \
ExplorerView.h \
IDocumentGenerator.h

INCLUDEPATH += $$includeDependency(Globals) \
$$includeDependency(PluginManager) \
$$includeDependency(ThumbnailManager)

LIBS += $$libraryDependency(PluginManager)


Loading

0 comments on commit 3ef46ce

Please sign in to comment.