Skip to content

Commit

Permalink
Implement ability to activate document's version links
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkanovikov committed Dec 12, 2022
1 parent 488c4fd commit 82fd418
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 7 deletions.
51 changes: 46 additions & 5 deletions src/core/management_layer/content/project/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ ProjectManager::ProjectManager(QObject* _parent, QWidget* _parentWidget,
continue;
}

QString documentName = screenplay->informationModel()->name();
auto documentName = screenplay->informationModel()->name();
if (const auto screenplayItem
= d->projectStructureModel->itemForUuid(screenplay->document()->uuid());
screenplayItem->name() != tr("Screenplay")) {
Expand Down Expand Up @@ -3495,27 +3495,68 @@ void ProjectManager::activateLink(const QUuid& _documentUuid, const QModelIndex&
return;
}

const auto sourceIndex = d->projectStructureModel->indexForItem(item);
auto sourceIndex = d->projectStructureModel->indexForItem(item);
constexpr int invalidVersionIndex = -1;
int versionIndex = invalidVersionIndex;
if (!sourceIndex.isValid()) {
return;
const auto parent = item->parent();
for (int childIndex = 0; childIndex < parent->childCount(); ++childIndex) {
const auto childItem = parent->childAt(childIndex);
if (childItem->versions().contains(item)) {
sourceIndex = d->projectStructureModel->indexForItem(childItem);
versionIndex = childItem->versions().indexOf(item) + 1;
break;
}
}

if (!sourceIndex.isValid() || versionIndex == invalidVersionIndex) {
return;
}
}

const auto itemIndex = d->projectStructureProxyModel->mapFromSource(sourceIndex);
if (!itemIndex.isValid()) {
return;
}

//
// Откроем ссылку на элемент
//
const auto withActivation = false;
//
// ... если работаем в двухпанельном режиме, то открываем её во второй панели, при этом
// активируем вторую панель для установки в неё целевого документа без активации, чтобы это
// прошло незаметно для пользователя
//
if (d->view.right->isVisible()) {
d->switchViews(false);
d->switchViews(withActivation);
}
d->navigator->setCurrentIndex(itemIndex);
//
// ... если нужно, активируем заданную версию
//
if (versionIndex != invalidVersionIndex) {
d->view.active->setCurrentVersion(versionIndex);
}
//
// ... если работаем с текущей версией, но редактор находится на другой, возвращаемся к текущей
//
else if (d->view.active->currentVersion() > 0) {
d->view.active->setCurrentVersion(0);
}
//
// ... фокусируем в представлении элемент с заданным индексом
//
if (d->view.active == d->view.left) {
d->pluginsBuilder.setViewCurrentIndex(_index, d->view.activeViewMimeType);
} else {
d->pluginsBuilder.setSecondaryViewCurrentIndex(_index, d->view.activeViewMimeType);
}
//
// ... возвращаем активность на исходную панель
//
if (d->view.right->isVisible()) {
d->switchViews(false);
d->switchViews(withActivation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ void AudioplayTextManager::resetModels()

void AudioplayTextManager::reconfigure(const QStringList& _changedSettingsKeys)
{
d->view->reconfigure(_changedSettingsKeys);
for (const auto& view : std::as_const(d->allViews)) {
if (!view.view.isNull()) {
view.view->reconfigure(_changedSettingsKeys);
}
}
}

void AudioplayTextManager::bind(IDocumentManager* _manager)
Expand Down
2 changes: 1 addition & 1 deletion src/core/management_layer/plugins/character_dialogues
Submodule character_dialogues updated from 1f5f2c to c1ae54
10 changes: 10 additions & 0 deletions src/corelib/ui/widgets/tree/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ QModelIndexList Tree::selectedIndexes() const
return d->tree->selectionModel()->selectedIndexes();
}

void Tree::clearSelection()
{
d->tree->clearSelection();
}

void Tree::setExpandsOnDoubleClick(bool _expand)
{
d->tree->setExpandsOnDoubleClick(_expand);
Expand Down Expand Up @@ -247,6 +252,11 @@ QHeaderView* Tree::headerView() const
return d->tree->header();
}

QSize Tree::viewportSizeHint() const
{
return d->tree->viewportSizeHint();
}

void Tree::setEditTriggers(QAbstractItemView::EditTriggers _triggers)
{
d->tree->setEditTriggers(_triggers);
Expand Down
10 changes: 10 additions & 0 deletions src/corelib/ui/widgets/tree/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class CORE_LIBRARY_EXPORT Tree : public Widget
*/
QModelIndexList selectedIndexes() const;

/**
* @brief Очистить выделение
*/
void clearSelection();

/**
* @brief Задать возможность раскрывать узлы дерева двойным кликом
*/
Expand Down Expand Up @@ -141,6 +146,11 @@ class CORE_LIBRARY_EXPORT Tree : public Widget
void setHeader(QHeaderView* _headerView);
QHeaderView* headerView() const;

/**
* @brief Получить размер вьюпорта
*/
QSize viewportSizeHint() const;

/**
* @brief Задать действия приводящие к редактированию элементов дерева
*/
Expand Down
5 changes: 5 additions & 0 deletions src/corelib/ui/widgets/tree/tree_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ void TreeView::setAutoAdjustSize(bool _auto)
d->adjustSizeAutomatically = _auto;
}

QSize TreeView::viewportSizeHint() const
{
return QTreeView::viewportSizeHint();
}

void TreeView::restoreState(const QVariant& _state)
{
std::function<void(const QDomElement&, const QModelIndex&)> readItem;
Expand Down
5 changes: 5 additions & 0 deletions src/corelib/ui/widgets/tree/tree_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class CORE_LIBRARY_EXPORT TreeView : public QTreeView
*/
void setAutoAdjustSize(bool _auto);

/**
* @brief Переопределяем метод, чтобы дать доступ к нему наружу
*/
QSize viewportSizeHint() const override;

/**
* @brief Загрузить состояние дерева
*/
Expand Down

0 comments on commit 82fd418

Please sign in to comment.