diff options
-rw-r--r-- | mappingeditdialog.cpp | 30 | ||||
-rw-r--r-- | mappingeditdialog.h | 27 | ||||
-rw-r--r-- | mappingeditwidget.cpp | 167 | ||||
-rw-r--r-- | mappingeditwidget.h | 50 | ||||
-rw-r--r-- | mappinginputdialog.cpp | 52 | ||||
-rw-r--r-- | mappinginputdialog.h | 30 | ||||
-rw-r--r-- | mappingtreeproxy.cpp | 25 | ||||
-rw-r--r-- | mappingtreeproxy.h | 28 | ||||
-rw-r--r-- | mappingtreeresultview.cpp | 24 | ||||
-rw-r--r-- | mappingtreeresultview.h | 26 | ||||
-rw-r--r-- | mappingtreewidget.cpp | 242 | ||||
-rw-r--r-- | mappingtreewidget.h | 84 | ||||
-rw-r--r-- | newpicsdialog.cpp | 1 | ||||
-rw-r--r-- | pictureswidget.cpp | 2 | ||||
-rw-r--r-- | pictureviewer2.cpp | 1 | ||||
-rw-r--r-- | shemov.pro | 14 |
16 files changed, 477 insertions, 326 deletions
diff --git a/mappingeditdialog.cpp b/mappingeditdialog.cpp new file mode 100644 index 0000000..68d80ab --- /dev/null +++ b/mappingeditdialog.cpp @@ -0,0 +1,30 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include <QPushButton> +#include <QHBoxLayout> +#include <QVBoxLayout> + +#include "mappingeditdialog.h" +#include "mappingeditwidget.h" + +MappingEditDialog::MappingEditDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ + mEditWidget = new MappingEditWidget; + mOk = new QPushButton(tr("Ok")); + connect(mOk, &QPushButton::clicked, this, &MappingEditDialog::accept); + mCancel = new QPushButton(tr("Cancel")); + connect(mCancel, &QPushButton::clicked, this, &MappingEditDialog::reject); + + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addStretch(); + buttonLayout->addWidget(mOk); + buttonLayout->addWidget(mCancel); + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(mEditWidget); + mainLayout->addLayout(buttonLayout); + setLayout(mainLayout); +} diff --git a/mappingeditdialog.h b/mappingeditdialog.h new file mode 100644 index 0000000..08510d8 --- /dev/null +++ b/mappingeditdialog.h @@ -0,0 +1,27 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef MAPPINGEDITDIALOG_H +#define MAPPINGEDITDIALOG_H + +#include <QDialog> + +class MappingEditWidget; + +class MappingEditDialog : public QDialog { + Q_OBJECT + public: + explicit MappingEditDialog(QWidget *parent, Qt::WindowFlags f = 0); + MappingEditWidget *editWidget() const { return mEditWidget; } + + private: + MappingEditWidget *mEditWidget; + QPushButton *mOk; + QPushButton *mCancel; +}; + +#endif // MAPPINGEDITDIALOG_H diff --git a/mappingeditwidget.cpp b/mappingeditwidget.cpp new file mode 100644 index 0000000..9ae13d5 --- /dev/null +++ b/mappingeditwidget.cpp @@ -0,0 +1,167 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include <QPushButton> +#include <QHBoxLayout> +#include <QVBoxLayout> +#include <QSettings> + +#include "mappingeditwidget.h" +#include "mappingtreewidget.h" +#include "mappingtreeresultview.h" +#include "mappingtreeview.h" +#include "mappingtreeproxy.h" + +MappingEditWidget::MappingEditWidget(QWidget *parent) : QWidget(parent){ + //the views + mMappingTree = new MappingTreeWidget; + mMappingResult = new MappingTreeResultView; + mResultModel = new MappingTreeResultModel(QStringList() << tr("Name") << tr("MappingId") << tr("ParentId") << tr("MyId"), this); + mMappingResult->setModel(mResultModel); + mMappingResult->setAlternatingRowColors(true); + mMappingResult->setColumnHidden(1, true); + mMappingResult->setColumnHidden(2, true); + mMappingResult->setColumnHidden(3, true); + connect(mMappingTree->mappingTreeView(), &MappingTreeView::addMapping, this, &MappingEditWidget::addMapping); + connect(mMappingTree->mappingTreeView(), &MappingTreeView::clearMappings, this, &MappingEditWidget::clearMapping); + connect(mMappingTree->mappingTreeView(), &MappingTreeView::shiftFocus, this, &MappingEditWidget::shiftFocusResult); + connect(mMappingResult, &MappingTreeResultView::shiftFocus, this, &MappingEditWidget::shiftFocusMappings); + connect(mMappingResult, &MappingTreeResultView::removeMapping, this, &MappingEditWidget::removeMapping); + connect(mMappingResult->selectionModel(), &QItemSelectionModel::currentChanged, this, &MappingEditWidget::resultSelectionChanged); + + //buttons + mAddMapping = new QPushButton(tr(">>")); + connect(mAddMapping, &QPushButton::clicked, this, &MappingEditWidget::addMapping); + mRemoveMapping = new QPushButton(tr("<<")); + connect(mRemoveMapping, &QPushButton::clicked, this, &MappingEditWidget::removeMapping); + mClearMapping = new QPushButton(tr("&Clear")); + connect(mClearMapping, &QPushButton::clicked, this, &MappingEditWidget::clearMapping); + mAddTree = new QPushButton(tr(">>>>")); + connect(mAddTree, &QPushButton::clicked, this, &MappingEditWidget::addTree); + + //layout + QHBoxLayout *mainLayout = new QHBoxLayout; + mainLayout->addWidget(mMappingTree); + QVBoxLayout *buttonLayout = new QVBoxLayout; + buttonLayout->addStretch(); + buttonLayout->addWidget(mAddMapping); + buttonLayout->addWidget(mRemoveMapping); + buttonLayout->addWidget(mClearMapping); + buttonLayout->addWidget(mAddTree); + buttonLayout->addStretch(); + mainLayout->addLayout(buttonLayout); + mainLayout->addWidget(mMappingResult); + setLayout(mainLayout); + mMappingTree->mappingTreeView()->setFocus(); +} + +void MappingEditWidget::addMapping(){ + MappingData selected = mMappingTree->selectedItem(); + mResultModel->addItem(selected); + mMappingResult->expandAll(); + mMappingTree->mappingTreeView()->setFocus(); +} + +void MappingEditWidget::addTree(){ + QList<MappingData> retval = mMappingTree->selectedTree(); + for(const MappingData &md : retval){ + mResultModel->addItem(md); + } + mMappingResult->expandAll(); + mMappingTree->mappingTreeView()->setFocus(); +} + +void MappingEditWidget::removeMapping(){ + QModelIndexList sel = mMappingResult->selectionModel()->selectedRows(); + if(sel.isEmpty()){ + return; + } + QModelIndex firstIdx = sel.first(); + if(firstIdx.isValid()){ + mResultModel->removeItem(firstIdx); + } + mMappingResult->expandAll(); + mMappingTree->mappingTreeView()->setFocus(); +} + +void MappingEditWidget::clearMapping(){ + mResultModel->clearData(); + mMappingTree->mappingTreeView()->setFocus(); +} + +void MappingEditWidget::setMappings(const QList<MappingData> &mappings){ + if(mappings.isEmpty()){ + return; + } + mResultModel->clearData(); + for(const MappingData &d : mappings){ + mResultModel->addItem(d); + } + mMappingResult->expandAll(); +} + +void MappingEditWidget::expandAllResults(){ + mMappingResult->expandAll(); +} + +void MappingEditWidget::shiftFocusResult(){ + mMappingResult->setFocus(); +} + +void MappingEditWidget::shiftFocusMappings(){ + mMappingTree->mappingTreeView()->setFocus(); +} + +void MappingEditWidget::saveMappings(QString where){ + const QList<MappingData> mappingData = model()->mappingData(); + QByteArray saveVal; + QDataStream in(&saveVal, QIODevice::WriteOnly); + for(const MappingData &md : mappingData){ + in << md; + } + QSettings s; + s.setValue(where, saveVal); +} + +void MappingEditWidget::loadMappings(QString from){ + QSettings s; + QByteArray val = s.value(from).toByteArray(); + QDataStream out(&val, QIODevice::ReadOnly); + MappingData md; + while(!out.atEnd()){ + out >> md; + model()->addItem(md); + } + expandAllResults(); +} + +void MappingEditWidget::resultSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous){ + Q_UNUSED(previous) + QStringList path; + QModelIndex c = current; + // gather elements from leaf to root + while(c != QModelIndex()){ + path << c.data().toString(); + c = c.parent(); + } + std::reverse(path.begin(), path.end()); + MappingTreeModel *srcModel = mMappingTree->mappingTreeModel(); + QModelIndex srcIdx = srcModel->rootIndex(); + // now search the source tree starting at the top, + // that's why we reversed the QStringList above + for(const QString &p : path){ + srcIdx = srcModel->find(p, 0, srcIdx); + if(!srcIdx.isValid()){ + return; + } + } + // yes, we have a valid index. Map it to the Proxy... + QModelIndex real = mMappingTree->mappingTreeProxy()->mapFromSource(srcIdx); + // select it and make sure it's visible! + mMappingTree->mappingTreeView()->selectionModel()->select(real, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + mMappingTree->mappingTreeView()->scrollTo(real, QAbstractItemView::PositionAtCenter); +} diff --git a/mappingeditwidget.h b/mappingeditwidget.h new file mode 100644 index 0000000..ce5ee86 --- /dev/null +++ b/mappingeditwidget.h @@ -0,0 +1,50 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef MAPPINGEDITWIDGET_H +#define MAPPINGEDITWIDGET_H + +#include <QWidget> + +#include "mappingtreemodel.h" + +class QPushButton; +class MappingTreeResultModel; +class MappingTreeResultView; +class MappingTreeWidget; + +class MappingEditWidget : public QWidget { + Q_OBJECT + public: + explicit MappingEditWidget(QWidget *parent = 0); + MappingTreeResultModel *model() const { return mResultModel; } + MappingTreeWidget *treeWidget() const { return mMappingTree; } + + public slots: + void addMapping(); + void addTree(); + void removeMapping(); + void clearMapping(); + void setMappings(const QList<MappingData> &mappings); + void expandAllResults(); + void shiftFocusResult(); + void shiftFocusMappings(); + void saveMappings(QString where); + void loadMappings(QString from); + void resultSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous); + + private: + MappingTreeWidget *mMappingTree; + MappingTreeResultView *mMappingResult; + MappingTreeResultModel *mResultModel; + QPushButton *mAddMapping; + QPushButton *mRemoveMapping; + QPushButton *mClearMapping; + QPushButton *mAddTree; +}; + +#endif // MAPPINGEDITWIDGET_H diff --git a/mappinginputdialog.cpp b/mappinginputdialog.cpp new file mode 100644 index 0000000..a9573d5 --- /dev/null +++ b/mappinginputdialog.cpp @@ -0,0 +1,52 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include <QPushButton> +#include <QCheckBox> +#include <QLineEdit> +#include <QHBoxLayout> +#include <QVBoxLayout> +#include <QLabel> + +#include "mappinginputdialog.h" + +MappingInputDialog::MappingInputDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ + mOk = new QPushButton(tr("Ok")); + connect(mOk, &QPushButton::clicked, this, &MappingInputDialog::accept); + mCancel = new QPushButton(tr("Cancel")); + connect(mCancel, &QPushButton::clicked, this, &MappingInputDialog::reject); + mIsRoot = new QCheckBox(tr("Create root item")); + mEditor = new QLineEdit; + + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addStretch(); + buttonLayout->addWidget(mOk); + buttonLayout->addWidget(mCancel); + + QVBoxLayout* inputLayout = new QVBoxLayout; + QLabel *caption = new QLabel(tr("Enter mapping name")); + inputLayout->addWidget(caption); + inputLayout->addWidget(mEditor); + + QHBoxLayout *cbLayout = new QHBoxLayout; + cbLayout->addStretch(); + cbLayout->addWidget(mIsRoot); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(inputLayout); + mainLayout->addLayout(cbLayout); + mainLayout->addLayout(buttonLayout); + setLayout(mainLayout); +} + +QString MappingInputDialog::mappingName() const{ + return mEditor->text(); +} + +bool MappingInputDialog::createRoot() const { + return mIsRoot->checkState() == Qt::Checked; +} diff --git a/mappinginputdialog.h b/mappinginputdialog.h new file mode 100644 index 0000000..993d295 --- /dev/null +++ b/mappinginputdialog.h @@ -0,0 +1,30 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef MAPPINGINPUTDIALOG_H +#define MAPPINGINPUTDIALOG_H + +#include <QDialog> + +class QLineEdit; +class QCheckBox; + +class MappingInputDialog : public QDialog { + Q_OBJECT + public: + explicit MappingInputDialog(QWidget *parent, Qt::WindowFlags f = 0); + QString mappingName() const; + bool createRoot() const; + + private: + QPushButton *mOk; + QPushButton *mCancel; + QLineEdit *mEditor; + QCheckBox *mIsRoot; + +}; +#endif // MAPPINGINPUTDIALOG_H diff --git a/mappingtreeproxy.cpp b/mappingtreeproxy.cpp new file mode 100644 index 0000000..077d72a --- /dev/null +++ b/mappingtreeproxy.cpp @@ -0,0 +1,25 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include "mappingtreeproxy.h" +#include "mappingtreemodel.h" + +MappingTreeProxy::MappingTreeProxy(QObject *parent) : QSortFilterProxyModel(parent) {} + +void MappingTreeProxy::setFilter(const QString &filter){ + mFilter = QRegExp(filter); + invalidateFilter(); +} + +bool MappingTreeProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const{ + if(mFilter.isEmpty()){ + return true; + } + QModelIndex nameIdx = sourceModel()->index(sourceRow, MappingTreeModel::Name, sourceParent); + MappingTreeModel *model = qobject_cast<MappingTreeModel*>(sourceModel()); + return model->matchRecursive(nameIdx, mFilter); +} diff --git a/mappingtreeproxy.h b/mappingtreeproxy.h new file mode 100644 index 0000000..0dd7c8d --- /dev/null +++ b/mappingtreeproxy.h @@ -0,0 +1,28 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef MAPPINGTREEPROXY_H +#define MAPPINGTREEPROXY_H + +#include <QSortFilterProxyModel> + +class MappingTreeProxy : public QSortFilterProxyModel { + Q_OBJECT + public: + explicit MappingTreeProxy(QObject *parent = 0); + + public slots: + void setFilter(const QString &filter); + + protected: + virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + + private: + QRegExp mFilter; +}; + +#endif // MAPPINGTREEPROXY_H diff --git a/mappingtreeresultview.cpp b/mappingtreeresultview.cpp new file mode 100644 index 0000000..f7d4d0b --- /dev/null +++ b/mappingtreeresultview.cpp @@ -0,0 +1,24 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include <QKeyEvent> + +#include "mappingtreeresultview.h" + +MappingTreeResultView::MappingTreeResultView(QWidget *parent) : SmTreeView(parent) {} + +void MappingTreeResultView::keyPressEvent(QKeyEvent *e){ + if(e->key() == Qt::Key_Left && (e->modifiers() & Qt::ControlModifier)){ + clearFocus(); + emit shiftFocus(); + return; + } + if(e->key() == Qt::Key_Left){ + emit removeMapping(); + } + SmTreeView::keyPressEvent(e); +} diff --git a/mappingtreeresultview.h b/mappingtreeresultview.h new file mode 100644 index 0000000..c999b77 --- /dev/null +++ b/mappingtreeresultview.h @@ -0,0 +1,26 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef MAPPINGTREERESULTVIEW_H +#define MAPPINGTREERESULTVIEW_H + +#include "smtreeview.h" + +class MappingTreeResultView : public SmTreeView { + Q_OBJECT + public: + explicit MappingTreeResultView(QWidget *parent = 0); + + signals: + void shiftFocus(); + void removeMapping(); + + protected: + virtual void keyPressEvent(QKeyEvent *e); +}; + +#endif // MAPPINGTREERESULTVIEW_H diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index cbd24b1..7a5675a 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -26,6 +26,8 @@ #include "mappingtreewidget.h" #include "mappingtreemodel.h" #include "mappingtreeview.h" +#include "mappingtreeproxy.h" +#include "mappinginputdialog.h" #include "smglobals.h" MappingTreeWidget::MappingTreeWidget(QWidget *parent) : QWidget(parent){ @@ -325,243 +327,3 @@ const QModelIndex MappingTreeWidget::selected() const{ } return sel.first(); } - - - - -MappingTreeResultView::MappingTreeResultView(QWidget *parent) : SmTreeView(parent) { - setAlternatingRowColors(true); - setPalette(qApp->palette()); -} - -void MappingTreeResultView::keyPressEvent(QKeyEvent *e){ - if(e->key() == Qt::Key_Left && (e->modifiers() & Qt::ControlModifier)){ - clearFocus(); - emit shiftFocus(); - return; - } - if(e->key() == Qt::Key_Left){ - emit removeMapping(); - } - SmTreeView::keyPressEvent(e); -} - -MappingEditWidget::MappingEditWidget(QWidget *parent) : QWidget(parent){ - //the views - mMappingTree = new MappingTreeWidget; - mMappingResult = new MappingTreeResultView; - mResultModel = new MappingTreeResultModel(QStringList() << tr("Name") << tr("MappingId") << tr("ParentId") << tr("MyId"), this); - mMappingResult->setModel(mResultModel); - mMappingResult->setAlternatingRowColors(true); - mMappingResult->setColumnHidden(1, true); - mMappingResult->setColumnHidden(2, true); - mMappingResult->setColumnHidden(3, true); - connect(mMappingTree->mappingTreeView(), &MappingTreeView::addMapping, this, &MappingEditWidget::addMapping); - connect(mMappingTree->mappingTreeView(), &MappingTreeView::clearMappings, this, &MappingEditWidget::clearMapping); - connect(mMappingTree->mappingTreeView(), &MappingTreeView::shiftFocus, this, &MappingEditWidget::shiftFocusResult); - connect(mMappingResult, &MappingTreeResultView::shiftFocus, this, &MappingEditWidget::shiftFocusMappings); - connect(mMappingResult, &MappingTreeResultView::removeMapping, this, &MappingEditWidget::removeMapping); - connect(mMappingResult->selectionModel(), &QItemSelectionModel::currentChanged, this, &MappingEditWidget::resultSelectionChanged); - - //buttons - mAddMapping = new QPushButton(tr(">>")); - connect(mAddMapping, &QPushButton::clicked, this, &MappingEditWidget::addMapping); - mRemoveMapping = new QPushButton(tr("<<")); - connect(mRemoveMapping, &QPushButton::clicked, this, &MappingEditWidget::removeMapping); - mClearMapping = new QPushButton(tr("&Clear")); - connect(mClearMapping, &QPushButton::clicked, this, &MappingEditWidget::clearMapping); - mAddTree = new QPushButton(tr(">>>>")); - connect(mAddTree, &QPushButton::clicked, this, &MappingEditWidget::addTree); - - //layout - QHBoxLayout *mainLayout = new QHBoxLayout; - mainLayout->addWidget(mMappingTree); - QVBoxLayout *buttonLayout = new QVBoxLayout; - buttonLayout->addStretch(); - buttonLayout->addWidget(mAddMapping); - buttonLayout->addWidget(mRemoveMapping); - buttonLayout->addWidget(mClearMapping); - buttonLayout->addWidget(mAddTree); - buttonLayout->addStretch(); - mainLayout->addLayout(buttonLayout); - mainLayout->addWidget(mMappingResult); - setLayout(mainLayout); - mMappingTree->mappingTreeView()->setFocus(); -} - -void MappingEditWidget::addMapping(){ - MappingData selected = mMappingTree->selectedItem(); - mResultModel->addItem(selected); - mMappingResult->expandAll(); - mMappingTree->mappingTreeView()->setFocus(); -} - -void MappingEditWidget::addTree(){ - QList<MappingData> retval = mMappingTree->selectedTree(); - for(const MappingData &md : retval){ - mResultModel->addItem(md); - } - mMappingResult->expandAll(); - mMappingTree->mappingTreeView()->setFocus(); -} - -void MappingEditWidget::removeMapping(){ - QModelIndexList sel = mMappingResult->selectionModel()->selectedRows(); - if(sel.isEmpty()){ - return; - } - QModelIndex firstIdx = sel.first(); - if(firstIdx.isValid()){ - mResultModel->removeItem(firstIdx); - } - mMappingResult->expandAll(); - mMappingTree->mappingTreeView()->setFocus(); -} - -void MappingEditWidget::clearMapping(){ - mResultModel->clearData(); - mMappingTree->mappingTreeView()->setFocus(); -} - -void MappingEditWidget::setMappings(const QList<MappingData> &mappings){ - if(mappings.isEmpty()){ - return; - } - mResultModel->clearData(); - for(const MappingData &d : mappings){ - mResultModel->addItem(d); - } - mMappingResult->expandAll(); -} - -void MappingEditWidget::expandAllResults(){ - mMappingResult->expandAll(); -} - -void MappingEditWidget::shiftFocusResult(){ - mMappingResult->setFocus(); -} - -void MappingEditWidget::shiftFocusMappings(){ - mMappingTree->mappingTreeView()->setFocus(); -} - -void MappingEditWidget::saveMappings(QString where){ - const QList<MappingData> mappingData = model()->mappingData(); - QByteArray saveVal; - QDataStream in(&saveVal, QIODevice::WriteOnly); - for(const MappingData &md : mappingData){ - in << md; - } - QSettings s; - s.setValue(where, saveVal); -} - -void MappingEditWidget::loadMappings(QString from){ - QSettings s; - QByteArray val = s.value(from).toByteArray(); - QDataStream out(&val, QIODevice::ReadOnly); - MappingData md; - while(!out.atEnd()){ - out >> md; - model()->addItem(md); - } - expandAllResults(); -} - -void MappingEditWidget::resultSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous){ - Q_UNUSED(previous) - QStringList path; - QModelIndex c = current; - // gather elements from leaf to root - while(c != QModelIndex()){ - path << c.data().toString(); - c = c.parent(); - } - std::reverse(path.begin(), path.end()); - MappingTreeModel *srcModel = mMappingTree->mappingTreeModel(); - QModelIndex srcIdx = srcModel->rootIndex(); - // now search the source tree starting at the top, - // that's why we reversed the QStringList above - for(const QString &p : path){ - srcIdx = srcModel->find(p, 0, srcIdx); - if(!srcIdx.isValid()){ - return; - } - } - // yes, we have a valid index. Map it to the Proxy... - QModelIndex real = mMappingTree->mappingTreeProxy()->mapFromSource(srcIdx); - // select it and make sure it's visible! - mMappingTree->mappingTreeView()->selectionModel()->select(real, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); - mMappingTree->mappingTreeView()->scrollTo(real, QAbstractItemView::PositionAtCenter); -} - -MappingInputDialog::MappingInputDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ - mOk = new QPushButton(tr("Ok")); - connect(mOk, &QPushButton::clicked, this, &MappingInputDialog::accept); - mCancel = new QPushButton(tr("Cancel")); - connect(mCancel, &QPushButton::clicked, this, &MappingInputDialog::reject); - mIsRoot = new QCheckBox(tr("Create root item")); - mEditor = new QLineEdit; - - QHBoxLayout *buttonLayout = new QHBoxLayout; - buttonLayout->addStretch(); - buttonLayout->addWidget(mOk); - buttonLayout->addWidget(mCancel); - - QVBoxLayout* inputLayout = new QVBoxLayout; - QLabel *caption = new QLabel(tr("Enter mapping name")); - inputLayout->addWidget(caption); - inputLayout->addWidget(mEditor); - - QHBoxLayout *cbLayout = new QHBoxLayout; - cbLayout->addStretch(); - cbLayout->addWidget(mIsRoot); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addLayout(inputLayout); - mainLayout->addLayout(cbLayout); - mainLayout->addLayout(buttonLayout); - setLayout(mainLayout); -} - -QString MappingInputDialog::mappingName() const{ - return mEditor->text(); -} - -bool MappingInputDialog::createRoot() const { - return mIsRoot->checkState() == Qt::Checked; -} - -MappingEditDialog::MappingEditDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ - mEditWidget = new MappingEditWidget; - mOk = new QPushButton(tr("Ok")); - connect(mOk, &QPushButton::clicked, this, &MappingEditDialog::accept); - mCancel = new QPushButton(tr("Cancel")); - connect(mCancel, &QPushButton::clicked, this, &MappingEditDialog::reject); - - QHBoxLayout *buttonLayout = new QHBoxLayout; - buttonLayout->addStretch(); - buttonLayout->addWidget(mOk); - buttonLayout->addWidget(mCancel); - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(mEditWidget); - mainLayout->addLayout(buttonLayout); - setLayout(mainLayout); -} - -MappingTreeProxy::MappingTreeProxy(QObject *parent) : QSortFilterProxyModel(parent) {} - -void MappingTreeProxy::setFilter(const QString &filter){ - mFilter = QRegExp(filter); - invalidateFilter(); -} - -bool MappingTreeProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const{ - if(mFilter.isEmpty()){ - return true; - } - QModelIndex nameIdx = sourceModel()->index(sourceRow, MappingTreeModel::Name, sourceParent); - MappingTreeModel *model = qobject_cast<MappingTreeModel*>(sourceModel()); - return model->matchRecursive(nameIdx, mFilter); -} diff --git a/mappingtreewidget.h b/mappingtreewidget.h index d5c431f..99f7c17 100644 --- a/mappingtreewidget.h +++ b/mappingtreewidget.h @@ -77,89 +77,5 @@ class MappingTreeWidget : public QWidget { -class MappingTreeResultView : public SmTreeView { - Q_OBJECT - public: - explicit MappingTreeResultView(QWidget *parent = 0); - - signals: - void shiftFocus(); - void removeMapping(); - - protected: - virtual void keyPressEvent(QKeyEvent *e); -}; - -class MappingEditWidget : public QWidget { - Q_OBJECT - public: - explicit MappingEditWidget(QWidget *parent = 0); - MappingTreeResultModel *model() const { return mResultModel; } - MappingTreeWidget *treeWidget() const { return mMappingTree; } - - public slots: - void addMapping(); - void addTree(); - void removeMapping(); - void clearMapping(); - void setMappings(const QList<MappingData> &mappings); - void expandAllResults(); - void shiftFocusResult(); - void shiftFocusMappings(); - void saveMappings(QString where); - void loadMappings(QString from); - void resultSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous); - - private: - MappingTreeWidget *mMappingTree; - MappingTreeResultView *mMappingResult; - MappingTreeResultModel *mResultModel; - QPushButton *mAddMapping; - QPushButton *mRemoveMapping; - QPushButton *mClearMapping; - QPushButton *mAddTree; -}; - -class MappingInputDialog : public QDialog { - Q_OBJECT - public: - explicit MappingInputDialog(QWidget *parent, Qt::WindowFlags f = 0); - QString mappingName() const; - bool createRoot() const; - - private: - QPushButton *mOk; - QPushButton *mCancel; - QLineEdit *mEditor; - QCheckBox *mIsRoot; - -}; - -class MappingEditDialog : public QDialog { - Q_OBJECT - public: - explicit MappingEditDialog(QWidget *parent, Qt::WindowFlags f = 0); - MappingEditWidget *editWidget() const { return mEditWidget; } - - private: - MappingEditWidget *mEditWidget; - QPushButton *mOk; - QPushButton *mCancel; -}; - -class MappingTreeProxy : public QSortFilterProxyModel { - Q_OBJECT - public: - explicit MappingTreeProxy(QObject *parent = 0); - - public slots: - void setFilter(const QString &filter); - - protected: - virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; - - private: - QRegExp mFilter; -}; #endif // MAPPINGTREEWIDGET_H diff --git a/newpicsdialog.cpp b/newpicsdialog.cpp index f5e5697..b972013 100644 --- a/newpicsdialog.cpp +++ b/newpicsdialog.cpp @@ -26,6 +26,7 @@ #include "mappingtreewidget.h" #include "mappingtreemodel.h" #include "mappingtreeview.h" +#include "mappingeditwidget.h" #include "delegates.h" #include "smglobals.h" diff --git a/pictureswidget.cpp b/pictureswidget.cpp index 0d4c49e..157dd81 100644 --- a/pictureswidget.cpp +++ b/pictureswidget.cpp @@ -17,6 +17,8 @@ #include "pictureswidget.h" #include "picturelistview.h" #include "mappingtreewidget.h" +#include "mappingeditwidget.h" +#include "mappingeditdialog.h" #include "delegates.h" #include "smglobals.h" #include "helper.h" diff --git a/pictureviewer2.cpp b/pictureviewer2.cpp index 5b0c8b0..778e091 100644 --- a/pictureviewer2.cpp +++ b/pictureviewer2.cpp @@ -49,6 +49,7 @@ #include "smglobals.h" #include "mappingtreemodel.h" #include "mappingtreewidget.h" +#include "mappingeditwidget.h" #include "smtreeitem.h" #include "configurationdialog.h" #include "newpicsdialog.h" @@ -50,7 +50,12 @@ SOURCES = main.cpp \ sminputdialog.cpp \ editfiledialog.cpp \ picturelistview.cpp \ - mappingtreeview.cpp + mappingtreeview.cpp \ + mappingtreeresultview.cpp \ + mappingeditwidget.cpp \ + mappinginputdialog.cpp \ + mappingeditdialog.cpp \ + mappingtreeproxy.cpp HEADERS = \ shemov.h \ helper.h \ @@ -95,7 +100,12 @@ HEADERS = \ sminputdialog.h \ editfiledialog.h \ picturelistview.h \ - mappingtreeview.h + mappingtreeview.h \ + mappingtreeresultview.h \ + mappingeditwidget.h \ + mappinginputdialog.h \ + mappingeditdialog.h \ + mappingtreeproxy.h LIBS += -lmagic -lXfixes -lX11 -lMagick++-6.Q16HDRI INCLUDEPATH += /usr/include/ImageMagick-6/ RESOURCES = shemov.qrc |