implementation of reordering (outline)
This commit is contained in:
@@ -46,6 +46,42 @@
|
||||
#include <QMenu>
|
||||
|
||||
|
||||
QDataStream& operator<<(QDataStream& out, cPart* const &rhs)
|
||||
{
|
||||
out.writeRawData(reinterpret_cast<const char*>(&rhs), sizeof(rhs));
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream& in, cPart* &rhs)
|
||||
{
|
||||
in.readRawData(reinterpret_cast<char*>(&rhs), sizeof(rhs));
|
||||
return in;
|
||||
}
|
||||
|
||||
QDataStream& operator<<(QDataStream& out, cChapter* const &rhs)
|
||||
{
|
||||
out.writeRawData(reinterpret_cast<const char*>(&rhs), sizeof(rhs));
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream& in, cChapter* &rhs)
|
||||
{
|
||||
in.readRawData(reinterpret_cast<char*>(&rhs), sizeof(rhs));
|
||||
return in;
|
||||
}
|
||||
|
||||
QDataStream& operator<<(QDataStream& out, cScene* const &rhs)
|
||||
{
|
||||
out.writeRawData(reinterpret_cast<const char*>(&rhs), sizeof(rhs));
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream& in, cScene* &rhs)
|
||||
{
|
||||
in.readRawData(reinterpret_cast<char*>(&rhs), sizeof(rhs));
|
||||
return in;
|
||||
}
|
||||
|
||||
cMainWindow::cMainWindow(cSplashScreen *lpSplashScreen, QTranslator *lpTranslator, QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::cMainWindow),
|
||||
@@ -72,6 +108,10 @@ cMainWindow::cMainWindow(cSplashScreen *lpSplashScreen, QTranslator *lpTranslato
|
||||
m_lpOldTextEdit(0),
|
||||
m_lpOptionsDialog(0)
|
||||
{
|
||||
qRegisterMetaTypeStreamOperators<cPart*>("cPart*");
|
||||
qRegisterMetaTypeStreamOperators<cChapter*>("cChapter*");
|
||||
qRegisterMetaTypeStreamOperators<cScene*>("cScene*");
|
||||
|
||||
initUI();
|
||||
createActions();
|
||||
onLanguageChanged();
|
||||
@@ -229,6 +269,8 @@ void cMainWindow::createActions()
|
||||
connect(ui->m_lpPlaceList, &QTreeView::customContextMenuRequested, this, &cMainWindow::onPlaceContextMenu);
|
||||
connect(ui->m_lpObjectList, &QTreeView::customContextMenuRequested, this, &cMainWindow::onObjectContextMenu);
|
||||
connect(ui->m_lpRechercheList, &QTreeView::customContextMenuRequested, this, &cMainWindow::onRechercheContextMenu);
|
||||
|
||||
connect(ui->m_lpOutlineList, &cTreeView::dropped, this, &cMainWindow::onOutlineDropped);
|
||||
}
|
||||
|
||||
void cMainWindow::createFileActions()
|
||||
@@ -953,6 +995,48 @@ void cMainWindow::onFontComboBoxLostFocus(cFontComboBox* /*lpComboBox*/)
|
||||
{
|
||||
}
|
||||
|
||||
void cMainWindow::onOutlineDropped(cTreeView* /*lpTreeView*/, QModelIndex from, QModelIndex /*to*/)
|
||||
{
|
||||
qint32 parts = m_lpOutlineModel->rowCount(QModelIndex());
|
||||
|
||||
for(qint32 part = 0;part < parts;part++)
|
||||
{
|
||||
QModelIndex partIndex = m_lpOutlineModel->index(part, 0, QModelIndex());
|
||||
cPart* lpPart = qvariant_cast<cPart*>(m_lpOutlineModel->itemFromIndex(partIndex)->data());
|
||||
qint32 chapters = m_lpOutlineModel->rowCount(partIndex);
|
||||
|
||||
if(partIndex != from)
|
||||
lpPart->setSortOrder(part);
|
||||
|
||||
for(qint32 chapter = 0;chapter < chapters;chapter++)
|
||||
{
|
||||
QModelIndex chapterIndex = m_lpOutlineModel->index(chapter, 0, partIndex);
|
||||
cChapter* lpChapter = qvariant_cast<cChapter*>(m_lpOutlineModel->itemFromIndex(chapterIndex)->data());
|
||||
qint32 scenes = m_lpOutlineModel->rowCount(chapterIndex);
|
||||
|
||||
if(chapterIndex != from)
|
||||
{
|
||||
lpChapter->setPart(lpPart);
|
||||
lpChapter->setSortOrder(chapter);
|
||||
}
|
||||
|
||||
lpChapter = lpChapter;
|
||||
for(qint32 scene = 0;scene < scenes;scene++)
|
||||
{
|
||||
QModelIndex sceneIndex = m_lpOutlineModel->index(scene, 0, chapterIndex);
|
||||
cScene* lpScene = qvariant_cast<cScene*>(m_lpOutlineModel->itemFromIndex(sceneIndex)->data());
|
||||
|
||||
if(sceneIndex != from)
|
||||
{
|
||||
lpScene->setChapter(lpChapter);
|
||||
lpScene->setSortOrder(scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
somethingChanged();
|
||||
}
|
||||
|
||||
void cMainWindow::onMainTabCurrentChanged(int /*index*/)
|
||||
{
|
||||
if(m_bUpdatingTab)
|
||||
|
||||
@@ -258,6 +258,13 @@ public slots:
|
||||
\param lpComboBox
|
||||
*/
|
||||
void onFontComboBoxLostFocus(cFontComboBox* lpComboBox);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn onOutlineDropped
|
||||
\param lpTreeView
|
||||
*/
|
||||
void onOutlineDropped(cTreeView* lpTreeView, QModelIndex from, QModelIndex to);
|
||||
private slots:
|
||||
/*!
|
||||
\brief
|
||||
|
||||
+18
-2
@@ -28,7 +28,7 @@
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>4</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_lpMainToolBoxOutline">
|
||||
<property name="geometry">
|
||||
@@ -44,13 +44,22 @@
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeView" name="m_lpOutlineList">
|
||||
<widget class="cTreeView" name="m_lpOutlineList">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="defaultDropAction">
|
||||
<enum>Qt::MoveAction</enum>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@@ -311,6 +320,13 @@
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>cTreeView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>ctreeview.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -788,6 +788,7 @@ bool cStoryBook::updateDatabase01()
|
||||
{
|
||||
QSqlQuery query;
|
||||
|
||||
query.exec("DROP TABLE config_old;");
|
||||
if(!query.exec("ALTER TABLE config RENAME TO config_old;"))
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
|
||||
@@ -5,6 +5,14 @@
|
||||
|
||||
#include "ctreeview.h"
|
||||
|
||||
#include "cpart.h"
|
||||
#include "cchapter.h"
|
||||
#include "cscene.h"
|
||||
|
||||
#include <QDropEvent>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
|
||||
cTreeView::cTreeView(QWidget* parent) :
|
||||
QTreeView(parent)
|
||||
{
|
||||
@@ -21,3 +29,40 @@ void cTreeView::focusOutEvent(QFocusEvent* event)
|
||||
lostFocus(this);
|
||||
QTreeView::focusOutEvent(event);
|
||||
}
|
||||
|
||||
qint16 level(QModelIndex index)
|
||||
{
|
||||
QModelIndex tmp = index;
|
||||
qint16 level = 0;
|
||||
|
||||
while(tmp.parent().isValid())
|
||||
{
|
||||
level++;
|
||||
tmp = tmp.parent();
|
||||
}
|
||||
return(level);
|
||||
}
|
||||
|
||||
void cTreeView::dropEvent(QDropEvent* event)
|
||||
{
|
||||
QModelIndex fromIndex = selectedIndexes()[0];
|
||||
QModelIndex droppedIndex = indexAt(event->pos());
|
||||
|
||||
qint16 fromLevel = level(fromIndex);
|
||||
qint16 droppedLevel = level(droppedIndex);
|
||||
|
||||
// QStandardItemModel* lpModel = (QStandardItemModel*)this->model();
|
||||
// QStandardItem* lpToItem = lpModel->itemFromIndex(droppedIndex);
|
||||
|
||||
// if(droppedLevel < fromLevel-1)
|
||||
// return;
|
||||
// else if(droppedLevel > fromLevel)
|
||||
// return;
|
||||
|
||||
if(fromLevel != droppedLevel)
|
||||
return;
|
||||
|
||||
QTreeView::dropEvent(event);
|
||||
QModelIndex toIndex = selectedIndexes()[0];
|
||||
dropped(this, fromIndex, toIndex);
|
||||
}
|
||||
|
||||
+14
@@ -44,6 +44,13 @@ signals:
|
||||
\param lpTreeView
|
||||
*/
|
||||
void lostFocus(cTreeView* lpTreeView);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn dropped
|
||||
\param lpTreeView
|
||||
*/
|
||||
void dropped(cTreeView* lpTreeView, QModelIndex from, QModelIndex to);
|
||||
|
||||
protected:
|
||||
/*!
|
||||
@@ -60,6 +67,13 @@ protected:
|
||||
\param event
|
||||
*/
|
||||
void focusOutEvent(QFocusEvent *event);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn dropEvent
|
||||
\param event
|
||||
*/
|
||||
void dropEvent(QDropEvent *event);
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(cTreeView*)
|
||||
|
||||
Reference in New Issue
Block a user