1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Optimised and tidied up some ValueTree methods. Added a method to MultiDocumentPanel.

This commit is contained in:
jules 2011-11-17 12:57:44 +00:00
parent ba2287033c
commit ef63c14040
6 changed files with 740 additions and 600 deletions

View file

@ -20,7 +20,7 @@ ifeq ($(CONFIG),Debug)
CPPFLAGS := $(DEPFLAGS) -D "LINUX=1" -D "DEBUG=1" -D "_DEBUG=1" -D "JUCE_UNIT_TESTS=1" -D "JUCER_LINUX_MAKE_7346DA2A=1" -I "/usr/include" -I "/usr/include/freetype2" -I "../../JuceLibraryCode"
CFLAGS += $(CPPFLAGS) $(TARGET_ARCH) -g -ggdb -O0
CXXFLAGS += $(CFLAGS)
LDFLAGS += -L$(BINDIR) -L$(LIBDIR) -L"/usr/X11R6/lib/" -L"../../../../../juce/bin" -lfreetype -lpthread -lrt -lX11 -lGL -lGLU -lXinerama -lasound
LDFLAGS += -L$(BINDIR) -L$(LIBDIR) -L"/usr/X11R6/lib/" -L"../../../../../juce/bin" -lfreetype -lpthread -lrt -lX11 -lGL -lGLU -lXinerama -lasound -lXext
LDDEPS :=
RESFLAGS := -D "LINUX=1" -D "DEBUG=1" -D "_DEBUG=1" -D "JUCE_UNIT_TESTS=1" -D "JUCER_LINUX_MAKE_7346DA2A=1" -I "/usr/include" -I "/usr/include/freetype2" -I "../../JuceLibraryCode"
TARGET := JuceDemo
@ -35,7 +35,7 @@ ifeq ($(CONFIG),Release)
CPPFLAGS := $(DEPFLAGS) -D "LINUX=1" -D "NDEBUG=1" -D "JUCE_UNIT_TESTS=1" -D "JUCER_LINUX_MAKE_7346DA2A=1" -I "/usr/include" -I "/usr/include/freetype2" -I "../../JuceLibraryCode"
CFLAGS += $(CPPFLAGS) $(TARGET_ARCH) -Os
CXXFLAGS += $(CFLAGS)
LDFLAGS += -L$(BINDIR) -L$(LIBDIR) -L"/usr/X11R6/lib/" -L"../../../../../juce/bin" -lfreetype -lpthread -lrt -lX11 -lGL -lGLU -lXinerama -lasound
LDFLAGS += -L$(BINDIR) -L$(LIBDIR) -L"/usr/X11R6/lib/" -L"../../../../../juce/bin" -lfreetype -lpthread -lrt -lX11 -lGL -lGLU -lXinerama -lasound -lXext
LDDEPS :=
RESFLAGS := -D "LINUX=1" -D "NDEBUG=1" -D "JUCE_UNIT_TESTS=1" -D "JUCER_LINUX_MAKE_7346DA2A=1" -I "/usr/include" -I "/usr/include/freetype2" -I "../../JuceLibraryCode"
TARGET := JuceDemo

View file

@ -130,17 +130,39 @@ public:
*/
inline ObjectClassPtr operator[] (const int index) const noexcept
{
const ScopedLockType lock (getLock());
return isPositiveAndBelow (index, numUsed) ? data.elements [index]
: static_cast <ObjectClass*> (nullptr);
return getObjectPointer (index);
}
/** Returns a pointer to the object at this index in the array, without checking whether the index is in-range.
/** Returns a pointer to the object at this index in the array, without checking
whether the index is in-range.
This is a faster and less safe version of operator[] which doesn't check the index passed in, so
it can be used when you're sure the index if always going to be legal.
*/
inline ObjectClassPtr getUnchecked (const int index) const noexcept
{
return getObjectPointerUnchecked (index);
}
/** Returns a raw pointer to the object at this index in the array.
If the index is out-of-range, this will return a null pointer, (and
it could be null anyway, because it's ok for the array to hold null
pointers as well as objects).
@see getUnchecked
*/
inline ObjectClass* getObjectPointer (const int index) const noexcept
{
const ScopedLockType lock (getLock());
return isPositiveAndBelow (index, numUsed) ? data.elements [index]
: nullptr;
}
/** Returns a raw pointer to the object at this index in the array, without checking
whether the index is in-range.
*/
inline ObjectClass* getObjectPointerUnchecked (const int index) const noexcept
{
const ScopedLockType lock (getLock());
jassert (isPositiveAndBelow (index, numUsed));
@ -736,6 +758,18 @@ public:
data.shrinkToNoMoreThan (numUsed);
}
/** Increases the array's internal storage to hold a minimum number of elements.
Calling this before adding a large known number of elements means that
the array won't have to keep dynamically resizing itself as the elements
are added, and it'll therefore be more efficient.
*/
void ensureStorageAllocated (const int minNumElements)
{
const ScopedLockType lock (getLock());
data.ensureAllocatedSize (minNumElements);
}
//==============================================================================
/** Returns the CriticalSection that locks this array.
To lock, you can call getLock().enter() and getLock().exit(), or preferably use

View file

@ -77,7 +77,7 @@ void UnitTest::expect (const bool result, const String& failureMessage)
//==============================================================================
UnitTestRunner::UnitTestRunner()
: currentTest (nullptr),
assertOnFailure (false),
assertOnFailure (true),
logPasses (false)
{
}

File diff suppressed because it is too large Load diff

View file

@ -164,6 +164,7 @@ public:
const var& operator[] (const Identifier& name) const;
/** Changes a named property of the node.
The name identifier must not be an empty string.
If the undoManager parameter is non-null, its UndoManager::perform() method will be used,
so that this change can be undone.
@see var, getProperty, removeProperty
@ -427,6 +428,11 @@ public:
/** Removes a listener that was previously added with addListener(). */
void removeListener (Listener* listener);
/** Causes a property-change callback to be triggered for the specified property,
calling any listeners that are registered.
*/
void sendPropertyChangeMessage (const Identifier& property);
//==============================================================================
/** This method uses a comparator object to sort the tree's children into order.
@ -454,10 +460,11 @@ public:
{
if (object != nullptr)
{
ReferenceCountedArray <SharedObject> sortedList (object->children);
OwnedArray<ValueTree> sortedList;
createListOfChildren (sortedList);
ComparatorAdapter <ElementComparator> adapter (comparator);
sortedList.sort (adapter, retainOrderOfEquivalentItems);
object->reorderChildren (sortedList, undoManager);
reorderChildren (sortedList, undoManager);
}
}
@ -468,78 +475,29 @@ public:
private:
//==============================================================================
class SetPropertyAction; friend class SetPropertyAction;
class AddOrRemoveChildAction; friend class AddOrRemoveChildAction;
class MoveChildAction; friend class MoveChildAction;
class SharedObject;
friend class SharedObject;
class JUCE_API SharedObject : public SingleThreadedReferenceCountedObject
{
public:
explicit SharedObject (const Identifier& type);
SharedObject (const SharedObject& other);
~SharedObject();
const Identifier type;
NamedValueSet properties;
ReferenceCountedArray <SharedObject> children;
SortedSet <ValueTree*> valueTreesWithListeners;
SharedObject* parent;
void sendPropertyChangeMessage (const Identifier& property);
void sendPropertyChangeMessage (ValueTree& tree, const Identifier& property);
void sendChildAddedMessage (ValueTree& parent, ValueTree& child);
void sendChildAddedMessage (ValueTree child);
void sendChildRemovedMessage (ValueTree& parent, ValueTree& child);
void sendChildRemovedMessage (ValueTree child);
void sendChildOrderChangedMessage (ValueTree& parent);
void sendChildOrderChangedMessage();
void sendParentChangeMessage();
const var& getProperty (const Identifier& name) const;
var getProperty (const Identifier& name, const var& defaultReturnValue) const;
void setProperty (const Identifier& name, const var& newValue, UndoManager*);
bool hasProperty (const Identifier& name) const;
void removeProperty (const Identifier& name, UndoManager*);
void removeAllProperties (UndoManager*);
bool isAChildOf (const SharedObject* possibleParent) const;
int indexOf (const ValueTree& child) const;
ValueTree getChildWithName (const Identifier& type) const;
ValueTree getOrCreateChildWithName (const Identifier& type, UndoManager* undoManager);
ValueTree getChildWithProperty (const Identifier& propertyName, const var& propertyValue) const;
void addChild (SharedObject* child, int index, UndoManager*);
void removeChild (int childIndex, UndoManager*);
void removeAllChildren (UndoManager*);
void moveChild (int currentIndex, int newIndex, UndoManager*);
void reorderChildren (const ReferenceCountedArray <SharedObject>& newOrder, UndoManager*);
bool isEquivalentTo (const SharedObject& other) const;
XmlElement* createXml() const;
private:
SharedObject& operator= (const SharedObject&);
JUCE_LEAK_DETECTOR (SharedObject);
};
ReferenceCountedObjectPtr<SharedObject> object;
ListenerList<Listener> listeners;
template <typename ElementComparator>
class ComparatorAdapter
struct ComparatorAdapter
{
public:
ComparatorAdapter (ElementComparator& comparator_) noexcept : comparator (comparator_) {}
int compareElements (SharedObject* const first, SharedObject* const second)
int compareElements (const ValueTree* const first, const ValueTree* const second)
{
return comparator.compareElements (ValueTree (first), ValueTree (second));
return comparator.compareElements (*first, *second);
}
private:
ElementComparator& comparator;
JUCE_DECLARE_NON_COPYABLE (ComparatorAdapter);
};
friend class SharedObject;
typedef ReferenceCountedObjectPtr <SharedObject> SharedObjectPtr;
SharedObjectPtr object;
ListenerList <Listener> listeners;
void createListOfChildren (OwnedArray<ValueTree>&) const;
void reorderChildren (const OwnedArray<ValueTree>&, UndoManager*);
#if JUCE_MSVC && ! DOXYGEN
public: // (workaround for VC6)

View file

@ -243,6 +243,8 @@ public:
*/
const Colour& getBackgroundColour() const noexcept { return backgroundColour; }
/** If the panel is being used in tabbed mode, this returns the TabbedComponent that's involved. */
TabbedComponent* getCurrentTabbedComponent() const noexcept { return tabComponent; }
//==============================================================================
/** A subclass must override this to say whether its currently ok for a document