Changeset View
Changeset View
Standalone View
Standalone View
kmplot/function.cpp
Show First 20 Lines • Show All 380 Lines • ▼ Show 20 Line(s) | 376 | { | |||
---|---|---|---|---|---|
381 | 381 | | |||
382 | m_variables.clear(); | 382 | m_variables.clear(); | ||
383 | 383 | | |||
384 | if ( looksLikeFunction() ) | 384 | if ( looksLikeFunction() ) | ||
385 | { | 385 | { | ||
386 | int p1 = m_fstr.indexOf( '(' ); | 386 | int p1 = m_fstr.indexOf( '(' ); | ||
387 | int p2 = m_fstr.indexOf( ')' ); | 387 | int p2 = m_fstr.indexOf( ')' ); | ||
388 | 388 | | |||
389 | QStringList listSplit; | 389 | const QStringList listSplit = ( (p1 != -1) && (p2 != -1) ) ? m_fstr.mid( p1+1, p2-p1-1 ).split( ',', QString::SkipEmptyParts ) : QStringList(); | ||
390 | if ( (p1 != -1) && (p2 != -1) ) | | |||
391 | listSplit = m_fstr.mid( p1+1, p2-p1-1 ).split( ',', QString::SkipEmptyParts ); | | |||
392 | 390 | | |||
aacid: what would you think of
const QStringList listSplit = ( (p1 != -1) && (p2 != -1) ) ? m_fstr. | |||||
393 | // Variables shouldn't contain spaces! | 391 | // Variables shouldn't contain spaces! | ||
394 | foreach ( QString s, listSplit ) { //krazy:exclude=foreach | 392 | for ( QString s : listSplit ) { | ||
395 | s = s.remove(' '); | 393 | s = s.remove(' '); | ||
396 | if ( !s.isEmpty() ) | 394 | if ( !s.isEmpty() ) | ||
397 | m_variables << s; | 395 | m_variables << s; | ||
398 | } | 396 | } | ||
399 | } | 397 | } | ||
400 | else switch ( type() ) | 398 | else switch ( type() ) | ||
401 | { | 399 | { | ||
402 | case Cartesian: | 400 | case Cartesian: | ||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Line(s) | 570 | { | |||
614 | f0.visible = true; | 612 | f0.visible = true; | ||
615 | 613 | | |||
616 | k = 0; | 614 | k = 0; | ||
617 | } | 615 | } | ||
618 | 616 | | |||
619 | 617 | | |||
620 | Function::~Function() | 618 | Function::~Function() | ||
621 | { | 619 | { | ||
622 | foreach ( Equation * e, eq ) | 620 | for ( Equation * e : qAsConst(eq) ) | ||
aacid: qDeleteAll? | |||||
623 | delete e; | 621 | delete e; | ||
624 | } | 622 | } | ||
625 | 623 | | |||
626 | 624 | | |||
627 | bool Function::copyFrom( const Function & function ) | 625 | bool Function::copyFrom( const Function & function ) | ||
628 | { | 626 | { | ||
629 | bool changed = false; | 627 | bool changed = false; | ||
630 | int i = 0; | 628 | int i = 0; | ||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Line(s) | 775 | { | |||
826 | 824 | | |||
827 | // Copy each plot in the list for other variations | 825 | // Copy each plot in the list for other variations | ||
828 | if ( (type() == Cartesian) && (combinations & DifferentDerivatives) ) | 826 | if ( (type() == Cartesian) && (combinations & DifferentDerivatives) ) | ||
829 | { | 827 | { | ||
830 | QList< Plot > duplicated; | 828 | QList< Plot > duplicated; | ||
831 | 829 | | |||
832 | for ( PMode p = Derivative0; p <= Integral; p = PMode(p+1) ) | 830 | for ( PMode p = Derivative0; p <= Integral; p = PMode(p+1) ) | ||
833 | { | 831 | { | ||
834 | foreach ( Plot plot, list ) { //krazy:exclude=foreach | 832 | for ( Plot plot : qAsConst(list) ) { | ||
aacid: qAsConst? | |||||
835 | if ( !plotAppearance(p).visible ) | 833 | if ( !plotAppearance(p).visible ) | ||
836 | continue; | 834 | continue; | ||
837 | plot.plotMode = p; | 835 | plot.plotMode = p; | ||
838 | duplicated << plot; | 836 | duplicated << plot; | ||
839 | } | 837 | } | ||
840 | } | 838 | } | ||
841 | 839 | | |||
842 | list = duplicated; | 840 | list = duplicated; | ||
843 | } | 841 | } | ||
844 | 842 | | |||
845 | if ( (type() == Differential) && (combinations & DifferentInitialStates) ) | 843 | if ( (type() == Differential) && (combinations & DifferentInitialStates) ) | ||
846 | { | 844 | { | ||
847 | QList< Plot > duplicated; | 845 | QList< Plot > duplicated; | ||
848 | 846 | | |||
849 | for ( int i = 0; i < eq[0]->differentialStates.size(); ++i ) | 847 | for ( int i = 0; i < eq[0]->differentialStates.size(); ++i ) | ||
850 | { | 848 | { | ||
851 | foreach ( Plot plot, list ) { //krazy:exclude=foreach | 849 | for ( Plot plot : qAsConst(list) ) { | ||
aacid: qAsConst? | |||||
852 | plot.stateNumber = i; | 850 | plot.stateNumber = i; | ||
853 | duplicated << plot; | 851 | duplicated << plot; | ||
854 | } | 852 | } | ||
855 | } | 853 | } | ||
856 | 854 | | |||
857 | list = duplicated; | 855 | list = duplicated; | ||
858 | } | 856 | } | ||
859 | 857 | | |||
860 | if ( combinations & DifferentPMSignatures ) | 858 | if ( combinations & DifferentPMSignatures ) | ||
861 | { | 859 | { | ||
862 | int size = 0; | 860 | int size = 0; | ||
863 | foreach ( Equation * equation, eq ) | 861 | for ( Equation * equation : qAsConst(eq) ) | ||
864 | size += equation->pmCount(); | 862 | size += equation->pmCount(); | ||
865 | 863 | | |||
866 | unsigned max = unsigned( std::pow( 2.0, (double)size ) ); | 864 | unsigned max = unsigned( std::pow( 2.0, (double)size ) ); | ||
867 | QVector< QVector<bool> > signatures( max ); | 865 | QVector< QVector<bool> > signatures( max ); | ||
868 | 866 | | |||
869 | for ( unsigned i = 0; i < max; ++i ) | 867 | for ( unsigned i = 0; i < max; ++i ) | ||
870 | { | 868 | { | ||
871 | QVector<bool> sig( size ); | 869 | QVector<bool> sig( size ); | ||
872 | 870 | | |||
873 | for ( int j = 0; j < size; ++j ) | 871 | for ( int j = 0; j < size; ++j ) | ||
874 | sig[ j ] = i & (1<<j); | 872 | sig[ j ] = i & (1<<j); | ||
875 | 873 | | |||
876 | signatures[i] = sig; | 874 | signatures[i] = sig; | ||
877 | } | 875 | } | ||
878 | 876 | | |||
879 | // Generate a plot for each signature in signatures | 877 | // Generate a plot for each signature in signatures | ||
880 | QList< Plot > duplicated; | 878 | QList< Plot > duplicated; | ||
881 | foreach ( const QVector<bool> &signature, signatures ) | 879 | for ( const QVector<bool> &signature : qAsConst(signatures) ) | ||
aacid: qAsConst? | |||||
882 | { | 880 | { | ||
883 | int at = 0; | 881 | int at = 0; | ||
884 | QList< QVector<bool> > pmSignature; | 882 | QList< QVector<bool> > pmSignature; | ||
885 | 883 | | |||
886 | foreach ( Equation * equation, eq ) | 884 | for ( Equation * equation : qAsConst(eq) ) | ||
887 | { | 885 | { | ||
888 | int pmCount = equation->pmCount(); | 886 | int pmCount = equation->pmCount(); | ||
889 | QVector<bool> sig( pmCount ); | 887 | QVector<bool> sig( pmCount ); | ||
890 | for ( int i = 0; i < pmCount; ++i ) | 888 | for ( int i = 0; i < pmCount; ++i ) | ||
891 | sig[i] = signature[ i + at]; | 889 | sig[i] = signature[ i + at]; | ||
892 | at += pmCount; | 890 | at += pmCount; | ||
893 | 891 | | |||
894 | pmSignature << sig; | 892 | pmSignature << sig; | ||
895 | } | 893 | } | ||
896 | 894 | | |||
897 | foreach ( Plot plot, list ) { //krazy:exclude=foreach | 895 | for ( Plot plot : qAsConst(list) ) { | ||
aacid: qAsConst? | |||||
898 | plot.pmSignature = pmSignature; | 896 | plot.pmSignature = pmSignature; | ||
899 | duplicated << plot; | 897 | duplicated << plot; | ||
900 | } | 898 | } | ||
901 | } | 899 | } | ||
902 | list = duplicated; | 900 | list = duplicated; | ||
903 | } | 901 | } | ||
904 | 902 | | |||
905 | return list; | 903 | return list; | ||
Show All 14 Lines | |||||
920 | bool Function::dependsOn( Function * function ) const | 918 | bool Function::dependsOn( Function * function ) const | ||
921 | { | 919 | { | ||
922 | if ( !function ) | 920 | if ( !function ) | ||
923 | return false; | 921 | return false; | ||
924 | 922 | | |||
925 | if ( m_dependencies.contains( function->id() ) ) | 923 | if ( m_dependencies.contains( function->id() ) ) | ||
926 | return true; | 924 | return true; | ||
927 | 925 | | |||
928 | foreach ( int functionId, m_dependencies ) | 926 | for ( int functionId : qAsConst(m_dependencies) ) | ||
929 | { | 927 | { | ||
930 | Function * f = XParser::self()->functionWithID( functionId ); | 928 | Function * f = XParser::self()->functionWithID( functionId ); | ||
931 | 929 | | |||
932 | if ( f->dependsOn( function ) ) | 930 | if ( f->dependsOn( function ) ) | ||
933 | return true; | 931 | return true; | ||
934 | } | 932 | } | ||
935 | 933 | | |||
936 | return false; | 934 | return false; | ||
▲ Show 20 Lines • Show All 273 Lines • Show Last 20 Lines |
what would you think of
const QStringList listSplit = ( (p1 != -1) && (p2 != -1) ) ? m_fstr.mid( p1+1, p2-p1-1 ).split( ',', QString::SkipEmptyParts ) : {};