ApplicationConfiguration.cxx 2.08 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//=========================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//=========================================================================
#include "smtk/extension/paraview/appcomponents/ApplicationConfiguration.h"

#include "pqApplicationCore.h"
#include "pqInterfaceTracker.h"

namespace smtk
{
namespace paraview
{

namespace
{

QMetaObject::Connection g_trackerConnection;

} // anonymous namespace

std::vector<ApplicationConfiguration::ConfigurationObserver>
  ApplicationConfiguration::s_uiComponents;

30
bool ApplicationConfiguration::notify(ConfigurationObserver observer)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{
  // Queue the observer in the list of UI components to be initialized.
  s_uiComponents.push_back(observer);
  // Try to find an existing application configuration object:
  auto* core = pqApplicationCore::instance();
  if (core)
  {
    auto* tracker = core->interfaceTracker();
    auto interfaces = tracker->interfaces<ApplicationConfiguration*>();
    if (!interfaces.empty())
    {
      for (auto& iface : interfaces)
      {
        if (ApplicationConfiguration::found(dynamic_cast<QObject*>(iface)))
        {
46
          return true;
47
48
49
50
51
52
53
54
55
56
57
58
        }
      }
    }
    // Queue an observer if we don't find an interface... only queue it once.
    if (!g_trackerConnection)
    {
      g_trackerConnection =
        QObject::connect(tracker, &pqInterfaceTracker::interfaceRegistered, [](QObject* iface) {
          ApplicationConfiguration::found(iface);
        });
    }
  }
59
  return false;
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
}

bool ApplicationConfiguration::found(QObject* iface)
{
  auto* configurator = dynamic_cast<ApplicationConfiguration*>(iface);
  if (!configurator)
  {
    return false;
  }
  for (auto& observer : s_uiComponents)
  {
    observer(*configurator);
  }
  s_uiComponents.clear();
  return true;
}

} // namespace paraview
} // namespace smtk